% DATE: 04/15/04
% FILE: convolve2D.m
% DESC: convolves the image (first with xfilter and then with yfilter)

function ourImage5=convolve2D(ourImage, border, xfilter, yfilter, width, height)

% convolve image with 1D xfilter mask
for r=1:height+2*border
    for c=1:width
        SUM1=0;
        %for I=1:5
        for J=1:5
            %r1=r+I-1;
            c1=c+J-1;
            SUM1 = SUM1 + (ourImage(r, c1))*(xfilter(1,J));
        end
        %end
        
        ourImage4(r,c+2)=SUM1;
    end
end

[M,N]=size(ourImage4);
% convolve image with 1D yfilter mask
for r=1:M-2*border
    for c=1:N
        SUM2=0;
        for I=1:5
            r1=r+I-1;
            SUM2 = SUM2 + (ourImage4(r1, c))*(yfilter(1,I));
        end
        
        ourImage5(r+2,c)=SUM2;
    end
end
figure; colormap(gray(256)); image(ourImage5); title('the result of convolution');
end