How can I link the color of an image to a defined temperature?

2 次查看(过去 30 天)
I'm working on this image as following:
RGB = imread('Flame1.jpg');
[X,map] = rgb2ind(RGB,3);
imagesc(X)
cmap = colormap(map);
colormap('hsv')
axis off
axis image
c = colorbar;
c.Limits = [-4 4];
c.Ticks = [-4 1 4];
c.TickLabels = {'800\circ C','900\circ C','1000\circ C'};
In this way on the colorbar to each temperature (800 °C, 900 °C and 1000 °C) it will correspond red, green and blue respectively as it's showed in the colormap. However, what I did is a manual assignement since I customize the colorbar manually. I was wondering if there is a way to link the colors of the colorbar and the colormap to the temperature.
If not, is there a better way to link the colors to the assigned temperature?
  6 个评论
Enne
Enne 2021-5-19
Thank you @Adam Danz, I tried to run this code with the examples given by the user itself but apparently it doesn't work

请先登录,再进行评论。

回答(1 个)

Sanju
Sanju 2024-2-29
Hi Enne,
I understand that you want to link the colour of an image automatically to a defined temperature,
Currently there is no built-in functionality in MATLAB that directly links the colors of the colorbar and the colormap to the temperature values. The manual assignment you have done is a common approach in such cases.
However, if you have a specific temperature-to-color mapping that you would like to achieve, you can create a custom colormap using the colormap function. By defining a colormap that smoothly transitions between colors, you can visually represent the temperature values with corresponding colors.
To create a custom colormap you may refer to the following code:
% Define the temperature values and their corresponding colors
temperature = [-4, 1, 4];
colors = [1 0 0; 0 1 0; 0 0 1]; % Red, Green, Blue
% Create a custom colormap
custom_cmap = interp1(temperature, colors, linspace(-4, 4, 256));
% Apply the custom colormap
colormap(custom_cmap);
%Add your code here
....
You can also refer to the following link for more information,
Hope this helps!

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by