Image Restoration Examples Image and Multidimensional Signal Processing Colorado School of Mines

advertisement
Image Restoration
Examples
Colorado School of Mines
Image and Multidimensional Signal Processing
Image Restoration Metrics
• RMS error is easy to compute (ie, square root of the
mean squared error).
– However, it (and similar metrics) are biased towards oversmoothed (i.e., blurry) results. Namely, an algorithm that
removes not only the noise but also part of the structure (e.g.,
edges) will have a good score.
• The structural similarity index (SSIM) takes into account
the similarity of the edges (high frequency content)
between the denoised image and the ideal one.
– To have a good SSIM measure, an algorithm needs to remove
the noise while also preserving the edges of the objects.
Colorado School of Mines
Image and Multidimensional Signal Processing
2
Other Image Restoration Metrics
Colorado School of Mines
Image and Multidimensional Signal Processing
3
Example 1 – Gaussian filter for denoising
clear all
close all
% Get an image.
Iinput = imread('liftingbody.png');
Iinput = double(Iinput);
imshow(Iinput, []); % Input image
% Add noise to the image. Let's use Gaussian noise, with sigma = sn.
sn = 20.0;
I = Iinput + sn*randn(size(Iinput));
figure, imshow(I, []); % Noisy image
sigmaGaussian = 3.0;
Iout = imfilter(I, fspecial('gaussian', 6*sigmaGaussian, sigmaGaussian));
figure, imshow(Iout, []), title('gaussian filter');
Idiff = Iout - Iinput;
rms = sqrt(mean2(Idiff.^2));
figure, imshow(Idiff, []);
title(sprintf('Errors (gaussian filter), rms = %f', rms));
Colorado School of Mines
Image and Multidimensional Signal Processing
4
Example 2 - Bilateral Filter
• The “bilateral filter” is similar to the “adaptive mean
filter” discussed in the textbook.
• It is useful to reduce image noise, but doesn’t blur
across boundaries.
• A good tutorial is available on this website:
– http://people.csail.mit.edu/sparis/bf_course/
– Matlab code available there too.
Colorado School of Mines
Image and Multidimensional Signal Processing
5
Example 2 (continued)
clear all
close all
% Get an image.
Iinput = imread('liftingbody.png');
Iinput = double(Iinput);
imshow(Iinput, []); % Input image
% Add noise to the image. Let's use Gaussian noise, with sigma = sn.
sn = 20.0;
I = Iinput + sn*randn(size(Iinput));
figure, imshow(I, []); % Noisy image
maxval = max(I(:));
minval = min(I(:));
sigmaSpatial = sigmaGaussian;
sigmaRange = (maxval-minval)/10;
% Default is (maxval-minval)/10
Iout = bilateralFilter(I, ...
[], ...
% optional edge image
minval, maxval, ...
% range of values
sigmaSpatial, sigmaRange); % sigmaSpatial, sigmaRange
figure, imshow(Iout, []), title('bilateral filter');
Idiff = Iout - Iinput;
rms = sqrt(mean2(Idiff.^2));
figure, imshow(Idiff, []);
Colorado
School of Mines
Image and Multidimensional
Processing
title(sprintf('Errors
(bilateral
filter),Signal
rms
= %f', rms));
6
Example 3 - Blur Degradation
• A blurring degradation can be modeled by a Gaussian
h ( x, y ) =
1
2πσ 2
−
e
x2 + y2
2σ 2
• If you take an image of a dot (impulse), the output
blurred image is just the Gaussian blurring function
Colorado School of Mines
Image and Multidimensional Signal Processing
7
Example 3 - Blurred image of a line
• Assume that the input image is a bright vertical line located at
x=a in the image, and zero everywhere else.
• Namely, f(x,y) = δ(x-a). What is the degraded output image
g(x,y)?
Colorado School of Mines
Image and Multidimensional Signal Processing
8
Example 4 – Compare filters
• Compare the performance of these filters, on reducing added
Gaussian noise:
–
–
–
–
Gaussian low pass filter
Bilateral filter
Adaptive mean filter
Anisotropic diffusion filter
• Try on these images:
– ckt-board.tif
– Fig0222(a)(face).tif
– cameraman.tif
% Add noise to the image. Let's use Gaussian noise, with sigma = sn.
sn = 20.0;
I = Iinput + sn*randn(size(Iinput));
figure, imshow(I, []); % Noisy image
Colorado School of Mines
Image and Multidimensional Signal Processing
9
Example 4 (continued)
• For each image and each filter, display the error
image between the original (noise-free) image and
the filtered reconstructed image. Notice where
errors occur.
• For each image and each filter, give the RMS error
between the restored image and the original. See if
a low RMS error gives the “best” reconstruction in
terms of preserving edges as well as reducing noise.
Colorado School of Mines
Image and Multidimensional Signal Processing
10
Example 4 (continued)
clear all
close all
% Get an image.
%Iinput = imread('ckt-board.tif');
%Iinput = imread('Fig0222(a)(face).tif');
Iinput = imread('cameraman.tif');
Iinput = double(Iinput);
imshow(Iinput, []); % Input image
% Add noise to the image. Let's use Gaussian noise, with sigma = sn.
sn = 20.0;
I = Iinput + sn*randn(size(Iinput));
figure, imshow(I, []); % Noisy image
sigmaGaussian = 3.0;
Iout = imfilter(I, fspecial('gaussian', 6*sigmaGaussian, sigmaGaussian));
figure, imshow(Iout, []), title('gaussian filter');
Idiff = Iout - Iinput;
rms = sqrt(mean2(Idiff.^2))
figure, imshow(Idiff, []);
title(sprintf('Errors (gaussian filter), rms = %f', rms));
maxval = max(I(:));
minval = min(I(:));
sigmaSpatial = sigmaGaussian;
sigmaRange = (maxval-minval)/10;
Colorado School of Mines
% Default is (maxval-minval)/10
Image and Multidimensional Signal Processing
11
Iout = bilateralFilter(I, ...
[], ...
% optional edge image
minval, maxval, ...
% range of values
sigmaSpatial, sigmaRange); % sigmaSpatial, sigmaRange
figure, imshow(Iout, []), title('bilateral filter');
Idiff = Iout - Iinput;
rms = sqrt(mean2(Idiff.^2))
figure, imshow(Idiff, []);
title(sprintf('Errors (bilateral filter), rms = %f', rms));
Iout = wiener2(I, [3*sigmaGaussian 3*sigmaGaussian]);
figure, imshow(Iout, []), title('adaptive mean filter');
Idiff = Iout - Iinput;
rms = sqrt(mean2(Idiff.^2))
figure, imshow(Idiff, []);
title(sprintf('Errors (adaptive mean filter), rms = %f', rms));
% Parameters:
niter - number of iterations.
%
kappa - conduction coefficient 20-100 ?
%
lambda - max value of .25 for stability
%
option - 1 Perona Malik diffusion equation No 1
%
2 Perona Malik diffusion equation No 2%
Iout = anisodiff(I, ...
10, ...
% niter - number of iterations
30, ...
% conduction coefficient 20-100
0.25, ...
% max value of .25 for stability
1);
% option: Perona Malik diffusion equation No 1 or No 2
figure, imshow(Iout, []);
Idiff = Iout - Iinput;
rms = sqrt(mean2(Idiff.^2))
figure, imshow(Idiff, []);
title(sprintf('Errors (anisotropic diffusion filter), rms = %f', rms));
Colorado School of Mines
Image and Multidimensional Signal Processing
12
Download