MATLAB: Problem displaying 12 bit colormap, bug

12-bit colormap

Hello,
I want to make a custom colour map to display my 12 bit images. The colour map I have created goes from:
dark red –> yellow –> white –> (black for only saturated pixels)
R = [linspace(0.25,1,512)'; ones(1535,1); 0];
G = [zeros(512,1); linspace(0,1, 512)'; ones((1023),1); 0];
B = [zeros(1024,1); linspace(0,1,1023)';0];
handles.myColourmap = [R G B];
snapshot = getsnapshot(handles.obj);
imshow(snapshot, [0 2^12-1], 'Parent', handles.axes2)
colormap(handles.myColourmap)
colorbar('NorthOutside')
The problem is that the colour map doesn't work at 12 bit, even though I have 12 bit images (they are stored in a 16-bit container). The problem manifests itself as every pixel value taking the first colour value from the colour map, and correspondingly, the colorbar displays only this colour for all values.
One way I can slightly solve this is to use an 8-bit colour map instead:
R = [linspace(0.25,1,64)'; ones(191,1);0];
G = [zeros(65,1); linspace(0,1, 64)'; ones((126),1);0];
B = [zeros(128,1); linspace(0,1,127)';0];
handles.myColourmap = [R G B];
This results in the colour map correctly displaying, almost. I assume it scales the colour mapping up from 8 bit to 12 bit, which means that when I wanted my saturated pixel (4095) to display black, I now have the last 15 or 16 pixel values displaying as black, which is not useful for my application at all.
I get the same problem when using a 12 bit colormap using one of the inbuilt functions, eg colormap(gray(4096)), displays every pixel as black, and sets every value in the colorbar to black.
There is nothing in the colormap help that says anything about how long the colour map can be, so why isn't it working, and how can I make it work?
Thank you in advance,
Nicole

Best Answer

Hi,
I'm not sure, if I understand correctly, but have you tried to display the image as an indexed image? Your 12 bit images, are they indexed? I.e., does your image has one channel (only) with values between 0 and 2047? In this case
imshow(snapshot, handles.myColourmap)
or, I'm not sure, maybe
imshow(snapshot+1, handles.myColourmap)
should work ...?
Titus