Conversion From Gray scale to RGB colormap

3 Ansichten (letzte 30 Tage)
Berkay Yaldiz
Berkay Yaldiz am 11 Apr. 2021
Kommentiert: Image Analyst am 11 Apr. 2021
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Apr. 2021
Don't so it like that. Simply use ind2rgb()
rgbImage = ind2rgb(indexedImage, cmap);
  2 Kommentare
Berkay Yaldiz
Berkay Yaldiz am 11 Apr. 2021
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 am 11 Apr. 2021
Since it's no longer a MATLAB question, you'd be better off asking in a C language question and answer forum.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Orange finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by