How to normalize an image in matlab?

56 次查看(过去 30 天)
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.

采纳的回答

John BG
John BG 2016-2-27
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 个评论
Image Analyst
Image Analyst 2016-2-28
Your code does what you tell it to, but not necessarily what you want it to. You're replacing the image by binary noise and then reshaping and summing this complete noise. This does not look useful to me. What do you want the code to do? What are you really after? What do you want the sum to mean/represent?
Yashaswini MU
Yashaswini MU 2016-2-28
编辑:Yashaswini MU 2016-2-28
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.

请先登录,再进行评论。

更多回答(3 个)

John BG
John BG 2016-2-27
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 2016-2-27
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 个评论
John BG
John BG 2016-2-28
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
Image Analyst 2016-2-28
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
John BG 2016-2-28
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

Community Treasure Hunt

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

Start Hunting!

Translated by