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
0 个评论
采纳的回答
Image Analyst
2021-4-11
Don't so it like that. Simply use ind2rgb()
rgbImage = ind2rgb(indexedImage, cmap);
2 个评论
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 Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!