function [nobg,fore]=removebackground(Imwork,Imback)

bg=rgb2gray(Imback);
im=rgb2gray(Imwork);

nobg = ((im > bg+5) | (im < bg-5));

nobg = medfilt2(nobg, [9 9]);
nobg=bwareaopen(nobg,600,8);
nobg=imfill(nobg,'holes');



nobg = uint8(nobg);

fore(:,:,1)=Imwork(:,:,1).*nobg;
fore(:,:,2)=Imwork(:,:,2).*nobg;
fore(:,:,3)=Imwork(:,:,3).*nobg;
%fore = bwmorph(fore,'erode',2);
