Getting rid of a black background surrounding an Image

Hello, I was wondering how it would be possible to get rid of a black background that I have in an image. My teacher says to use a "green screen", but I do not see how it works for my image. bg is the fixed scene in which my image will be moving across. I understand that he made the black canvas by using the zeros function, but I cannot get it to work with my image. His image that he used also had a black background and his image resulted in only the colored image that he wanted. My image is this: http://www.buzzle.com/articles/how-to-make-a-paper-airplane.html
Here's the code that he used:
[row col pg] = size(bg);
pg = zeros(row,col,'uint8');
canv = cat(3,pg,pg,pg);
image(canv)

Answers (1)

[row col pg] = size(bg);
pg = zeros(row,col,'uint8');
gr = 255*ones(row,col,'uint8');
canv = cat(3,pg,gr,pg);
image(canv)

9 Comments

I tried this instead of the code above and my scene turned blue and purplish, while my image was still that airplane with the black surrounding it.
I have just edited (255 multiply) my answer
The scene now has a bright green hue. The airplane still has the black background.
could you paste all your code?
X= imread('airplanes.jpg');
image(X)
pause(1)
bg = imread('wind_turbines.jpg');
image(bg)
pause(1)
[row col pg] = size(bg);
pg = zeros(row,col,'uint8');
gr = 255*ones(row,col,'uint8');
canv = cat(3,pg,gr,pg);
image(canv)
what is the foreground and what is the background?
the background scene is the wind_turbines, the foreground is the airplanes. Airplanes is shown in the link above. I want to get rid of that black surrounding the airplane.
How does wind_turbines.jpg look like? How does airplanes.jpg look like?
wind_turbines.jpg looks like the picture in this link:
(The third picture, not including graphs)
airplanes.jpg looks like the picture in this link:

Sign in to comment.

Asked:

on 2 Dec 2012

Community Treasure Hunt

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

Start Hunting!