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 endendend
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?
Best Answer