Image Background Removal
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (1)
Siddharth Shankar
il 26 Gen 2011
0 voti
Have you considered using the imabsdiff method. The difference of the two images is basically the object obstructing the background.
1 Commento
Mazvydas Tadaravicius
il 27 Gen 2011
Categorie
Scopri di più su Image Arithmetic in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!