How to copy colormap from an existing image

42 views (last 30 days)
I have an image that came from an imaging software that already comes complete with its own color bar. Below is an example so you know what I mean. I could use any image software to grab some RGB values from various points within the color bar. But then I'm not sure how to proceed. I can't figure out how to use the Colormap Editor at all... Like how do you put new colors into it?? I've browsed through some other questions that discuss how make color maps through commands, but the ones I've seen are for very specific discrete colors that the user knows. Here, I want to replicate the entire color bar--so probably 256 colors. How many colors do I need to sample to ger a reasonably accurate copy of this? And how do I interpolate them?
(The custom colormap doesn't have to match this exactly, just good enough so two images look like they're using the same colormap without any obvious color differences.)

Accepted Answer

David Goodmanson
David Goodmanson on 8 May 2020
Edited: David Goodmanson on 8 May 2020
HI Alexei
I copied the image you provided as a jpeg, used datatips to find coordinate points at the top and bottom of the colorbar and ran the following code. It shows the profile of the color map, with color intensity on the vertical and colormap row index on the horizontal. There are 210 rows, although the number of rows does not make too much difference since it is the scaled distance from 1 to rowmax = 210 that matters.
MODIFIED to incorporate Walter's comment below
micro_m = imread('micro_m.jpg');
% datatips show coordinates (20,16) and (20,225)
cmap = squeeze(micro_m(225:-1:16,20,:));
cmap = double(cmap)/255; % 0 <= values <=1 for colormap
n = size(cmap,1);
ind = 1:n;
plot(ind,cmap(:,1),'r',ind,cmap(:,2),'g',ind,cmap(:,3),'b');grid on
grid on
The colormap somewhat resembles 'jet' but is not the same.
Alexei M
Alexei M on 9 May 2020
Edited: Alexei M on 9 May 2020
Ohh... the increment! I forgot all about that part of the syntax.
Ok now it's clear, thanks! (Sorry about the silly question. Should've known that.)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 9 May 2020
See my attached demos where I grab the colorbar from an image and create an colormap from it. Then I invert the colormap to turn the pseudocolored image back into the gray scale/indexed image.





Community Treasure Hunt

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

Start Hunting!