Conversion From Gray scale to RGB colormap

2 次查看(过去 30 天)
Hello, I am trying to convert images from gray scale to RGB. Firstly, I tried it for the jet colormap, but I would like to do this for other possible colormaps which MATLAB has. I imported the 'car1.jpg' image and converted via these lines:
indexedImage = imread('car1.jpg');
Gray_Image= indexedImage(:,:,1)*0.299+indexedImage(:,:,2)*0.587+indexedImage(:,:,3)*0.114;
Then I gave "Gray_Image" variable to my function "gray_to_jet" to convert RGB. Although output seemed like "jet", there are differences between MATLAB's jet colormap. How can I exactly map the values like MATLAB? I am new to image processing, so any help including theoritical appreciated. Here is my function:
function [converted_image,Elapsed_time] = gray_to_jet(varargin)
input_image = varargin{1};
[row_number, column_number] = size(input_image);
C = uint8(255*colormap('jet')); % Convert 0-1 numbers in colormap to 0-255 and uint8.
converted_image = zeros(row_number, column_number, 3);
for idx = 1:row_number
for jdx =1:column_number
colormap_row= double(input_image(idx, jdx) ) + 1;
new_red_pixel = C(colormap_row, 1);
new_green_pixel = C(colormap_row, 2);
new_blue_pixel = C(colormap_row, 3);
converted_image(idx, jdx, 1) = new_red_pixel;
converted_image(idx, jdx, 2) = new_green_pixel;
converted_image(idx, jdx, 3) = new_blue_pixel;
end
end
end

采纳的回答

Image Analyst
Image Analyst 2021-4-11
Don't so it like that. Simply use ind2rgb()
rgbImage = ind2rgb(indexedImage, cmap);
  2 个评论
Berkay Yaldiz
Berkay Yaldiz 2021-4-11
Thank you for your answer, actually I need to do it this conversion in C by hand because it is a school project and I just figured it out the problem I think, I had to convert result to uint8 datatype.
Image Analyst
Image Analyst 2021-4-11
Since it's no longer a MATLAB question, you'd be better off asking in a C language question and answer forum.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by