heatmap to color image matlab

I have a grayscle image. I can create a heatmap in matlab using:

        I = imagesc(I);

it displays the intensity values in color. I want to get a color image using this heatmap. How can I do it?

This is the output of imagesc:

Answers


Presumably by "color image" you mean an RGB or truecolor image (an image array with three color channels). And what you're calling a "heatmap" is the colormap that Matlab applies by default to grayscale images (image arrays with only one color channel). A grayscale image plus a color map is referred to as an indexed color image (read more about that here). You can use the ind2rgb function to convert from indexed color to RGB:

IMG_gray = rand(100);
map = colormap; % Get the current colormap
IMG_rgb = ind2rgb(IMG_gray,map);

Note that by default the colormaps in Matlab use only 64 colors rather 256. To get smoother color gradations you can set the colormap manually via map = colormap(jet(256)); or map = colormap(hsv(256));.

If you then want an image file, you can use imwrite, which can take either RGB images or indexed color images with colormaps as input.


Scale the intensity values in your image as imagesc does, and use a colormap (jet is default):

N = 256;
IN = round(N * (I-min(I(:)))/(max(I(:))-min(I(:))));
cmap = jet(N); % see also hot, etc.
IRGB = ind2rgb(IN,cmap);

Need Your Help

Eclipse maven-enabled web app references workspace projects, but those are not deployed when running Tomcat server

java eclipse maven m2e m2e-wtp

I have a web application (Eclipse's Dynamic Web App) which uses Maven (m2e-wtp) for the build and dependencies management. This web app's POM references a few other projects in my workspace, which ...

CSS menu won't stay active after clicking

css menu

I found a nice drop-line menu and styled it like I need it. Now I only need to add 1 thing.