6 views (last 30 days)
Sordin on 22 Apr 2017
Commented: Walter Roberson on 24 Apr 2017
Is it possible to make an alphamap for a figure based on its binary mask?
Here is a sample image and its binary:
a = im2bw(I, graythresh(I));
I want the regions in black to be made transparent and white regions to be opaque. So the only area visible is the image itself without the background.
Is this possible in Matlab? I couldn't find any information or examples in the documentation.
##### 2 CommentsShowHide 1 older comment
Sordin on 23 Apr 2017
I want the space to be transparent. The Saturn must be completely opaque. I am working on stacking slices to make a volumetric representation of medical data. Being able to exclude the background of each image (i.e., the parts of the image that contain no useful data) would help a lot.

Image Analyst on 23 Apr 2017
When you say "Being able to exclude the background of each image (i.e., the parts of the image that contain no useful data) would help a lot." It sounds like you want masking. So if the unwanted stuff was segmented so that it's white (like the Saturn in your binary image), then you can exclude that from the original image by masking like this:
% Mask the image using bsxfun() function
that will give you a color image of the space/universe while the Saturn pixels would be completely black ("removed" from the image). Invert the mask using mask=~mask if you want the opposite stuff blacked out.
% Mask the image using bsxfun() function
If it's a simple grayscale image, you can erase mask pixels like this:
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 24 Apr 2017
You are using an older MATLAB that does not support that syntax. You can replace
with

KSSV on 22 Apr 2017
I = rgb2gray(I) ;
I(I<50) = 255 ;
imshow(I)

Walter Roberson on 23 Apr 2017
a = im2bw(I, graythresh(I));
Alpha data needs to be between 0 and 1 (inclusive), so just double() the logical data to get suitable alpha data.

### Community Treasure Hunt

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

Start Hunting!

Translated by