What have you tried so far? If you post your code, we can suggest edits more easily.
How to highlight a area in figure
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
xie
am 22 Jan. 2025
Kommentiert: Image Analyst
am 24 Jan. 2025
I want to hightlight the defect in croppedImage.mat by convHull.mat.
It's better set transparent.
the size of two figures is same.
3 Kommentare
Akzeptierte Antwort
prabhat kumar sharma
am 22 Jan. 2025
Verschoben: Mathieu NOE
am 22 Jan. 2025
To highlight an area in a figure and make it transparent, you can use the alpha data property in MATLAB. Here's a step-by-step guide to achieve this:
- Load your data: First, load your croppedImage and convHull data.
- Create a mask: Use the convHull to create a mask that identifies the region you want to highlight.
- Display the image with transparency: Use the imshow function with the 'AlphaData' property to make the highlighted area transparent.
Here's an example code snippet:
% Load the data
load('croppedImage.mat'); % Assuming this loads a variable named croppedImage
load('convHull.mat'); % Assuming this loads a variable named convHull
% Display the original image
imshow(croppedImage);
hold on;
% Create a mask for the highlighted area
highlightMask = false(size(croppedImage));
highlightMask(convHull) = true;
% Overlay the highlighted area with transparency
h = imshow(croppedImage);
set(h, 'AlphaData', ~highlightMask); % Set the non-highlighted part to transparent
% Optional: Add a color to the highlighted area
highlightedArea = imshow(cat(3, ones(size(croppedImage)), zeros(size(croppedImage)), zeros(size(croppedImage))));
set(highlightedArea, 'AlphaData', highlightMask * 0.5); % Adjust transparency level
1 Kommentar
Weitere Antworten (2)
Image Analyst
am 23 Jan. 2025
You can try imoverlay to make the mask overlaid on the image, or you can use plot to plot a red outline at the mask perimeter location in the image.
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!