필터 지우기
필터 지우기

How do I overlay a contour plot for a ROI onto a grayscale image?

조회 수: 12 (최근 30일)
Jeremy Ahner
Jeremy Ahner 2022년 7월 7일
댓글: Jeremy Ahner 2022년 7월 11일
Essentially, I have a ROI of a grayscale image that has had analysis performed on it to measure the displacement. I want to overlay the contoured plot using contourf (with about 50% opacity) onto the background image (.tiff), but it currently washes out the background image since the contours have specified limits much lower than the background values. Is there a way to only apply contourf to specificied axis values instead of over the entire figure?
Any assistance would be tremendously appreciated

채택된 답변

DGM
DGM 2022년 7월 7일
편집: DGM 2022년 7월 7일
I'm not really sure what you're asking for. It might look like you're trying to restrict the domain of the contourf() plot, but the likely problem is that your grayscale image and contourf() will be difficult to read because they share the same colormap, which will be the default behavior.
To plot a contour/contourf plot over an arbitrary restricted domain, one way is to use NaNs:
To plot a semitransparent contourf() plot over a grayscale image, with removal of the background levels from the contourf() plot:
If you're looking for something else, provide an example that demonstrates what you're doing and the issue that's happening.
  댓글 수: 3
DGM
DGM 2022년 7월 8일
편집: DGM 2022년 7월 8일
I'm not sure why you're doing that. You said you wanted to overlay the contour plot on the image and that it was transparent.
The pixel values of the photograph aren't relevant to the specification of clim. If you follow the example I gave, the underlying image will be rendered as a truecolor image, and so it won't be colormapped. Its appearance will be entirely independent of any colormapped object in the axes (e.g. the contour plot).
EDIT: I just realized that this can be simplified since your contour covers the image fully. In this sort of case, it's easier to plot the image on top and make it transparent instead.
% a single-channel image
BG = imread('cameraman.tif');
% some fake data
y = (1:size(BG,1)).';
x = 1:size(BG,2);
z = x.*y/100E3;
% THE IMAGE MUST BE RGB
BG = repmat(BG,[1 1 3]);
% plot it
nlevels = 4;
contourf(x,y,z,nlevels); hold on
hi = imshow(BG);
hi.AlphaData = 0.5;
colormap(parula(nlevels+1))
colorbar
Jeremy Ahner
Jeremy Ahner 2022년 7월 11일
Awesome, I got it to work! Thank you so much for the help, I appreciate it tremendously!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by