I'm using imagesc to display data in grayscale. I want to be able to set the color for one particular value to red. How do I accomplish this?
204 次查看(过去 30 天)
显示 更早的评论
I have a 2-d matrix of type double. I want to display the data while retaining the values in the image. The image is to be displayed in gray scale, except for a particular value which I'd like to show up in red. This value is not fixed and can be changed later. I want to use imagesc for this (and change the limits, i.e. imagesc(data,[min max]),colormap('gray') and I only want those pixels with the exact value to be red. Is there a way to do this?
回答(1 个)
Image Analyst
2016-9-22
Try using a colormap
cmap = gray(256);
% Set one gray level, 8, to red.
% Remember, row #1 is 0 gray levels.
% so row #9 is 8 gray levels.
cmap(9,:) = [1,0,0];
colormap(cmap); % Apply the custom colormap.
colorbar;
4 个评论
Image Analyst
2016-9-22
If you want 8 in a floating point image, it will be very very rare indeed. See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
You're going to have to set a tolerance and find pixels in that tolerance band. This might be easier to do if you create an RGB image than use a pseudocolor lookup table (colormap) on an indexed image.
GL1 = 7.995;
GL2 = 8.005;
binaryImage = grayImage >= GL1 & grayImage <= GL2;
% Extract the individual red, green, and blue color channels.
redChannel = grayImage ;
greenChannel = grayImage ;
blueChannel = grayImage ;
maxGL = max(grayImage(:));
redChannel(binaryImage) = maxGL;
greenChannel(binaryImage) = 0;
blueChannel(binaryImage) = 0;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
rgbImage = rgbImage / maxGL; % Scale to -1 range for display.
imshow(rgbImage);
That's untested code just off the top of my head.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Blue 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!