MATLAB: Make the white background transparent

alphasvgtransparentwhite background

Hello, I would like to convert the white pixels in the attached image to be 100% transparent. Could you please help with this? I'm going to eventually convert this image into an svg file to open in illustrator. Thank you.

Best Answer

First, to answer your exact question: it's not possible in matlab, since matlab does not have a concept of a transparency channel.
A transparency channel is an additional channel (on top of the 1 grayscale or the 3 RGB channels) that indicates the transparency of each pixel. You could always create such a channel but matlab wouldn't know what to do with it except if you were to save the image as PNG (or possibly other formats that support transparency). Matlab certainly cannot display transparency.
So, if you want to play around with transparency, you're better off doing it in some other program. Your favorite image editor (GIMP, Photoshop, Paint.Net, etc.) is a lot better suited for this.
However, I don't see how converting the pixels to transparent is going to help for your ultimate goal. You're trying to convert a raster image into a vectorial image which basically means doing shape recognition. There's nothing built-in in matlab to do that. You can certainly use the image processing and computer vision toolbox to help you but you're going to have to work for this. Again, you're probably better off working in something other than matlab.
Note: to save that image as PNG with the white pixels transparent, assuming the image is loaded as uint8:
%img: source image as RGB uint8
alphachannel = all(img == 255, 3); %replace 255 with 1 if img is double
imwrite(img, 'somename.png', 'Alpha', alphachannel);
Related Question