How to highlight a area in figure

6 ビュー (過去 30 日間)
xie
xie 2025 年 1 月 22 日
コメント済み: Image Analyst 2025 年 1 月 24 日
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 件のコメント
xie
xie 2025 年 1 月 22 日
編集済み: xie 2025 年 1 月 22 日
Sorry, I have no idea to combine these two attached figures.
xie
xie 2025 年 1 月 22 日
maskedImage = croppedImage;
maskedImage(convHull) =0;
imshow(maskedImage)
But I want to change the black portion to transparent. I have no idea. Could you help me?

サインインしてコメントする。

採用された回答

prabhat kumar sharma
prabhat kumar sharma 2025 年 1 月 22 日
移動済み: Mathieu NOE 2025 年 1 月 22 日
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:
  1. Load your data: First, load your croppedImage and convHull data.
  2. Create a mask: Use the convHull to create a mask that identifies the region you want to highlight.
  3. 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 件のコメント
xie
xie 2025 年 1 月 22 日
移動済み: Mathieu NOE 2025 年 1 月 22 日
Very clear! Good teaching!

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2025 年 1 月 23 日
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.
  2 件のコメント
xie
xie 2025 年 1 月 23 日
Very good guidance!!!
Image Analyst
Image Analyst 2025 年 1 月 24 日
imoverlay gives opaque overlays. labeloverlay can give transparent/tinted overlays.

サインインしてコメントする。


xie
xie 2025 年 1 月 23 日
移動済み: Walter Roberson 2025 年 1 月 23 日
Maybe I got the simple method: labeloverlay function can meet my request.
imshow(labeloverlay(croppedImage,convHull, 'Colormap','spring','Transparency',0.7));
thank you all!

Community Treasure Hunt

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

Start Hunting!

Translated by