File Exchange

image thumbnail

ALPHAMASK: semi-transparent image overlay

version (1.77 KB) by Andrew Davis
Overlay image with semi-transparent mask and return handle


Updated 06 Feb 2012

View License

ALPHAMASK: Overlay image with semi-transparent mask

Overlays a semi-transparent mask over an image. By default the
currently displayed figure is overlain.
Options include overlay colour and opacity.
Returns a handle to the overlay mask.

hOVM = alphaMask(bwMask, [colour, transparency, axHandle])
bwMask: logical matrix representing mask
colour: vector of three rgb values in range [0, 1] (optional; default [0 0 1])
transparency: scalar in range [0, 1] representing overlay opacity (optional; default 0.6)
axHandle: handle to axes on which to operate (optional; default current axes)
hOVM: handle to overlay image is returned

I = peaks(200);
bwMask = eye(200);
imshow(I, [], 'Colormap', hot);
alphamask(bwMask, [0 0 1], 0.5);


Cite As

Andrew Davis (2021). ALPHAMASK: semi-transparent image overlay (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Andrew Davis

@Maleen That is true. This software can overly an existing mask with transparency on another image. If you're looking to create a mask at specific xy values, as you suggest, the alphamask function will not help, because that's not its purpose.

can't assign the mask to specific xy values

bourr houssam

Thank you davis, that's exactly what i'm looking for




Andrew Davis

Thanks for the comment, Scott. I was using the square brackets to indicate that those arguments are optional, but I can see how it could be construed to mean that the last three arguments should be given as a single vector. Maybe alphamask(bwMask, [colour], [transparency], [axHandle]) would be more clear...


Great function. FYI, you have a small typo in your usage comments. Line 10 should read:
% hOVM = alphamask(bwMask, [colour], transparency, axHandle)


MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Image overlay

Community Treasure Hunt

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

Start Hunting!