imagesc make all negatives values black

조회 수: 11 (최근 30일)
Robert
Robert 2016년 3월 29일
댓글: Walter Roberson 2016년 3월 29일
I have the following code which is part of a subplot series. I want to change it so that all negative values become a certain colour (preferably black). I am stuck as to how to achieve this.
figure(3)
subplot(3,3,1)
imagesc(coeffA40)
title ('A40 Coefficients')
caxis([minCoeff, maxCoeff])
myColorMap = hsv(256);
myColorMap(1,:) = 1;
colormap(myColorMap);
grid on
ax = gca
ax.LineWidth = .75
ax.GridColor = 'k'
ax.GridAlpha = .2
ax.XTick = [10 20 30 40];
ax.YTick = [10 20 30];
ax.XTickLabel = {'', '', '', ''};
ax.YTickLabel = {'','',''};
ax.TickLength =[0.0 0.0]
ax.XTickLabelRotation = 45
Thank you in advance for any help!

답변 (1개)

Image Analyst
Image Analyst 2016년 3월 29일
Several ways. One is to create a temporary image
displayedImage = coeffA40; % Initialize
displayedImage(displayedImage <=0) = 0;
cmap = jet(256);
cmap(1,:) = 0; % Lowest gray level appears black.
imshow(displayedImage);
colormap(cmap);
colorbar;
Another might be to alter the colormap so that it applies between 0 and the max.
cmap = jet(256);
cmap(1,:) = 0; % Lowest gray level appears black.
imshow(coeffA40);
colormap(cmap);
colorbar;
caxis([0, max(coeffA40(:))]);
(Both of these are untested - just off the top of my head.)
  댓글 수: 3
Image Analyst
Image Analyst 2016년 3월 29일
Set the nans to the max value (or the white value) before display, something like:
displayedImage(isnan(displayedImage)) = max(displayedImage(:));
Walter Roberson
Walter Roberson 2016년 3월 29일
image(coeffA40, 'AlphaData', double(~isnan(coeffA40)) )

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by