how to convert a gray scale image to color image using matlab

조회 수: 176 (최근 30일)
learningmat
learningmat 2013년 9월 11일
댓글: Image Analyst 2023년 4월 2일
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
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
Jule
Jule 2023년 4월 2일
편집: Jule 2023년 4월 2일
tryin' to convert my unit8 image to green channel or blue channel, respectivel.
What should I change in:
RGB2 = Gray;
RGB2(end, end, 3) = 0; % All information in red channel
? Thnx
Image Analyst
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
sidra 2013년 9월 11일
Nirmala , try the following , its a very simple and efficient code to convert grayscale images to RGB using a specified colormap.
  댓글 수: 4
Youssef  Khmou
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
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

댓글을 달려면 로그인하십시오.


DGM
DGM 2022년 5월 2일
편집: DGM 2022년 5월 2일
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
Tallha Akram 2013년 9월 11일
[X,map] = imread('trees.tif');
gmap = rgb2gray(map);
figure, imshow(X,map), figure, imshow(X,gmap);
figure; imshow(X,gmap); colormap(map);
  댓글 수: 10
Image Analyst
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.

댓글을 달려면 로그인하십시오.


David Mills
David Mills 2017년 2월 22일

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by