MATLAB: Can u pls explain it

Image Processing Toolboxnormalization

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(:));

Best Answer

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.