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?
조회 수: 198 (최근 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!