I convert RGB image to binary and do some processing on it. now i need to convert binary image to RGB image again in matlab?
I use this code:
%RGB to binary
c = imread('101200.jpg');
l=graythresh(c);
bww=im2bw(c,l);
%do processing on bww and name it s
.
.
.
%binary to RGB
[X, map] = gray2ind(s,16);
RGB = ind2rgb(X,map);
but result is a gray scale image again.
Your problem is that [X, map] = gray2ind(s,16);
is partly equivalent to map = gray(16);
. I.e. you get a colormap containing 16 gray levels.
Since your image is binary, it doesn't really make sense to display it in color. But if you really want to:
%binary to RGB
[X, map] = gray2ind(s,16);
RGB = ind2rgb(X,jet(16));
Of course, only two colors will be displayed, but this may suit you better than black and white.
Or to achieve what you want (which is not entirely clear in your question), perhaps just pass colormap to imshow()
, e.g.:
c = imread('cameraman.tif');
l=graythresh(c);
bww=im2bw(c,l);
imshow(bww,lines(2));
gives