How to copy colormap from an existing image

33 次查看(过去 30 天)
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.)

采纳的回答

David Goodmanson
David Goodmanson 2020-5-8
编辑:David Goodmanson 2020-5-8
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');
image(micro_m)
% 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;
figure(2)
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.
  6 个评论
Image Analyst
Image Analyst 2020-5-9
That's standard MATLAB syntax. It's basically startingValue : increment : endingValue. So it's [225, 224, 223, ..... 19,18,17,16]. You could do it like you did but then the first element of the colormap would be the color at the top of the bar, and this is not the convention in MATLAB. The first row in the N-by-3 colormap is the RGB color of the bottom of the colorbar, not the top of it.
Alexei M
Alexei M 2020-5-9
编辑:Alexei M 2020-5-9
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.)

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2020-5-9
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.

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by