3

I read some similar article, but they are not what I want.
Get the matrix after imagesc?
imagesc plot to matrix in matlab

My Problem
I have a matrix A with all elements are double.
I do imagesc(A) and then I have an image.
Now, I want to get the matrix that make the image. How can I do that?

From those articles, if I do

I = imagesc(A)
B = get(I, 'CData')

Then B == A that is not what I want.

Community
  • 1
  • 1
sflee
  • 1,659
  • 5
  • 32
  • 63
  • 1
    Check [getimage](http://www.mathworks.com.au/help/images/ref/getimage.html). – Marcin Aug 15 '13 at 10:45
  • 2
    You said what you don't want, but it is not clear to me exactly what you want. What is a 'matrix that make the image'?? – Bas Swinckels Aug 15 '13 at 10:49
  • Sorry, I didn't make it clear. What I know is that imagesc(A) will scale the data and display those data as an image. What I want is to get those data after scaling. Thank you – sflee Aug 15 '13 at 12:13

2 Answers2

4

To scale the image in the same way as imagesc do the following

Amin = min(A(:));
Amax = max(A(:));
A_scaled = (A - Amin)/(Amax - Amin);

To prove that the scaled image is what imagesc does internally then try this

imagesc(A,[Amin Amax]);
pause
imagesc(A_scaled);
twerdster
  • 4,977
  • 3
  • 40
  • 70
  • 1
    @twerdster You probably meant `image` on the last line? – Luis Mendo Aug 15 '13 at 14:53
  • If I do `A = rand(100,100); "code provided by twerdster" image(A_scaled);` then I will get an image with all blue, how can I get the same figure by image()? – sflee Aug 16 '13 at 01:50
0

It can be done in a simpler way. I tried my code in Octave.

colormap gray;
h=imshow(F,[]);
B=get(h, 'CData');