MATLAB: How to save image with custom colormap (imwrite problems)

colorcolormapimageImage Processing Toolboximwritejpegpngtiff

Hello everyone, I am trying to save a large matrix who's cells contain one of 6 possible values (0, 50, 100, 150, 200, 255)(if needed those values can be changed). I also have a 6 by 3 matrix as color map: cmap=[153 76 0; 0 128 255; 96 96 96; 224 224 224; 255 255 255; 0 0 0]/255; (those colors need to stay as they are).
I try to save the image like this
imwrite(matrix, cmap, 'name.png');
but the image is saved with only two colors. I have tried different image types and different rang values for the matrix but no solution.
Can anyone help me with this?
Thank you very much.
Cheers,
Camilo

Best Answer

Try imwrite() and see if that works. Use imread() to see if the saved colormap comes back with only 2 colors, or all 6.