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 Comments

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.
Is it using this code?
imagesc(peaks)
alpha color
alpha scaled
will it effect this code?
himage.AlphaData=0.3
Yes, setting himage.AlphaData=0.3 will write over the effects of alpha color

Sign in to comment.

Answers (1)

Did you try getframe()?

9 Comments

Did you mean this code?
surf(peaks)
F = getframe(gcf);
figure
imshow(F.cdata)
Yes, but didn't you want to call
imwrite(F.cdata, filename);
TQ, the imwrite problem is solved however the ouput is the problem,
Capture.PNGit still capture the outer layer of the image,
I need the output of the newimage to be as in newFCMimage2, where 200 by 200, because i want to evaluate the newimage with the original image. Is it possible to change the size in
imwrite(F.cdata, filename);
If the new image needs to be the same size as the original, then where do you want the title to go?
My original image is similar as newFCMimage2, the title won’t be needed when i compare the original image with the new image, it need to be the same size when compared that why i want the newimage ouput to be 200 by 200 as well.
When using imwrite for my fcm coding the output size is same as original image, but when applied to the watershed coding, it stuck at the alphadata part, so i’m still testing whether to change the alphadata coding or the imwrite coding. Any suggestion?
[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));
I'm able to get the image using export_fig.
When using
Lrgb=label2rgb(L,'jet','w','shuffle');
imshow(Lrgb), title('Colored Watershed Label Matrix (Lrgb)')
imshow(I)
[nr, nc, np] = size(Lrgb);
AD = 0.3 * ones(nr, nc);
imwrite(Lrgb, 'NewAImage.png', 'AlphaData', AD);
it produces this error
%Error using writepng>CheckTextItem (line 378)
%Text chunk must be a string.
%Error in writepng (line 258)
% item = CheckTextItem(unmatched.(param_name));
%Error in imwrite (line 472)
% feval(fmt_s.write, data, map, filename, paramPairs{:});
%Error in Watershed_Algorithm (line 114)
%imwrite(Lrgb,'NewAImage.png','AlphaData',AD);
imwrite(Lrgb, 'NewAImage.png', 'Alpha', AD);

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 13 Mar 2019

Commented:

on 18 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!