converting gray to RGB
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
having RGB image then converting it to gray image for calculations
how to get it back to RGB image ??
I=imread('yellowlily.jpg');
A=rgb2gray(I);
0 comentarios
Respuestas (2)
Stephan
el 9 de Dic. de 2018
Hi,
"...rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components:
0.2989 * R + 0.5870 * G + 0.1140 * B
These are the same weights used by the rgb2ntsc function to compute the Y component."
Now think about one pixel in a gray scale image. Its value is 0...255. So what you want is to find 3 unknown values for the 3 color components R, G and B from one single value with only knowing the weights used, when it was converted to gray. Convince yourself, that there are a plenty of possible combinations for R, G and B values that lead to one and the same result in a gray scale. So how do want to choose the correct combination without additional informations?
From the mathematical point of view this is not possible. So the conclusion is that you need an idea which allows you to reconstruct the original values by using additional informations. Maybe you can do this by indexing the pixels, and retrieving the needed information from the original image.
Best regards
Stephan
0 comentarios
Image Analyst
el 9 de Dic. de 2018
Try this:
rgbImage = cat(3, grayImage, grayImage, grayImage);
It will be an RGB image, but all the colors are still gray of course, not your original colored image. If you know what colors each gray level should be then you can list them in a colormap and use ind2rgb
rgbImage = ind2rgb(grayImage, yourColorMap);
Of course the best way is to just keep your RGB image in memory. You said you had the RGB image at one point, and then plugged it into rgb2gray(). So you already have the RGB color image. Just do some things to make sure it's still available in whatever workspace you need it. See the FAQ for several ways to do this.
0 comentarios
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!