Overlaying Transparent Image with Clear Background on Original
Ältere Kommentare anzeigen
Hello, I have a problem with creating a semi-transparent overlay that I hope someone can help me with. I am performing marker-controlled watershed segmentation for small regions in an image, and I'd like to overlay the result on the original image. However, when I do the overlay, the black background of the segmentation result is overlayed as well, making it very difficult to see the features in the original image and determine how well the segmentation worked.
Is there a way to create a semi-transparent overlay of segmented regions with the background of that overlay being clear instead of black or white? My code is below. If you would like to see sample images, I can e-mail them.
% REMOVE REGIONS IN LABEL MATRIX L THAT ARE LARGER THAN A CERTAIN SIZE
stats = regionprops(L,'Area');
L2 = zeros(s1,s2);
for z = 1:length(stats)
ind = find(L == z); % Find the locations of all pixels with the label z
if stats(z).Area <= 50
L2(ind) = 1; % Set all pixels with label z for regions smaller than 50 to white
end
end
L3 = bwlabel(L2); % Re-label the new regions so that the labels are sequential
Lrgb = label2rgb(L3,'jet','k','shuffle'); % Convert label matrix to RGB image
% RE-DISPLAY ORIGINAL IMAGE
title = horzcat('Slice ',num2str(slice),' of ',num2str(Nslc));
set(handles.axesttl,'String',title); % Reset the slicetitle 'String'
...property
imagesc(cimg,'Parent',handles.axes1); % Display original image in
...GUI axes
colormap('gray'); % Set colormap to grayscale
axis off; % Turn off axis numbering
% OVERLAY SEMI-TRANSPARENT SEGMENTATION RESULT ON ORIGINAL IMAGE
hold on;
himage = imagesc(Lrgb,'Parent',handles.axes1);
set(himage,'AlphaData',0.2);
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 28 Mär. 2013
0 Stimmen
Please read Steve's blog on the topic: http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/
Muhammad Zeeshan Ahmed Khan
am 12 Mär. 2021
0 Stimmen
When you image() or imagesc() or imshow(), pass an option 'AlphaData' that is an array with the desired transparency, with 1 meaning to show the image completely and 0 meaning not showing the image at all (that is, show the background completely there.)
If the PNG had alpha information stored with it that you read with imread() then you should be able to use that transparency information directly.
[YourImage, ~, ImageAlpha] = imread('YourFile.png');
image(YourImage, 'AlphaData', ImageAlpha)
1 Kommentar
Walter Roberson
am 12 Mär. 2021
Copied without attribution from my answer to https://www.mathworks.com/matlabcentral/answers/365228-can-a-png-image-be-displayed-without-displaying-the-black-fill-in-the-guide#answer_289605
Kategorien
Mehr zu Image Segmentation finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!