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

조회 수: 1 (최근 30일)
Enne
Enne 2021년 4월 28일
답변: Sanju 2024년 2월 29일
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
Adam Danz
Adam Danz 2021년 5월 13일
I came across this file exchange submission today that may be helpful to you
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에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by