Justin
Justin

Reputation: 95

Create an RGB image from a grayscale image and custom color map

I have a grayscale matlab image that I would like to convert to an RGB image with a custom color map. I have no problems displaying the image with the colors I want, but when I use imwrite, the figure doesn't save as an RGB image. Instead of 300x1000x3 data structure, it is simply 300x1000. What can I do to fix this?

m=255;
map = ones(m,3);
strongsignal = [3, 7, 41]./ 255;
DRAQ = [100, 85, 105]./255;

R = linspace(DRAQ(1),strongsignal(1),254); 
G = linspace(DRAQ(2),strongsignal(2),254);
B = linspace(DRAQ(3),strongsignal(3),254);

Sample = [R', G', B'];

i = imread('sliceXY045_660.png');
limits = graythresh(i);
i_adjust = im2bw(i,limits); 
map(2:255,:)= Sample;

imagesc(i_adjust)
colormap(map)
imwrite(i_adjust,map,'colormap45.png')

Upvotes: 3

Views: 1085

Answers (1)

lakshmen
lakshmen

Reputation: 29064

cmap = colormap(map);
imwrite(i_adjust,cmap, 'colormap45.png', 'png');

Change the last part to this.. Hope this helps..

Upvotes: 1

Related Questions