Convert color map and a corresponding color scale to a matrix of numerical values.

31 vues (au cours des 30 derniers jours)
Siva Poornan
Siva Poornan le 28 Nov 2019
Modifié(e) : Luna le 29 Nov 2019
I have a color map and a corresponding color scale. How do i convert this to a matrix of numerical values?
For example, find the image attached. I have to convert this picture into a matrix of values in accordance to the color scale given.
This should be the opposite of the inbuilt function 'colorbar'.

Réponses (2)

Luna le 28 Nov 2019
Modifié(e) : Luna le 28 Nov 2019
What do you mean by opposite of inbuilt function colorbar?
colorbar is a function to create any colorbar near your axis. The colormap you are looking for is already defined as name 'jet'. If you want to make flip just use flip function.
Here is sample code. Read the comments.
colorbar; % creates default colorbar (with a yellow - green color)
c = jet(64); % 64x3 colormap matrix
colormap(c); % changes the color of the colorbar
% OR
colormap(flip(c)); % flips the colorbar upside down
  2 commentaires
Luna le 29 Nov 2019
Modifié(e) : Luna le 29 Nov 2019
In the above code c variable is the matrix. You can get higher size of it by changing the input of jet.
For example:
c = jet(1000000) % gives you 1000000x3 Matrix and each row represents R G B values between 0-1.
By the way, @Image Analyst's code convert your actual image into matrix cmap. You can use colormap(cmap) function to change your colorbar's color.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 28 Nov 2019
Read each channel of the image and transpose and concatenate
rgbImage = imread('image.png');
subplot(2, 1, 1);
impixelinfo; % Show RGB value on figure as you mouse around.
% Please crop image out of screenshot so there is no white padding.
[rows, columns, numberOfColorChannels] = size(rgbImage);
row = round(rows/2); % Take middle row.
redCurve = rgbImage(row, :, 1);
greenCurve = rgbImage(row, :, 2);
blueCurve = rgbImage(row, :, 3);
subplot(2, 1, 2);
plot(redCurve, 'r-', 'LineWidth', 3);
hold on;
plot(greenCurve, 'g-', 'LineWidth', 3);
plot(blueCurve, 'b-', 'LineWidth', 3);
grid on;
title('Color Map', 'FontSize', 15);
xlabel('Input Gray Level', 'FontSize', 15);
ylabel('Output Color Level', 'FontSize', 15);
legend('Red Curve', 'Green Curve', 'Blue Curve', 'location', 'east');
cmap = [redCurve(:), greenCurve(:), blueCurve(:)]
0001 Screenshot.png
  2 commentaires
Image Analyst
Image Analyst le 29 Nov 2019
I solve that kind of problem with the attached demo where I get the temperature from an image using the color bar.

Connectez-vous pour commenter.


En savoir plus sur White dans Help Center et File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by