How to normalize an image in matlab?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (3)
John BG
el 27 de Feb. de 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
1 comentario
Yashaswini MU
el 28 de Feb. de 2016
Image Analyst
el 27 de Feb. de 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 comentarios
John BG
el 28 de Feb. de 2016
to Image Analyst,
hope you don't mind mind the following question:
the term 'normalize' applied to a still image means making black really black, white really white and to remove, detrend, clutter, DC, that may be compressing the the dynamic range of the image?
thanks for attention
John
Image Analyst
el 28 de Feb. de 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.
John BG
el 28 de Feb. de 2016
1 voto
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
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!