

An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. Each row in the matrix defines one color using an RGB triplet. Colormaps can be any length, but must be three columns wide. The images I used have the same color scale now, both the saved one and the one shown in figure. A colormap is an m-by-3 matrix of real numbers between 0.0 and 1.0. MATLAB draws the objects by mapping data values to colors in the colormap. % Convert indexed image to RGB using 256-colors jet map Usage: ('C' is color matrix) colormap (C/255) in matlab import matplotlib as mpl in python cm (C/255.0) plt.imshow (., cmapcm) for example.

Then it might happen that an image was written with a colormap different from the one applied to image figure (for example, if a figure called after imwrite).įinally I found this solution (no image pre-scaling needed): % Create indexed image, explicitly using 256 colors Number of Colors: Style: Matrix Plaintext. While using this command, we cannot specify the length of colormap as per our choice. Then, if any image is shown with a colormap, for example if imshow('cameraman.tif'), colormap('jet') is executed, all default colormaps become 256x3 (can be verified with jetMap=jet before and after). This command is used to set the color of the figure to some predefined colormap. Usage: ('C' is color matrix) colormap(C/255) in matlab import matplotlib as mpl in python cm (C/255.0) plt.imshow(., cmapcm) for example Or, copy a 256-color preset: blues dawn dusk fire golds grays greens ice kryptonite purples redblue reds seashore teals. Just after Matlab starts, its default colormaps (including 'jet') are set to 64 colors (64x3). However, I might found a reason of an original problem. The colorbar shows the correspondence between colors and categories. Looking at the Jet colormap (the old Matlab default) in this way the problem becomes clear.

Solution by hbaderts worked well for me, but later I found out that some images were still scaled slightly different way from imshow. The colormap is set to match the colors of your categories (black for empty bins, green, orange, yellow, and red for the other categories). The 3D color inspector plugin for imageJ provides a handy tool to visualise the colormaps in Lab space.
