how to convert a gray scale image to color image using matlab
이전 댓글 표시
Hi all, Is there any possibility to convert ab gray scale image into color image.If so, kindly suggest me.
Thanks in advance
답변 (5개)
Jan
2013년 9월 11일
It depends on how the converted image should look like, so please explain any details. Examples:
Gray = rand(200, 200);
RGB1 = cat(3, Gray, Gray, Gray); % information stored in intensity
RGB2 = Gray;
RGB2(end, end, 3) = 0; % All information in red channel
GrayIndex = uint8(floor(Gray * 255));
Map = jet(255);
RGB3 = ind2rgb(GrayIndex, Map);
And there are many many other possible solutions.
댓글 수: 5
learningmat
2013년 9월 11일
Jan
2013년 9월 11일
This is not possible. converting an RGB image to grayscale deletes information and there is no way to obtain these information back again.
Image Analyst
2013년 9월 11일
What happened to A? Why is it no longer available in your code? Did you use "clear" to get rid of it? If so, just don't do that and you'll have the original A.
Image Analyst
2023년 4월 2일
@Jule to split up into channels, you can use
[r, g, b] = imsplit(rgbImage);
r, g, and b will be gray scale versions of each color channel.
If you want to keep it as RGB you can blacken specific channels in place, like
% Make it look red by blackening the green and blue channels.
rgbCopy = rgbImage;
rgbCopy(:, :, 2) = 0; % Erase green channel.
rgbCopy(:, :, 3) = 0; % Erase blue channel.
% Make it look green by blackening the red and blue channels.
rgbCopy = rgbImage;
rgbCopy(:, :, 1) = 0; % Erase red channel.
rgbCopy(:, :, 3) = 0; % Erase blue channel.
% Make it look blue by blackening the red and green channels.
rgbCopy = rgbImage;
rgbCopy(:, :, 1) = 0; % Erase red channel.
rgbCopy(:, :, 2) = 0; % Erase green channel.
You can also use cat(3,...):
[r, g, b] = imsplit(rgbImage);
% Create an image of all zeros
blackImage = zeros(size(r, 1), size(r, 2), class(rgbImage));
% Make an RGB image look red by combining
% the red channel with two black channels.
rgbCopy = cat(3, r, blackImage, blackImage);
% Make an RGB image look green by combining
% the green channel with two black channels.
rgbCopy = cat(3, blackImage, g, blackImage);
% Make an RGB image look blue by combining
% the blue channel with two black channels.
rgbCopy = cat(3, blackImage, blackImage, b);
sidra
2013년 9월 11일
2 개 추천
Nirmala , try the following , its a very simple and efficient code to convert grayscale images to RGB using a specified colormap.
댓글 수: 4
Image Analyst
2013년 9월 11일
It will be color, but not the original color of course.
@Image Analyst: Ya not the original color, that's impossible , but using a specified colormap.
@Image Analyst / Jan Simon : I have posted a queston about principle component and closest axis. It would be really great if you would help me out.
Youssef Khmou
2013년 9월 12일
편집: Youssef Khmou
2013년 9월 12일
So how they did retrieve old Black and White movies , made them Colored like they were recorded in RGB?
Image Analyst
2013년 9월 12일
I believe I heard that most of that was done "by hand" - by artists - with some help from digital computers to continue colors onto the next frame. See https://en.wikipedia.org/wiki/Colorizing
To answer the original intent of the question, there is no trivial way to return a grayscale image back to its original color. That information is gone. Your options are:
- Go back to the source image before it was converted to grayscale
- Manually colorize it by some means
- Train an AI to guess what color a banana is
Only one of those options will get you back to the original image.
Otherwise, consider the conspicuously low-effort example of manual colorization:
A = imread('cameraman.tif');
B = imread('cmancolorize.png');
% i bet you didn't know cameraman was a smurf in a salmon shirt
Bycc = rgb2ycbcr(B);
Bycc(:,:,1) = 219*(im2double(A).^0.8) + 16;
C = ycbcr2rgb(Bycc);
imshow(C)
Honestly, I think it should be obvious that color information has been permanently lost. So I have to assume that the hundreds of people looking at this question every month are surely thinking of a less-than-obvious interpretation of the question.
With that in mind, there are a number of ways to add color information to a grayscale image. The following link covers a handful of ways, including simple colorization methods and basic application of colormaps.
Tallha Akram
2013년 9월 11일
0 개 추천
[X,map] = imread('trees.tif');
gmap = rgb2gray(map);
figure, imshow(X,map), figure, imshow(X,gmap);
figure; imshow(X,gmap); colormap(map);
댓글 수: 10
learningmat
2013년 9월 11일
Tallha Akram
2013년 9월 11일
which matlab version you are using. Code is working fine with me.
Image Analyst
2013년 9월 11일
Nirmala: Don't worry about it - that code (from the help for rgb2gray) does not turn a grayscale image into a color image as you requested. It displays an indexed image in color, and then displays the indexed image in grayscale. No color image is produced and stored in a variable like you wanted. (Actually no image variable of any type is created.)
Julie Ann Serrano
2016년 10월 5일
Hi. Do you guys know how to convert Grayscale image into temperature in Matlab? Its the grayscale feature of thermal image. Please explain the details. Thanks a lot.
Walter Roberson
2016년 10월 5일
You need to have a mapping between greyscale level and temperature. The mapping will not necessarily be linear.
IR images are often shown as greyscale, and generally brighter means hotter. But you have to worry about band for IR because we cannot assume blackbody radiation from thermal equilibrium for a number of situations of interest. For example in near infrared, different biological molecules vibrate at different frequencies and have preferred radiation wavelengths, so bright in one IR image might reflect compounds that radiate on the sensitive frequency rather than continuous spectra due to heat
Julie Ann Serrano
2016년 10월 5일
Thanks for answering. Really appreciate that. What we're going to do is to capture the thermal image of a plant. Can you give me some recommendations on how can measure the temperature of the plant itself?By using Matlab? What exactly are the considerations and parameters involved? Can you help me?. Thank you so much. :)
Walter Roberson
2016년 10월 5일
The appearance of vegetation is pretty sensitive to which IR band (and filtering) is being used, so you cannot assume that brightness is due entirely to temperature differences.
"The pigment in plant leaves, chlorophyll, strongly absorbs visible light (from 0.4 to 0.7 µm) for use in photosynthesis. The cell structure of the leaves, on the other hand, strongly reflects near-infrared light (from 0.7 to 1.1 µm). The more leaves a plant has, the more these wavelengths of light are affected, respectively."
So for that particular range of IR, "bright" can just mean that it has a lot of leaves reflecting ambient infrared preferably. See also http://www.nconemap.com/Portals/7/documents/Using_Color_Infrared_Imagery_20110810.pdf for more on how that property is used.
The situation is different if you measure in the far infrared; see https://en.wikipedia.org/wiki/Thermal_radiation
And notice, "The total amount of radiation of all frequencies increases steeply as the temperature rises; it grows as T^4, where T is the absolute temperature of the body."
Therefore if you had a way of measuring the total amount of radiation on all frequencies then you could take the fourth root to determine the proportional temperature. But you do not have a way to get that total radiation, and at the moment you do not know whether your sensors are linear in measuring that T^4.
So what do you need? Well, you can look for the frequency of peak radiation in the far infrared, under a black-body assumption. But to study peak frequency your equipment needs to be able to measure at multiple frequencies. If you have a greyscale image, chances are high that it is being measured over a band of frequencies in which all that can be registered is the total energy over that band, without being able to distinguish where the peak frequency was.
You need to find out a lot more about your available equipment.
Julie Ann Serrano
2016년 10월 31일
Hi we're gonna use the Flir one camera for iOs
Image Analyst
2016년 10월 31일
Ask FLIR how to import the temperature matrix into MATLAB. I'm sure they must have code for doing that. Now you will have a matrix that has a spatial record of what temperature is where in your image, assuming you inputted the correct emissivity value. Ask FLIR because they might know what an accurate emissivity is for the type of plants you're looking at.
If you meant how to measure temperature directly, then look into thermocouples that interface with MATLAB. This will give you a "second opinion" on the temperature of the plants that you can check your camera against. Perhaps you can then adjust the emissivity of the camera until its values match the thermocouple's values.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
