Image Background Removal
Mostrar comentarios más antiguos
For my gesture recognition uni project I have developed simple code that removes background from the image. For it to work there has to be an image of background scene and an image with an object that partially covers same background scene (a hand with a background of a room scene for example).
function [outIm] = makeMask(bg, im, tol)
%bg - background image
%im - input image
%tol - tolerance
[h,w] = size(bg);
outIm = false(h, w);
for ch = 1:h
for cw = 1:w
imPix = im(ch,cw);
bgPix = bg(ch,cw);
if ((bgPix == imPix) || (bgPix > imPix && bgPix <= imPix + tol) || (bgPix < imPix && bgPix >= imPix - tol))
outIm(ch, cw) = 0;
else
outIm(ch, cw) = 1;
end
end
end
end
As You see, code checks every single pixel and decides if it belongs to background scene. All this works well, however I want to ask is there more efficient way to achieve the same?
Respuesta aceptada
Más respuestas (1)
Siddharth Shankar
el 26 de En. de 2011
0 votos
Have you considered using the imabsdiff method. The difference of the two images is basically the object obstructing the background.
1 comentario
Mazvydas Tadaravicius
el 27 de En. de 2011
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!