How to convert color map into contour map?
Show older comments
I have a file of color map with known boundary coordinates and color bar scale either horizontal or vertical. How can we transform the color map into contour map, such that the value of contours expressed the same in the color bar values?
Accepted Answer
More Answers (1)
Walter Roberson
on 14 Jul 2025
YourImageArray = imread('Color map.jpg');
cropped_image = imcrop(YourImageArray, Crop_Rectange_Of_Image);
cropped_colorbar = imcrop(YourImageArray, Crop_Rectangel_of_Colorbar);
mean_colormap = reshape(mean(cropped_colorbar, 1, "native"), [], 3); %assuming horizontal colormap
image_idx = rgb2ind(cropped_image, mean_colormap);
At this point, image_idx is a linear range mapping color into index in colormap.
At this point, you have the problem that your colormap is decidedly non-uniform in a way that is neither linear nor logarithm. We cannot guess how to interpolate colormap index into temperature properly. The distance from -50.8 to -24.8 is 26 degrees, but the distance from -24.8 to 10.4 is 35.2 degress. The distance from 10.4 to 19.2 is 8.8 degrees. There is no logic in those choice of distances, so we have to assume that within the 35.2 degree gap that some unknown portion of the range is a linear mapping but below that in the range it switches to log scaling. There is no way for us to know where that breakpoint is.
With us being unable to map colormap index into temperature due to the inconsistent mapping, we are unable to draw a contour plot.
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!












