returning the indexes of an image displayed with a specific colormap

hi, does anyone know hot to get the numeric indexes of a displayed image with a specific user defined colormap???
for example imagesc(IMAGE) colormap(user_colormap)
displays an image mapped into the colormap....and I want the numeric representation of the displayed image.

5 commentaires

Can you be more specific on what you want to do? You already have the numeric data - it's stored in IMAGE. If you want to look at that on the screen, you can print out a certain range; "IMAGE(1:10,1:10)" or get a single pixel value with the cursor + sticky note icon in the figure toolbar.
Suppose you have an IMAGE and display it using imagesc(IMAGE) using a colormap that switches between black and white 0,1,0,1... etc the displayed result is a black and white map composed by 0s and 1s.... I want to recover this matrix of 0s and 1s....
What format is the IMAGE? m-by-n-by-3 or m-by-n or what?
That's what IMAGE is.... It's just a 2d matrix of indices into the colormap.
@ Matt: m-by-n only. @ Sean: I know! yet the colormap is transforming the matrix, and I want THAT transformation (or mapping), and not the original one. I want to recover the transformed 2d matrix after using imagesc with a specific user defined colormap.

Connectez-vous pour commenter.

 Réponse acceptée

Matt Fig
Matt Fig le 14 Août 2012
Modifié(e) : Matt Fig le 14 Août 2012
If I understand you correctly, you want (for example):
A = rand(4);
C = [0 0 0;.5 .5 .5;1 1 1];
imagesc(A);
colormap(C);
% idx = interp1([0 .5 1],[0 .5 1],A,'nearest')
idx = ceil(A*size(C,1))

7 commentaires

its getting closer but still not there... the problem is that my colormap is not a linear function. check it out
% building the colormap
k=32; % cycles
x=(0:2*pi/63:2*pi)';
y=(-cos(k.*x)+1)./2; % sinusoidal waveform between 0 and 1
% variant (black and white)
yy=y;
yy(find(y>=0.5))=1;
yy(find(y<0.5))=0;
% colormap_MT=horzcat(y,y,y);
colormap_MT=horzcat(yy,yy,yy);
in this case how would you get your 'idx'????
Matt Fig
Matt Fig le 14 Août 2012
Modifié(e) : Matt Fig le 14 Août 2012
I think that INTERP1 will not work. But this seems to:
A = rand(3,3)
C = [0 0 0;.5 .5 .5;1 1 1];
imagesc(A,[0 1]); % Note the second arg.
colormap(C)
idx = ceil(A*size(C,1))
So for your colormap colormap_MT, use:
idx = ceil(A*size(colormap_MT,1))
no, sorry, its not working. the outcome shoul be a colormap with 0s and 1s only... and its not being mapped correctly.... i still dont 'get what I see'...
Matt Fig
Matt Fig le 14 Août 2012
Modifié(e) : Matt Fig le 14 Août 2012
Oh, you said you want the indexes into the colormap, which is what I gave you. Now you want to return the values of the colormap using those indices. That's just another step.
Look at idx here:
A = rand(3)
C = [0 0 0;.5 .5 .5;1 1 1];
imagesc(A,[0 1]); % Note the second arg.
colormap(C)
idx = ceil(A*size(C,1))
So if you want to look at the colors for each pixel of A, index into the colormap:
C(idx(1,1),:) % The color of pixel A(1,1)
C(idx(2,1),:) % The color of pixel A(2,1), etc.
So for your task, do the same.
Now since you only have black and white, the first column of idx can denote the color. Take a look:
A = rand(3)
k=32; % cycles
x=(0:2*pi/63:2*pi)';
y=(-cos(k.*x)+1)./2; % sinusoidal waveform between 0 and 1
% variant (black and white)
yy=y;
yy(find(y>=0.5))=1;
yy(find(y<0.5))=0;
% colormap_MT=horzcat(y,y,y);
colormap_MT=horzcat(yy,yy,yy);
imagesc(A,[0 1])
colormap(colormap_MT)
idx = ceil(A*size(colormap_MT,1));
% Finally, we index into the map with idx. Compare to the image.
CI = reshape(colormap_MT(idx,1),size(A))
You got it man! Its working for me now!
I dont know how the reshape function works... would it hold with zeros?
that you very much Matt
I don't know what you mean by holding with zeros. But the reshape function does pretty much what the name indicates. Take a look:
X = [1 0 2 0 3 0 4 0 5 0 6 0]
reshape(X,4,3)
reshape(X,3,4)
reshape(X,6,2)
reshape(X,2,6)
reshape(X,12,1)
you are absolutely right Matt. What I saw is that none of the elements from A (or idx) can be 0 for the reshape function to work.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by