I noticed that MATLAB sometimes displays my colors incorrectly. I am not sure if this is a programming error on my side, or if it is a real mistake in MATLAB. I noticed this behavior with some regularity over the last year or so.
This time I decided to take a picture of the figure with the corresponding error (taken on MATLAB 2011b in Windows 7, 64 bit):

The code displaying the image in question is as follows:
figure;
clf;
cla;
imshow(matrix, []);
colormap(cmap);
set(gca, 'Clim', [0 highest_index]);
Where:
matrixhas a type uint32(although I also tried to explicitly distinguish matrixas doublebefore the call imshow)- Values in
matrixare between 0and900 cmaphas 901recordshighest_index 900
RGB 259 matrix [1, 0, 0.1] , colormap cmap, cmap(300, :) = [1, 0, 0.1] ( , 259 300 , 0).
:
? ? -, ?
1:
CDataMapping direct scaled, .imagesc imshow, .RGB (.. indexed image true color; . ), i_rgb = ind2rgb(i_indexed, cmap), , .
, true color, , RGB (.. , MATLAB ).
2:
:
h_f = figure(1);
clf;
i_spiral = spiral(40);
h_i = image(i_spiral);
% Synthesize a colormap first in HSV and then transform it to RGB:
max_i_spiral = max(i_spiral(:));
m = max_i_spiral;
h = (0:m-1)'/max(m,1);
cmap_spiral = hsv2rgb([h ones(m,2)]);
colormap(cmap_spiral);
% If I comment out the following two lines or use imshow instead of image,
% it makes no difference (I still get the same error):
set(gca, 'Clim', [1 max_i_spiral]);
set(h_i, 'CDataMapping', 'direct');
:
