MATLAB Answers

How to save an image with an overlay mask applied to it?

조회 수: 23(최근 30일)
Antonio
Antonio 3 Feb 2013
Consider the following code
I = imread('pout.tif');
figure, imshow(I);
h = imfreehand (gca, 'Closed',false);
wait(h);
maskColor = getColor(h);
bwMask = createMask(h);
ContornoMask = imdilate(bwMask, true(3)) & ~imerode(bwMask, true(3));
imshow(I, [], 'Colormap', gray(256));
OverlayMask =alphamask(ContornoMask, maskColor, 0.5); %%how do I save the image with the overlay mask applied?
I don't understand why OverlayMask is a scalar value instead of a logical matrix.
I want to save the image generated by alphamask (<http://www.mathworks.com/matlabcentral/fileexchange/34936-alphamask-semi-transparent-image-overlay>) as a new image matrix. How can I do this?

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Andrew Davis
Andrew Davis 6 Feb 2013
Alphamask is a display tool. Your 'OverlayMask' variable is a scalar because alphamask returns a handle to the graphic. If you wanted the logical matrix, you already have it as 'ContornoMask', right?
To save the image with the mask applied, I recommend saveas:
saveas(OverlayMask, 'imagefile', 'jpg')
Or, in general, gcf can be used as a handle to the figure if you like:
saveas(gcf, 'imagefile', 'jpg')
Of course you may choose different file formats including Matlab's 'fig'. If you find alphamask useful, please leave a rating on the file exchange page.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Image Analyst
Image Analyst 4 Feb 2013
How about saving OverlayMask (which is generated by the alphamask program) with imwrite:
imwrite(OverlayMask, theFullFileName);
Isn't this what you asked?

  댓글 수: 2

Andrew Davis
Andrew Davis 6 Feb 2013
Unfortunately imwrite will not work in this case because OverlayMask is just a scalar value (representing the graphic handle).
Image Analyst
Image Analyst 6 Feb 2013
Then just save ContornoMask
imwrite(ContornoMask , theFullFileName);

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by