MATLAB: Returning the indexes of an image displayed with a specific colormap

colormap imagesc

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.

Best Answer

  • 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))