Azzera filtri
Azzera filtri

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

12 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

DGM
DGM il 7 Lug 2022
Modificato: DGM il 7 Lug 2022
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 Commenti
DGM
DGM il 8 Lug 2022
Modificato: DGM il 8 Lug 2022
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 il 11 Lug 2022
Awesome, I got it to work! Thank you so much for the help, I appreciate it tremendously!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by