creating a custom color map

조회 수: 564 (최근 30일)
Lisa
Lisa 2015년 2월 25일
댓글: DGM 2023년 1월 16일
I'm looking to create a custom color map so that an image appears as various shades of red. I understand that this would require changing the matrix of the RGB image to an image consisting of _,0,0, but I am not sure of the best way to go about this
  댓글 수: 2
Markus Kokot
Markus Kokot 2020년 12월 29일
is a there a solution?
Image Analyst
Image Analyst 2020년 12월 29일
Yes, two of them. Did youi scroll down and look at them?

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2015년 2월 25일
You don't need an RGB image. In fact RGB images don't even take a colormap. If you want an RGB image, just create one
rgbImage = cat(3, grayImage, zeros(size(grayImage), 'uint8'), zeros(size(grayImage), 'uint8'));
imshow(rgbImage);
Or use a colormap with your grayscale image:
grayImage = imread('moon.tif');
imshow(grayImage);
colorMap = [linspace(0,1,256)', zeros(256,2)]
colormap(colorMap);
colorbar;
  댓글 수: 3
Image Analyst
Image Analyst 2020년 5월 5일
Try this:
yellowMap = [linspace(0, 255, 256)', linspace(0, 255, 256)', zeros(256, 1)]
colormap(yellowMap);
DGM
DGM 2023년 1월 16일
I'm not so sure that's a simple false color image. It may be a composite. That possibility aside, here's a better approximation:
% reduced sampling
x0 = [0 0.008889 0.03556 0.08 0.1422 0.2222 0.32 0.4356 0.5644 0.68 0.7778 0.8578 0.92 0.9644 0.9911 1];
CT0 = [0 0 0.1; 0.002914 0.01103 0.1143; 0.01221 0.02996 0.1352; 0.02938 0.04745 0.1489; 0.05622 0.07057 0.1604; ...
0.09753 0.1003 0.1803; 0.1756 0.1568 0.2046; 0.2908 0.2456 0.2395; 0.4299 0.355 0.2906; 0.5757 0.4753 0.3516; ...
0.7288 0.6116 0.427; 0.8555 0.7448 0.5124; 0.9486 0.8541 0.6076; 0.9871 0.9329 0.7081; 0.9983 0.983 0.809; 1 1 0.95];
% generate a new uniform table of desired length
N = 256;
xf = linspace(0,1,N);
CT = interp1(x0,CT0,xf,'pchip');
% use the map to plot something
x = linspace(-pi/2,pi/2,30);
y = x.';
z = sin(x).*sin(y);
surf(x,y,z)
colormap(CT)
colorbar
view(-17,50)
Of course, the dark blue is essentially black against this awful white background, but that's what you get.
Note that even though we might be able to define some trajectory through some color space, there's no information which unambiguously informs us about the rate at which that path is traversed with respect to the mapped variable. Here, we're assuming it's linear.
If you want the map shifted more toward blue or more toward yellow, you can use MIMT ctshift().
% generate some example images using shifted versions of the CT
testsweeps = cat(3,ctshift(CT,-0.67), ...
ctshift(CT,-0.33), ...
ctshift(CT,0), ...
ctshift(CT,0.33), ...
ctshift(CT,0.67));
testsweeps = permute(testsweeps,[3 1 2]);
testsweeps = imresize(testsweeps,[128 256],'nearest');
imshow(testsweeps)

댓글을 달려면 로그인하십시오.


Alka Nair
Alka Nair 2015년 2월 25일
편집: per isakson 2015년 2월 25일
The 'colormapeditor' helps in displaying the current figure's colormap and customizing it. To find more information about colormapeditor, please refer to the documentation at:

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by