how can i perform gray scale image normalization???

i want to implement normalization to gray scale image to reduce the effect of illumination's differences.
the eq. of the grayscale normalization is :
y=((x-min)*255/(max-min))
x : gray scale value of original image.
y : gray scale value of op image(after normalization).
min : minimum gray scale for the original image.
max : maximum gray scale for the original image.
i tried to perform this by :
m=imread();
min1=min(min(m));
max1=max(max(m));
y=((m-min1).*255)./(max1-min1);
imshow(m);figure,imshow(y);
but it is wrong code .
i dont know why ?
is there any help?
regards

5 Kommentare

Image Analyst
Image Analyst am 19 Jan. 2012
Perhaps because you didn't pass any filename into imread(). Perhaps because you left off the [] in imshow(y, []). It's floating so unless it's in the range 0-1 you need to give [] as the second arg to imshow().
I think you've been around here long enough to know that you need to tell us what the error message is (by copying and pasting the red text from the command window) because just saying "it is wrong code" is not sufficient for us to debug your code or figure out what is wrong or unexpected behavior.
mmm ssss
mmm ssss am 19 Jan. 2012
dear image analyst
what i means by it's wrong code that it did not enable me to get my goal .
the image y is only whole black image with only one white point inside it .
so this is not normalization
Image Analyst
Image Analyst am 19 Jan. 2012
Like I said, you probably just didn't display it correctly. See my answer below.
We would need to see the current code.
Xylo
Xylo am 11 Mär. 2014
you can use double() before main function....
y=double((m-min1).*255./(max1-min1)); and as m is a 2D variable, y should be 2D variable. i.e u have to write as for i=1:m for j=1:n y(i,j)=double((m(i,j)-min1).*255./(max1-min1)); end end

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Image Analyst
Image Analyst am 19 Jan. 2012

4 Stimmen

Or you can simply do this:
normalizedImage = uint8(255*mat2gray(grayImage));
imshow(normalizedImage);
and not worry about the normalization because mat2gray will do it for you.

4 Kommentare

mmm ssss
mmm ssss am 19 Jan. 2012
not very good effect of mat2gray(grayimage)
Image Analyst
Image Analyst am 19 Jan. 2012
It does exactly what you asked for and exactly what all these other formulas here are doing. It maps the min of your array to 0 and the max of your array to 255. You can subtract the array from what you got with the other formulas and you'll see that everything is zero, meaning they're the same. If that doesn't have a "good effect" then none of the formulas here will either.
mmm ssss
mmm ssss am 19 Jan. 2012
image analyst
i think that your opininon is correct but, in many paper they use the grayscale normalization to reduce the differences in illumination.
Image Analyst
Image Analyst am 19 Jan. 2012
Then maybe their algorithm uses image normalization as just one step in the process and maybe you're not doing all the steps. Or else maybe their algorithm is not appropriate for the kind of video or images you have.

Melden Sie sich an, um zu kommentieren.

Syed Ahson Ali Shah
Syed Ahson Ali Shah am 8 Feb. 2022
Bearbeitet: Syed Ahson Ali Shah am 10 Feb. 2022

1 Stimme

This is the Formula:
Normalized Image = (Original image - min of image) * ((newMax-newMin) / (ImageMax - ImageMin)) + newMin
where newMax and newMin is 255 and 0 respectively for the case when normalization is between 0 to 255.

2 Kommentare

No it's not:
Originalimage = [100, 200]
Originalimage = 1×2
100 200
minofimage = min(Originalimage(:));
ImageMin = min(Originalimage(:));
ImageMax = max(Originalimage(:));
newMax = 255;
newMin = 0;
% Do the formula he gave.
NormalizedImage = (Originalimage - minofimage) * ((newMax-newMin) / (ImageMax - ImageMin)) + newMax
NormalizedImage = 1×2
255 510
% Do my formula:
normalizedImage = uint8(255*mat2gray(Originalimage))
normalizedImage = 1×2
0 255
There was typo mistake. I corrected now.
My answer is 100% correct. I guarantee

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 18 Jan. 2012

0 Stimmen

I would suggest you use
y = uint8(255 .* ((double(m)-min1)) ./ (max1-min1));
With your existing code, the (x-min) would be okay, but multiplying by 255 would get saturation to 255 whenever the difference was not 0, and then you would get integer division of that 0 or 255 by the range interval.

5 Kommentare

mmm ssss
mmm ssss am 18 Jan. 2012
??? Error using ==> minus
Integers can only be combined with integers of the same class, or scalar doubles.
i faced this matlab error
y = uint8(255 .* ((double(m)-double(min1))) ./ (max1-min1));
mmm ssss
mmm ssss am 19 Jan. 2012
y = uint8(255 .* ((double(m)-double(min1))) ./ (max1-min1));
??? Error using ==> rdivide
Integers can only be combined with integers of the same class, or scalar doubles.
You should be able to extrapolate.
y = uint8(255 .* ((double(m)-double(min1))) ./ double(max1-min1));
mmm ssss
mmm ssss am 19 Jan. 2012
can you see the modified code:
clear all
>> m=imread('E:\master_matlab\HandVein_DataSet\0010hv3.bmp');
min1=min(min(m));
max1=max(max(m));
y = uint8(255 .* ((double(m)-double(min1))) ./ double(max1-min1));
>> imshow(m);
>> figure,imshow(y);title(,normalization,);
i implemented also image analyst'method:
J = filter2(fspecial('sobel'), m);
K = mat2gray(m);
figure,imshow(K);
can you give me your opinion in the resultant images (Y&K) , is they good or the image before normalization is more suitable.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 18 Jan. 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by