How to copy colormap from an existing image

조회 수: 40 (최근 30일)
Alexei M
Alexei M 2020년 5월 7일
편집: Alexei M 2020년 5월 9일
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