I was able to fix my problem by using the regionprops and patch functions to find object extrema and plot patch regions semi-transparently on the original image.
Overlaying Transparent Image with Clear Background on Original
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Susan
el 27 de Mzo. de 2013
Comentada: Walter Roberson
el 12 de Mzo. de 2021
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);
0 comentarios
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 28 de Mzo. de 2013
Please read Steve's blog on the topic: http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/
Muhammad Zeeshan Ahmed Khan
el 12 de Mzo. de 2021
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 comentario
Walter Roberson
el 12 de Mzo. de 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
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!