Hi, I am trying to convert the background of an image into transparent.
I took an image as input, then created an alpha channel. The alpha channel is supposed to be a matrix with 1 where there is white color. Then the output image will be transparent where there were initially white color pixels.
This is the code I wrote ...
alphachannel = all(img == 255, 3);
imwrite(img, 'practice_2.png', 'Alpha', alphachannel_2);
I practiced with the following image ...
The white color is supposed to be transparent in the output image. But as it turns out the whole image is being transparent in the output image. The red,blue and black boxes aren't appearing in the output image.
But instead, if I use the ' Transparency' attribute of imwrite() function, then it works.
imwrite(img, 'practice_2.png', 'Transparency',[1 1 1]);
But, using 'Transparency' lets me to convert the image into transparent background based on only a single color, not on a certain Alpha Channel. What am I doing wrong with the first code ?
I am including the image and the matlab file, if you need.
Thanks in advance :)