How do I overlay a contour plot for a ROI onto a grayscale image?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!