MATLAB image processing

0

How to convert a grayscale image to a color image (rgb)?

img=im2double(imread('37_M.jpg'));
figure(1),
imshow(img,[]),
title('original');
t=imgaussfilt3(img,0.2);
figure(2),
imshow(t,[]),
title('original filtro');
img2=rgb2gray(t);
figure(3),
imshow(img2,[]),
title('original gray');

I want a final image that is the merging of the img with the img2 after it is segmented and contoured, but since img is 3D and img2 2D I do not know how to do it.

    
asked by anonymous 31.05.2016 / 21:23

1 answer

1

You can not convert grayscale images back to RGB because you do not have enough information. Many different combinations of RGB values convert to the same grayscale level, so if all you have is the grayscale level then you can not know which of the RGB values that map exactly the same grayscale as the original RGB. In your case, you do not need a color image, but only a 3-channel grayscale image (such as rgb format). So you just need to turn the image into grayscale (1 channel) in 3-channel format.

For this you can use:

img2 = cat(3,img2,img2,img2);

or

img2 = repmat(img2,[1 1 3]);

Now both images im and im2 have the same format (check using size (img) and size (im2)).

    
22.12.2016 / 15:58