using two 73728 x 3 matrix with RGB and Contour to draw a heatmap

3 visualizzazioni (ultimi 30 giorni)
i have used RGB like :
R=[1 0; 0 0]; G=[0 0.3; 0 0]; B=[0 1;0 0];
R = interp2(R,8);
G = interp2(G,8);
B = interp2(B,8);
I = uint8(255*cat(3,R,G,B));
image(I)
and i think I should be a 257*257*3 matrix, and also i have used some limits assign to RGB. But didnt work like the left image. how can i improve.

Risposte (1)

Udit06
Udit06 il 19 Mar 2024
Hi Jinyang,
In my understanding you want to create a color label similar to as shown in the top portion of the left image. You can use HSV color space to create the same, and then use "hsv2rgb" function to convert the colors back to RGB domain. Here is the code implementation for the same.
% Number of colors
numColors = 10;
% Create a figure
figure;
hold on;
% Generate evenly spaced hues from 0 to 1
hues = linspace(0, 1, numColors + 1);
hues(end) = []; % Remove the last element to avoid repeating the first color
% Generate colors in HSV space
% Here, we set saturation and value to 1 to get the brightest and most vivid colors
saturation = 1;
value = 1;
hsvColors = [hues', saturation * ones(numColors, 1), value * ones(numColors, 1)];
% Convert HSV colors to RGB
rgbColors = hsv2rgb(hsvColors);
% Draw each color as a rectangle using patch
for i = 1:numColors
patch([i, i, i+1, i+1], [0, 1, 1, 0], rgbColors(i, :));
end
axis off; % Remove axis for better visualization
xlim([1 numColors+1]); % Adjust x-axis limits to fit the color patches
You can refer to the following MathWorks documentation to understand more about HSV to RGB space conversion.
I hope this helps.

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by