%This function is for erode operation, used to denoise for frame difference
%image;
function frameDif = erodeFramediff(frameDif)
height = size(frameDif,1);
width = size(frameDif,2);
erohalfwin = 1; %half of the erode window
erothreshold = 5;
tempdif = frameDif;

%search for the entire image to denoise
for h = erohalfwin+1:1:height-erohalfwin-1
    for w = erohalfwin+1:1:width-erohalfwin-1
        count = 0;
        if frameDif(h,w,:) ~= 0
            
            %to decide if this point is a noise or not according to its
            %neighbourhood 
            for h1 = -erohalfwin:1:erohalfwin
                for w1 = -erohalfwin:1:erohalfwin
                    if frameDif(h+h1,w+w1,:) ~= 0
                        count=count+1;
                    end
                end
            end
            if count < erothreshold %this point is a noise
                tempdif(h,w,:) = 0;
            else tempdif(h,w,:) = 255;
            end
        end
    end
end

frameDif = tempdif;

            
                    
            
            
        
