Image Normalization in the range 0 to 1

 Akzeptierte Antwort

Image Analyst
Image Analyst am 12 Dez. 2013

6 Stimmen

Use mat2gray() or im2double(). Hopefully you have the image processing Toolbox.
normImage = mat2gray(yourImage);
normImage = im2double(yourImage);
Also look at stretchlim() and imadjust().

10 Kommentare

Image Analyst
Image Analyst am 14 Dez. 2013
Sapam - are you still alive???
Sapam Jaya
Sapam Jaya am 5 Feb. 2014
Bearbeitet: Sapam Jaya am 5 Feb. 2014
i was sick..thanx
Image Analyst
Image Analyst am 5 Feb. 2014
So does my answer solve your question?
Sapam Jaya
Sapam Jaya am 6 Feb. 2014
i guess no,the value is coming 0.the thing is i have to do dwt then get the low frequency (LL)component.in this LL i have to do a log average transform.the result of this has to be normalized from 0 to 1.in this log average i have to use a rectangular region.is it same as rectangular window.i dont understand this window much so maybe my output is wrong
Image Analyst
Image Analyst am 6 Feb. 2014
You can do your log, and then pass that in to mat2gray() like I showed you. The image is already rectangular so I don't know why you say you have to use a rectangular window and don't understand it. There's nothing to do since it's already a rectangle, unless you want a different sized rectangle, for which you can use rbbox() or imrect().
Sapam Jaya
Sapam Jaya am 6 Feb. 2014
the rectangular window is as per the instruction..this clears much of the doubt..thanx
Image Analyst
Image Analyst am 6 Feb. 2014
Can you go ahead and Accept the answer to close it out? Thanks in advance.
Andrea Daou
Andrea Daou am 23 Sep. 2021
How can these normalized images between 0 and 1 be saved in a folder ? Because after I normalized them and saved them the images obtained remain with pixel range between 0 and 255.
Thank you in advance!
If you really want them to have fractional values between 0 and 1, that's not a standard image format so you'll just have to save them with
save('myFile.mat', 'yourImageVariable');
to save them in a .mat file.
Andrea Daou
Andrea Daou am 29 Sep. 2021
Thank you for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

mutant
mutant am 6 Okt. 2019

7 Stimmen

Old question but as of R2017b, rescale does exactly this.
B = rescale(A); % Normalizes image (0 to 1, by default)
You can even use this to scale to uint8, for example:
B = rescale(A,0,255); % Normalizes image to [0 255]
Documentation here:
Azzi Abdelmalek
Azzi Abdelmalek am 12 Dez. 2013
Bearbeitet: Azzi Abdelmalek am 12 Dez. 2013

4 Stimmen

If im is your image
im=(im-min(im(:)))/(max(im(:))-min(im(:)))

1 Kommentar

I suggest to do this in two steps to avoid the calculation of MIN twice ...
IM = IM - min(IM(:)) ;
IM = IM / max(IM(:)) ;

Melden Sie sich an, um zu kommentieren.

Sajid Khan
Sajid Khan am 6 Feb. 2014
Bearbeitet: DGM am 13 Feb. 2023

2 Stimmen

function image_normalized = imnormalize( image_orig, min_norm, max_norm)
val_max = max(image_orig(:));
val_min = min(image_orig(:));
range = val_max - val_min;
image_normalized = (image_orig - val_min) ./ range; % Then scale to [x,y] via:
range2 = max_norm - min_norm;
image_normalized = (image_normalized*range2) + min_norm;
end
In this function, you can set min_norm = 0 and max_norm = 1 to normalize image to a scale of 0 to 1. If you have any other questions to ask, then you are welcome. I always use this function for normalization purpose. It even works if you have to increase the scale length.

2 Kommentare

Image Analyst
Image Analyst am 6 Feb. 2014
Your function basically does the same thing as the built in function mat2gray().
DGM
DGM am 13 Feb. 2023
Rather, mat2gray() only allows the specification of the input levels, assuming the output levels are [0 1]. Sajid's function allows specification of the output levels, while using image extrema as the input levels.
So in that sense, it's more like rescale(), same syntax and everything.

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 12 Dez. 2013

Kommentiert:

DGM
am 13 Feb. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by