MATLAB Answers

How to normalize an image in matlab?

232 views (last 30 days)
Yashaswini MU
Yashaswini MU on 27 Feb 2016
Answered: RUJEYANTHI U on 25 Sep 2018
Hi, I have a region of interest of dimension 50*50. I want to normalize this image in order to obtain a row vector of dimensions equal to the number of pixels in the image i.e 1*2500. How can I achieve this? Can someone please help me? I have attached the image below.

Accepted Answer

John BG
John BG on 27 Feb 2016
X would be a test region of interest
X=zeros(5,5,3)
X_r=randi([0 255],5,5)
X_g=randi([0 255],5,5)
X_b=randi([0 255],5,5)
X(:,:,1)=X_r
X(:,:,2)=X_g
X(:,:,3)=X_b
then
L=reshape(X,3,25)
lines up all pixels on a single row. To get all reds
L(1,:)
to get the Luminance on a row
Y=sum(L,1)
Multiply by 10 the size of X to work with a region of interest same size as the one you suggest in the question.
If you find this answer of any help solving this question, please click on the thumbs-up vote link,
thanks in advance
John
  3 Comments
Yashaswini MU
Yashaswini MU on 28 Feb 2016
Image Analyst
Sir, I want to normalize all the different ROI of various activities to obtain a row vector of the dimensions I have mentioned and apply feature extraction techniques on them.

Sign in to comment.

More Answers (4)

John BG
John BG on 27 Feb 2016
Yshaswini
A=imread('roiresize.jpg')
[s1 s2 s3]=size(A)
roithread=reshape(A,3,s1*s2)
Ythread=floor(sum(roithread,1)/3) % Luminance of each pixel
Please note that because I have cropped the image you have attached the size of roiresize.jpg many not be exactly the same size of the file you have attached. Don't try the command squeeze, it's not what the name suggests.
If you find this answer of any help solving this question, please click on the thumbs-up vote link,
thanks in advance
John

Image Analyst
Image Analyst on 27 Feb 2016
If you have a grayscale image of dimensions 50 rows by 50 columns, you can turn it into a 1*2500 row vector simply by doing
rowVector = grayImage(:)';
Or you can use reshape():
rowVector = reshape(grayImage, 1, []);
  2 Comments
Image Analyst
Image Analyst on 28 Feb 2016
John, yes, that would be intensity normalization. I didn't address that - I just answered the reshaping 50x50 into 2500x1 question. If he also wanted intensity normalization, he can use the built-in function mat2gray(), which does a scaling and shifting of the data to a 0-1 range. If he wanted it in the 0-255 range instead, he would simply do
rowVector = 255 * mat2gray(rowVector);
Of course, it's a double and if you used imshow() without [] it would show as a white line. So you can either use []
imshow(rowVector, []); % Show double data
or cast it to uint8, if that is the data type that is wanted:
rowVector = uint8(255 * mat2gray(rowVector));
imshow(rowVector);
Of course this is all for a gray scale image. If the image is color, you'd have to take more care. You can't just normalize R, G, and B separately or you'll introduce color artifacts.

Sign in to comment.


John BG
John BG on 28 Feb 2016
L.Csink D.Paulus U.Ahlrichs and B.Heigl (Koblenz 98, from Erlangen Uni)
mention 3 color normalization methods
  • Color rotation
  • Whitening
  • Comprehensive normalization
Regarding Color rotation, the rotated color of a pixel cluster f (R,G,B) seems to be fr=A*f' in the color base (RG,BY,WB)
.JPG do not use (RG,BY,WB) but (R,G,B).
To directly normalize (R,G,B) pixels you need to calculate fr=A^-1*R*A(f-m)+[128 128 128] where R is the rotation matrix where A=[.5 -1 .5;-.875 0 .875;1.5 1.5 1.5]
You may want to read the whole article as well as follow the references in case there is already a function or script around to normalize color of cluster without having to reshape the matrix.
And obviously, first place to look at should be MATLAB CENTRAL, you may be interested to use the functions in:
or
hope it helps
John

RUJEYANTHI U
RUJEYANTHI U on 25 Sep 2018
please anyone tell me how to normalize the iris images.i want to Matlab code for iris normalization

Community Treasure Hunt

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

Start Hunting!

Translated by