Non-cyclic smoothing of a 2D image
Pad image and smooth:




Make image of value 1 same size as original. Pad and smooth:




Divide original image by '1' image:



And crop:



MATLAB demo code:

I = double(imread('lena.tif'));
g = fspecial('gaussian',60,10);
Ipad = padarray(I,[10,10]);
imagesc(Ipad); colormap gray(256); pause;
Ipadg = imfilter(Ipad,g);
imagesc(Ipadg); colormap gray(256); pause;
A = ones(size(I));
Apad = padarray(A,[10,10]);
imagesc(Apad); colormap gray(256); pause;
Apadg = imfilter(Apad,g);
imagesc(Apadg); colormap gray(256); pause;
IA = Ipadg./Apadg;
imagesc(IA); colormap gray(256); pause;
I = IA(11:end-10,11:end-10);
imagesc(I); colormap gray(256); pause;


*Note: * MATLAB imfilter already does zero padding. The pad array step is not needed, it is just for demonstration. Actual code would be:

I = double(imread('lena.tif'));
g = fspecial('gaussian',60,10);
Ig = imfilter(I,g);
A = ones(size(I));
Ag = imfilter(A,g);;
Ismooth = Ig./Ag;