How to save image that used AlphaData function?
Ältere Kommentare anzeigen
I am using the transparency on watershed,
Lrgb=label2rgb(L,'jet','w','shuffle');
imshow(Lrgb), title('Colored Watershed Label Matrix (Lrgb)')
imshow(I)
hold on
himage=imshow(Lrgb);
himage.AlphaData=0.3;
title('Lrgb Superimposed Transparently on Original Image')
imwrite(himage,'newWAimage.png','PNG');
I want to save the superimposed image using imwrite since i need my image the same size as the original images but "matlab.graphics.primitive.Image." error occurs.
I did use saveas function however the output size image is different than the original image.
Is there any other way to save the superimposed image? Do I need to change the transparency code?
3 Kommentare
Walter Roberson
am 13 Mär. 2019
Do you need the title to show up in output? If not then you could imwrite(L) with a colormap and using the 'Apha' option that is accepted for PNG.
athirahlan
am 13 Mär. 2019
Walter Roberson
am 13 Mär. 2019
Yes, setting himage.AlphaData=0.3 will write over the effects of alpha color
Antworten (1)
Image Analyst
am 13 Mär. 2019
0 Stimmen
Did you try getframe()?
9 Kommentare
athirahlan
am 13 Mär. 2019
Image Analyst
am 13 Mär. 2019
Yes, but didn't you want to call
imwrite(F.cdata, filename);
athirahlan
am 13 Mär. 2019
Walter Roberson
am 13 Mär. 2019
If the new image needs to be the same size as the original, then where do you want the title to go?
athirahlan
am 13 Mär. 2019
Image Analyst
am 13 Mär. 2019
Walter Roberson
am 13 Mär. 2019
[nr, nc, np] = size(Lrgb);
AD = 0.3 * ones(nr, nc);
imwrite(Lrgb, 'NewAImage.png', 'AlphaData', AD);
Note that this will produce a .png with alpha data inside it, with whatever display utility you use being responsible for processing the effects of the alpha. This will not produce a .png in which the effects of the alpha have been post-processed .
One thing to remember is that the effects of the transparency are going to depend upon what is underneath the image at time of display. When using imshow() or image() or imagesc(), anything you have already drawn in the axes would be "underneath", and if you have not drawn anything underneath then what would be underneath would be the background color of the axes, which defaults to pure white. You can do the post-processing yourself:
AD = 0.3;
post_processed = typecast( double(Lrgb) * (1-AD) + AD*ones(size(Lrgb)), class(Lrgb));
athirahlan
am 18 Mär. 2019
Walter Roberson
am 18 Mär. 2019
imwrite(Lrgb, 'NewAImage.png', 'Alpha', AD);
Kategorien
Mehr zu Images finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
