can u pls explain it
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sangamithra.k kunnath
le 10 Juin 2015
Commenté : Image Analyst
le 11 Juin 2015
function imOut = mean_imnorm(im)
% O = IMNORM(I)Image normalization
% imwrite doesnt seem to do any normalizing, so i do it here.
% normalizes to the range (0,1).
imOut = im;
% normalize
imMin = mean(imOut(:));
if (imMin < 0)
imOut = imOut + abs(imMin);
end
imOut = imOut ./ max(imOut(:));
0 commentaires
Réponse acceptée
Image Analyst
le 10 Juin 2015
It basically scales the input image to the range 0-1 if the original mean is negative, and scales it from (theMin/theMax) to 1 if the mean is more than 0. I don't know why they want to do it this crazy inconsistent way. You should consider just using mat2gray() which will scale the image from 0 to 1 regardless of whether the mean is negative or not. mat2gray() is the main MATLAB image normalization function that you're supposed to use. You can also use imadjust() if you want a little bit of clipping, which is good for visualization if the histogram has long tails.
2 commentaires
Image Analyst
le 11 Juin 2015
mat2gray normalizes range. That will shift the mean and scale the normalization. One place it might be useful is if you have a floating point image of something, say temperature, that has floating point units. You can display it fine with [] like this:
imshow(temperature, []);
but it you use imwrite() to save it to disk, it will mess up since imwrite wants uint8. So to convert it to uint8 you can do this to capture the whole range and quantize it to 256 gray levels:
image8 = uint8(255 * mat2gray(temperature));
imwrite(filename, image8);
image8 will be quantized with the values 0, 1, 2, 3, 4, 5, .... 254, 255.
Plus de réponses (1)
dpb
le 10 Juin 2015
% normalizes to the range (0,1).
Excepting that it doesn't if mean(imOut(:))<0. In that case it adjusts by the average, but there must be values < average so they'll still be negative. For the normalization to be >= 0, the shift would have to be abs(min()) to move the smallest value to the zero point.
OTOH, if all initial values are >=0, then the if clause doesn't come into play and since the lower bound would then be 0, the final range will be [0,1].
That still leaves the case where there are individual values <0 but the mean >0; again the range output will not be constrained [0 1].
One presumes with the name this is an image and hence there aren't negative values so the problems may not show up but the routine doesn't do as advertised (if it makes a difference).
0 commentaires
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!