Lecture 4: Nonlinear Filters
Image Noise
Physical effects (dust, raindrops)
Electrical noise
Lecture 4:
Caused by fluctuations in electric circuit.
Thermal noise
Nonlinear Filters
Impulse noise
Quantization noise
Poor illumination
Math 490
Prof. Todd Wittman
The Citadel
Source: http://photographylife.com/what-is-iso-in-photography
Applications Noise vs. Blur
Astronomy Microscopy Noise adds static by randomly corrupting individual pixels.
Blur smooths the edges by averaging over multiple pixels.
= +
=∗
Medical Imaging Computer Animation
Mathematically speaking, noise is generally an additive
process, while blur is generally multiplicative.
Artificial Noise Additive Noise
Gaussian Noise (MRI) Poisson Noise (PET)
We can add artificial noise to images using the Matlab = + (0, ) = ()
imnoise command.
We have to specify what type of noise we want and how 50 50
much.
100 100
The most common type of noise
is Gaussian (white noise). 150 150
200 200
A = imread('cameraman.tif');
B = imnoise(A, 'gaussian', 0, 0.3); 250
50 100 150 200 250
250
50 100 150 200 250
A=imread('cameraman.tif'); A=imread('cameraman.tif');
Variance B=imnoise(uint8(A),'gaussian',0,0.02); B=imnoise(uint8(A),'poisson');
Distribution of noise Mean imagesc(B); imagesc(B);
1
Lecture 4: Nonlinear Filters
Non-additive Noise Filters
Salt & Pepper Noise Speckle Noise (Ultrasound)
(Reset random pixels) = ( 1 + 0, ) A filter is a process that removes or enhances some
feature of an image.
Commonly, the word “filter” describes an operation on
50 50
the neighborhood of an image.
100 100
110
50
150 150 111
100 112
200 200 113
150
114
250 250 200
115
50 100 150 200 250 50 100 150 200 250
250 116
A=imread('cameraman.tif'); A=imread('cameraman.tif'); 50 100 150 200 250 93 94 95 96 97 98 99 100
B=imnoise(uint8(A),'salt & pepper',0.1); B=imnoise(uint8(A),'speckle',0.05);
imagesc(B); imagesc(B);
Linear vs. Nonlinear Median Filter
The median filter computes the median of the
A linear filter can be expressed as a convolution neighborhood centered over the pixel.
(weighted average over a neighborhood): Compared to the mean filter, the median filter
=∗
preserves edges better.
Any filter that cannot be written as a convolution Mean
255 255 0
is called a nonlinear filter. =
255 100 0 =152.8
Linear filters can be computed very quickly using
Fourier Transforms by The Convolution Median
255 255 0
Theorem. =0, 0, 0 100, 255, 255, 255, 255, 255
Nonlinear filters will generally be much slower. = 255
Median Filter Visualizing Noise
The median filter and its variants are particularly well-suited
for salt & pepper noise. A common way to test denoising algorithms is to subtract
The Matlab command nlfilter calculates nonlinear the denoised image from the noisy image.
functions on neighborhoods. It is much slower than imfilter. This subtracted image is called the residual.
B = nlfilter(A, [3,3], @(x) median(x(:)) ); If the algorithm did a good job denoising, then we should
only see random dots and no structure.
50 50
100 100
150 150
200
250
50 100 150 200 250
200
250
50 100 150 200 250
- =
Can also use the command medfilt2.
2
Lecture 4: Nonlinear Filters
Thought Exercise
Quantifying Noise
A noisy brain MRI is segmented into 4 classes using
There are two major statistics used to determine the amount K-means clustering.
of noise in an image. K = kmeans(A(:),4);
Both statistics compare the noisy image f to an ideal noise- B = reshape(K, size(A));
free image fideal. The image B takes on integer values 1-4.
Both statistics are easier to write using the Frobenius norm: 50
= ! ! , "
100
150
$ #
200
250
1. Root Mean Square Error (RMSE) 300
350
%& = − $)*+,
400
where N=#pixels in image
'
450
500
2. Signal-to-Noise Ratio (SNR)
50 100 150 200 250 300 350 400 450 500
123456
Mean and median filters are not appropriate for this
% = 20 log Larger SNR = Less Noise type of data. Can you explain why?
17123456
Thought Exercise
Beyond Local
The data is qualitative. The values 1,2,3,4 are just labels
Suppose Lena’s left eye was obscured by noise.
and the order is irrelevant.
A neighborhood around the eye will not tell us the eye’s true
We could run a ___________ filter on the data. color.
C = nlfilter(B,[3,3], @(x)________(x(:)) );
50 50
100 100
150 150
200 200
250 250
300 300
350 350
400 400
450 450
500
50 100 150 200 250 300 350 400 450 500
500
50 100 150 200 250 300 350 400 450 500
Solution: Look at the other eye!
Image Similarity Nonlocal-Means
(Buades-Coll-Morel, 2005)
Natural images tend to have similar neighborhoods. proposed a denoising method that
averages over all pixels in the
image that have a similar
neighborhood.
They call their method Nonlocal
(NL) Means.
∑<
9, ; (;)
8 9 =
∑<
(9, ;)
where w is a weight that judges the
similarity between the
neighborhoods.
Similar ⟶ w=1, Different ⟶ w=0
3
Lecture 4: Nonlinear Filters
Nonlocal-Means Weights from Clean Images
Let N(x) denote the neighborhood around pixel x.
We want w(x,q)=1 if the neighborhoods N(x) and N(q)
are similar.
And we want w(x,q)=0 if the neighborhoods N(x) and
N(q) are completely different.
9 − ;
9, ; = >9? −
ℎ
The parameter h controls the similarity.
Generally choose square neighborhood, e.g. 5x5.
Can add Gaussian weights to norm to emphasize center.
Weights from Noisy Images NL-Means
Smaller neighborhoods remove noise
better, but may over-smooth the image.
NL-Means NL-Means
Many consider NL-Means and its variants to be NL-Means performs best on images with
the best denoising method for natural images. repeating patterns.
Noisy Gauss Filtered NL-Means
Noisy NL-Means
4
Lecture 4: Nonlinear Filters
Implementation Color Images
NL-Means is painfully slow. There are 2 tricks to speed We can extend NL-Means to color images by comparing
it up: 3D neighborhood cubes.
NL-Means actually achieves better results on color
1. Search Somewhat Local -- Restrict the neighborhood images than on grayscale. We can shrink the
comparisons to a window around the current pixel, neighborhood size because of the extra information.
rather than the whole image.
2. Save Pixel Comparisons -- Store all pixel-to-pixel
comparisons in an efficient data structure to avoid
making unnecessary passes through the image
(Darbon-Cunha-Chan-Osher-Jensen, 2008).
Noisy NL-Means
3D NL-Means Ultrasound
Nonlocal methods are good at removing the speckle
NL-Means extends to 3D for surface denoising (Dong- noise in Ultrasound images (Sawatzky, 2011).
Ye-Osher-Dinov, 2007).
NL-Means recovers corners and flattens smooth regions
better than many denoising methods.
NL-Means is particularly good for microscopy
(Darbon-Cunha-Chan-Osher-Jensen, 2008).
Noisy Mean Curvature Smoothing NL-Means
More Neighborhoods Use with Caution
Standard NL-Means only compares neighborhoods
under translation.
Nonlocal methods are powerful denoisers, but
they have to be used carefully.
We could also consider neighborhoods under scaling
and rotation transformations (Lou-Favaro-Soatto-
Bertozzi, 2008). Exploiting image similarity could erase small-
But this will slow down the computation. scale features that only occur in one part of the
image.
But these small features are often the most
important part in some applications. For
example, in medical imaging we look for tumors,
Noisy NL-Means Extended NL-Means hemorrhages, muscle tears, bone fractures, etc.