how to make the background of an image transparent?
Show older comments
I'm having a bird image with white background..and i need to make the background transparent so that i can add it to a block of the sky image naturally. Can anyone please help me to do it in Matlab..Thanks in advance..
2 Comments
Daniel Shub
on 23 Jan 2013
This might be related to this question or are you trying to take an image (say a png file), process it, and create a new image (also a png file)?
Daniel Shub
on 23 Jan 2013
EDIT Moved answer to comments john-john said: how can we help or suggest you.. you didn't post your picture =)
Answers (2)
Image Analyst
on 23 Jan 2013
Extract color channels of each RGB image:
% Extract the individual red, green, and blue color channels.
redChannel = rgbBirdImage(:, :, 1);
greenChannel = rgbBirdImage(:, :, 2);
blueChannel = rgbBirdImage(:, :, 3);
skyRedChannel = rgbSkyImage(:, :, 1);
skyGreenChannel = rgbSkyImage(:, :, 2);
skyBlueChannel = rgbSkyImage(:, :, 3);
For each color channel, threshold
bird = greenChannel < threshold; % Create binary mask image.
Then do the replacement:
skyGreenChannel(bird) = greenChannel(bird); % Replace with bird pixels.
Then recombine:
compositeImage = cat(3, skyRedChannel, skyGreenChannel, skyBlueChannel);
Walter Roberson
on 23 Jan 2013
Create a logical array BirdMask that is true for pixels that you want to continue to show, and false for background pixels. Display the sky image first. Then
image(BirdImage, 'AlphaData', BirdMask)
1 Comment
Raseen Akhtar
on 4 Dec 2015
How would I get the logical array BirdMask?
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!