Noise Removal
Noise Removal
Images are often polluted with unwanted variations in colouring or brightness, often
produced by the sensor or circuitry of an image capture device. Since all signal
processing devices are to some extent susceptible to electronic noises, many noise
reduction techniques have been developed.
Reference:
Rafael C. Gonzalez; Richard E. Woods (2007). Digital Image Processing. Pearson
Prenctice Hall. ISBN 0-13-168728-X.
Linda G. Shapiro; George C. Stockman (2001). Computer Vision. Prentice-Hall. ISBN 0
-13-030796-3.
Charles Boncelet (2005). "Image Noise Models". In Alan C. Bovik. Handbook of Image
and Video Processing. Academic Press. ISBN 0-12-119792-1.
> restart:
with(ImageTools):
Import Image
Please ensure this image file is located in the same folder as this worksheet, or
> img:=Matrix(RGBtoGray(Import("image.jpeg"))):
> nRows, nCols := LinearAlgebra:-Dimension(img):
> Embed(Create(img));
Sale & Pepper Noise
We define a procedure that adds salt and pepper noises to the image. Salt and
pepper noises result in the irregular appearance of dark pixels in the bright area
and bright pixels in the dark area of the image. A major source of period noise is
errors in the process of converting analog signals to digital signals. In this case we
are artifically producing this error by adding white and black pixels randomly
across the image.
The intensity is by default 50%, we will call the procedure with intensity=0.9.
> saltAndPepper := proc(img::Matrix, nCols, nRows,
intensity::float:=0.5)
local xrand, yrand, i:
xrand := rand(1..nCols):
yrand := rand(1..nRows):
for i from 1 to ceil(intensity*0.004*nRows*nCols) do
img[yrand(),xrand()] := 0:
img[yrand(),xrand()] := 1:
end do:
end proc:
> saltAndPepper(img,nCols,nRows,0.9):
> Embed(Create(img));
Periodic Noise
Then we add periodic noises to the image. Period noises result in repetitive
patterns being added to the original image, they are usually caused by electrical or
electromechanical interference in the image capturing process (Gonzalez &
Woords, 2007). Here we will artifically generate a periodic noise by adding a
sinusoidal wave to the original frequency, which produces a diagnoal pattern
across the image.
> noise := Matrix(nRows, nCols,(i,j) -> evalhf(sin((i+j))/10),
datatype = complex[8]):
> imgNoisy := noise+~img:
> Embed(Create(imgNoisy));
Removing periodic noise with Fourier Transform
In order to remove the periodc noise, we first decompose the image into frequency
waves by performing a 2D Fourier Transform on the image.
> FFT2D := proc(M)
local nCols, nRows, fft_img, i:
fft_img := Matrix(M, datatype = complex[8]):
nRows, nCols := LinearAlgebra:-Dimensions(fft_img):
for i from 1 to nCols do
fft_img[.., i] := SignalProcessing:-FFT(fft_img[.., i]):
end do:
for i from 1 to nRows do
fft_img[i, ..] := SignalProcessing:-FFT(fft_img[i, ..]):
end do:
return fft_img:
end proc:
We resize the image matrix in order to apply the SignalProcesing:-FFT() command.
> rows_closest := 2^(ceil(MTM:-log2(nRows))):
cols_closest := 2^(ceil(MTM:-log2(nCols))):
spec_img := FFT2D(Matrix(1..rows_closest,1..cols_closest,
imgNoisy)):
We define a procedure called fftshift to shift the zero frequency component to the
centre of the image.
> fftshift := proc(M)
local nRows, nCols, quad_1, quad_2, quad_3, quad_4, cRows,
>
cCols;
nRows, nCols := LinearAlgebra:-Dimensions(M):
cRows, cCols := ceil(nRows/2), ceil(nCols/2):
quad_1 := M[1..cRows, 1..cCols]:
quad_2 := M[1..cRows, cCols + 1..-1]:
quad_3 := M[cRows + 1..-1, cCols + 1..-1]:
quad_4 := M[cRows + 1..-1, 1..cCols]:
return <<quad_3, quad_2 |quad_4, quad_1>>:
end proc:
> spec_img := fftshift(spec_img):
> Embed(Create(abs~(spec_img)));