How to copy colormap from an existing image
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alexei M
el 7 de Mayo de 2020
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.)
0 comentarios
Respuesta aceptada
David Goodmanson
el 8 de Mayo de 2020
Editada: David Goodmanson
el 8 de Mayo de 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');
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 comentarios
Image Analyst
el 9 de Mayo de 2020
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.
Más respuestas (1)
Image Analyst
el 9 de Mayo de 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.
0 comentarios
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!