Skip to content

Instantly share code, notes, and snippets.

@bkrajendra
Created February 9, 2013 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkrajendra/4746511 to your computer and use it in GitHub Desktop.
Save bkrajendra/4746511 to your computer and use it in GitHub Desktop.
MatLab BG removal By Rajendra
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment