how to make the background of an image transparent?

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 commentaires

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)?
EDIT Moved answer to comments john-john said: how can we help or suggest you.. you didn't post your picture =)

Connectez-vous pour commenter.

Réponses (2)

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);
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)

Community Treasure Hunt

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

Start Hunting!

Translated by