MATLAB image processing

Asked

Viewed 707 times

0

How to convert an image to grayscale (Gray) 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 junction of the img with the img2 after segmented and with contours, but as img is 3D and img2 2D do not know how to do.

  • Add and your question some code! Matlab is a very reserved section and not everyone here knows this program!

1 answer

1

You cannot 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 cannot know which of the RGB values map exactly the same grayscale as the original RGB. In your case, you don’t need a color image, but only a 3-channel gray image (such as rgb format). Thus, you just need to turn the image into grayscale (1 channel) in 3-channel format.

For such you can use:

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

or

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.