function imageblurred = Blur(image,levelblurring) % returns a blurred version of image of blurring level levelblurring % image is the string (file name of the image to be blurred) % imageblurred is the matrix representing the blurred image A = imread(image); A = double(rgb2gray(A)); [m,n] = size(A); % blurring: it uses a matrix B for the vertical blurring % and a matrix C for the horizontal blurring; v = [1/4 1/2 1/4]; B = spdiags( repmat(v,m,1), [-1 0 1],m,m); C = spdiags( repmat(v,n,1), [-1 0 1],n,n); imageblurred = B^levelblurring * A * C^levelblurring; end