How to save image that used AlphaData function?
显示 更早的评论
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 个评论
Walter Roberson
2019-3-13
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
2019-3-13
Walter Roberson
2019-3-13
Yes, setting himage.AlphaData=0.3 will write over the effects of alpha color
回答(1 个)
Image Analyst
2019-3-13
0 个投票
Did you try getframe()?
9 个评论
athirahlan
2019-3-13
Image Analyst
2019-3-13
Yes, but didn't you want to call
imwrite(F.cdata, filename);
athirahlan
2019-3-13
Walter Roberson
2019-3-13
If the new image needs to be the same size as the original, then where do you want the title to go?
athirahlan
2019-3-13
Image Analyst
2019-3-13
Walter Roberson
2019-3-13
[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
2019-3-18
Walter Roberson
2019-3-18
imwrite(Lrgb, 'NewAImage.png', 'Alpha', AD);
类别
在 帮助中心 和 File Exchange 中查找有关 Images 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
