Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to Get Index Values of an Image by imagesc

Asked by HANS on 20 Aug 2012

Hi everyone,

I have a matrix that includes complex values. I am using imagesc to see the output. I can see the index values by using data cursor but How can I assign and get index values of that output ?

Thanks BR Hans

2 Comments

Manuel on 10 Dec 2012

Hello:

I also need the intensity values but not only the max of the picture, but also all of them, in order to save this values into a matrix and to calculate the intensity average value.

Thank you in advance, Manuel

Image Analyst on 10 Dec 2012

You already have the values, or else you would not have been able to display anything. meanIntensity = mean(yourImage(:)). Why don't you start your own thread to discuss further?

HANS

Products

No products are associated with this question.

2 Answers

Answer by Image Analyst on 21 Aug 2012
Accepted answer

What is "the output" - is that the same as "matrix" or is it different? And imagesc doesn't work with complex images. Can you explain how you got it to work? Also I don't know what you mean by index. If you use impixelinfo you can see the x (column) and y (row) and the value (gray level). And there is also some funky colormap applied to the image, which you can retrieve. But I don't know which of these several numbers you call "index". Do you mean like the index into a colormap (i.e. the intensity value), or the linear index of the image (i.e. the pixel location), or something else. And I don't know what you want to do when you say you want to "assign" and "get" the indexes. Why do you need to both set and get these values (whatever they are)?

% Generate some sample complex image.
realPart = rand(300);
imaginaryPart = i * rand(300);
complexImage = realPart + imaginaryPart;
% Try to display complex image - won't work.
% imagesc(complexImage); % Does not work.
% Display the real part only.
imagesc(realPart);
% Set up where it will show x, y, and value in status line.
impixelinfo;
% Get the current colormap
cmap = colormap

3 Comments

HANS on 21 Aug 2012

Thanks for the quick and detailed response.

-Yes, the output is like imagesc(real(complex_matrix)); -Sorry, you are right, I am plotting only the real part of my complex matrix. -I mean intensity values by saying index. -When I plot by using imagesc, I can see the different index values by using data cursor but I have to have maximum index value that I can see from the figure by writing imagesc(real(complex_matrix)) and then I'll assign it to a parameter.

BR

Image Analyst on 21 Aug 2012

How about if you use ginput() go get an x,y coordinate and then just assign your parameter like this:

% Find the value where the user clicks.
uiwait(msgbox('Click a point'));
[x y] = ginput(1);
row = int32(y)
column = int32(x)
a = realPart(row, column);
b = i * imaginaryPart(row, column);
theParameter = a + i * b

Or find the max over the entire image, if you don't want them to click anywhere.

% Find the location of the max intensity value 
% of the real part over the entire image.
[row column] = find(realPart == max(realPart(:)), 1, 'first')
aMax = realPart(row, column);
bMax = i * imaginaryPart(row, column);
theParameterFromTheMax = aMax + i * bMax
HANS on 22 Aug 2012

I appreciated your help. :] Thanks a lot. It does.

Image Analyst
Answer by Walter Roberson on 20 Aug 2012

See the File Exchange contribution "freezeColors"

3 Comments

HANS on 21 Aug 2012

Thanks. I'll check this out. This is is a big package.

Walter Roberson on 21 Aug 2012

The mapping done by freezeColors is not very complex; you can extract the ideas and implement them in a few lines.

HANS on 22 Aug 2012

Thanks a lot. I will try. It is sure that it helps.

Walter Roberson

Contact us