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!
