IMAGE FILTERING
INEL 6088 Computer Vision
References: Chapter 4 Jain et al, Chapter 3 Davies
IMAGE FILTERING INEL 6088 Computer Vision References: Chapter 4 - - PowerPoint PPT Presentation
IMAGE FILTERING INEL 6088 Computer Vision References: Chapter 4 Jain et al, Chapter 3 Davies 2.3 Convolutions and Point Spread Functions 39 at perfectly good algorithm strategies that mysteriously turn out not to work well in practice! 2.3
References: Chapter 4 Jain et al, Chapter 3 Davies
40
CHAPTER 2 Images and Imaging Operations Convolution can then be calculated using the more intuitive formula:
i
J
(2.29) Clearly, this involves multiplying corresponding values in the modified mask and the neighborhood under consideration. Reexpressing this result for a 3 x 3 neighborhood and writing the mask coefficients in the form: h4 h3 h2" h5 hO hi h6 h7 h8 the algorithm can be obtained in terms of our earlier notation: CONVOLV: [[ QO = PO * hO + PI * hi + P2 * h2 + P3 * h3 + P4 * h4 +P5 * h5 + P6 * h6 + P7 * h7 -f P8 * h8; ]] (2.30) We are now in a position to apply convolution to a real situation. At this stage we merely extend the ideas of the previous section, attempting to suppress noise by averaging not over corresponding pixels of different images, but over nearby pixels in the same image. A simple way of achieving this is to use the convolution mask: 1 9 "1 1 1 1 1 1 1 1 1 where the number in front of the mask weights all the coefficients in the mask and is inserted to ensure that applying the convolution does not alter the mean intensity in the image. As hinted earher, this particular convolution has the effect of blurring the image as well as reducing the noise level (Fig. 2.17). More will be said about this in the next chapter. Convolutions are linear operators and are the most general spatially invariant linear operators that can be applied to a signal such as an image. Note that linearity is often of interest in that it permits mathematical analysis to be performed that would otherwise be intractable.
2.3 Convolutions and Point Spread Functions 39 at perfectly good algorithm strategies that mysteriously turn out not to work well in practice!
2.3 Convolutions and Point Spread Functions
Convolution is a powerful and widely used technique in image processing and
book, it is useful to introduce it at an early stage. We start by defining the convolution of two functions/(x) and g(x) as the integral: f(x) * g(x) = / f(u)g(x - u)du (2.26)
J—oo
The action of this integral is normally described as the result of applying a point spread function g(x) to all points of a function f(x) and accumulating the contributions at every point. It is significant that if the point spread function (PSF) is very narrow,^ then the convolution is identical to the original function/(x). This makes it natural to think of the function/(x) as having been spread out under the influence of g(x). This argument may give the impression that convolution necessarily blurs the original function, but this is not always so if, for example, the PSF has a distribution of positive and negative values. When convolution is appHed to digital images, the above formulation changes in two ways: (1) a double integral must be used in respect of the two dimensions; and (2) integration must be changed into discrete summation. The new form of the convolution is: where g is now referred to as a spatial convolution mask. When convolutions are performed on whole images, it is usual to restrict the sizes of masks as far as possible in order to save computation. Thus, convolution masks are seldom larger than 15 pixels square, and 3 x 3 masks are typical. The fact that the mask has to be inverted before it is applied is inconvenient for visualizing the process of
h{x^y) = g(-x^~y)
(2.28)
5 Formally, it can be a delta function, which is infinite at one point and zero elsewhere while having an integral of unity.
2.3 Convolutions and Point Spread Functions 39 at perfectly good algorithm strategies that mysteriously turn out not to work well in practice!
2.3 Convolutions and Point Spread Functions
Convolution is a powerful and widely used technique in image processing and
book, it is useful to introduce it at an early stage. We start by defining the convolution of two functions/(x) and g(x) as the integral: f(x) * g(x) = / f(u)g(x - u)du (2.26)
J—oo
The action of this integral is normally described as the result of applying a point spread function g(x) to all points of a function f(x) and accumulating the contributions at every point. It is significant that if the point spread function (PSF) is very narrow,^ then the convolution is identical to the original function/(x). This makes it natural to think of the function/(x) as having been spread out under the influence of g(x). This argument may give the impression that convolution necessarily blurs the original function, but this is not always so if, for example, the PSF has a distribution of positive and negative values. When convolution is appHed to digital images, the above formulation changes in two ways: (1) a double integral must be used in respect of the two dimensions; and (2) integration must be changed into discrete summation. The new form of the convolution is: where g is now referred to as a spatial convolution mask. When convolutions are performed on whole images, it is usual to restrict the sizes of masks as far as possible in order to save computation. Thus, convolution masks are seldom larger than 15 pixels square, and 3 x 3 masks are typical. The fact that the mask has to be inverted before it is applied is inconvenient for visualizing the process of
h{x^y) = g(-x^~y)
(2.28)
5 Formally, it can be a delta function, which is infinite at one point and zero elsewhere while having an integral of unity.
40
CHAPTER 2 Images and Imaging Operations Convolution can then be calculated using the more intuitive formula:
i
J
(2.29) Clearly, this involves multiplying corresponding values in the modified mask and the neighborhood under consideration. Reexpressing this result for a 3 x 3 neighborhood and writing the mask coefficients in the form: h4 h3 h2" h5 hO hi h6 h7 h8 the algorithm can be obtained in terms of our earlier notation: CONVOLV: [[ QO = PO * hO + PI * hi + P2 * h2 + P3 * h3 + P4 * h4 +P5 * h5 + P6 * h6 + P7 * h7 -f P8 * h8; ]] (2.30) We are now in a position to apply convolution to a real situation. At this stage we merely extend the ideas of the previous section, attempting to suppress noise by averaging not over corresponding pixels of different images, but over nearby pixels in the same image. A simple way of achieving this is to use the convolution mask: 1 9 "1 1 1 1 1 1 1 1 1 where the number in front of the mask weights all the coefficients in the mask and is inserted to ensure that applying the convolution does not alter the mean intensity in the image. As hinted earher, this particular convolution has the effect of blurring the image as well as reducing the noise level (Fig. 2.17). More will be said about this in the next chapter. Convolutions are linear operators and are the most general spatially invariant linear operators that can be applied to a signal such as an image. Note that linearity is often of interest in that it permits mathematical analysis to be performed that would otherwise be intractable. 1D: 2D, discrete For convenience, pre-calculate
f(x) ⋆ g(x) = ∫
+∞ −∞
f(u)g(x − u)du ⇒ f(i) ⋆ g(i) =
m
∑
k=1
f(k)g(i − k)
3
4
Salt & pepper - Random black & white pixels Impulse - Only random white Gaussian – random gray level variations
5
ADDITIVE WHITE GAUSSIAN NOISE
6
Single-peak,
7
8
9
I = imread('eight.tif'); figure imshow(I)
% For this example, add salt and pepper noise to the image. This % type of noise consists of random pixels being set to black or % % white (the extremes of the data range). J = imnoise(I,'salt & pepper',0.02); figure imshow(J)
% Filter the noisy image, |J|, % with an averaging filter and % display the results. The % example uses a 3-by-3 % neighborhood. Kaverage = filter2(fspecial('average',3),J)/ 255; figure imshow(Kaverage)
% Now use a median filter to filter % the noisy image, |J|. The example % also uses a 3-by-3 neighborhood. % Display the two filtered images % side-by-side for comparison. Notice % that |medfilt2| does a better job % of removing noise, with less % blurring of edges of the coins. Kmedian = medfilt2(J); imshowpair(Kaverage,Kmedian,'montage')
13
g[i, j] = exp ✓ −i2 + j2 2σ2 ◆ = exp ✓ − i2 2σ2 ◆ exp ✓ − j2 2σ2 ◆
14
15
Multiple lopes can cause halos on image
16
use w = 5σ for 98.76% of the area; for a σ=0.6, use w = 3 pixels; for σ=1, use w = 5
GAUSSIAN FILTER – CAN BE APPLIED AS THE CONVOLUTION OF TWO 1D FILTERS
Table 3.1 Savings achieved by factorizing an nxn Gaussian operator
n 1 3 5 7 9 1 1 1 3 1 5 2n 2 6 1 1 4 1 8 22 26 30 n^ 1 9 25 49 8 1 1 2 1 1 6 9 225 nil . 5 1 . 5 2 . 5 3 . 5 4 . 5 5 . 5 6 . 5 7 . 5
18
19
Result of using a single horizontal convolution mask k on (a) original noisy image. (b) After convolution with k. (c) transpose of (b). (d) convolution of (c) with k. (e) Transpose of (d) to get the final smoothed image.
20
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1
21
22
Another approach: compute the mask directly from the discrete Gaussian distribution. Below it is shown the result of using For n=7 and σ2=2.
23
24
25
Original Image Gaussian filtered image, < = 2
% Filter the image with a Gaussian filter % with standard deviation of 2. Iblur = imgaussfilt(I, 2);
27
Another commonly used Gaussian mask
28