IMAGE FILTERING INEL 6088 Computer Vision References: Chapter 4 - - PowerPoint PPT Presentation

image filtering
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

IMAGE FILTERING

INEL 6088 Computer Vision

References: Chapter 4 Jain et al, Chapter 3 Davies

slide-2
SLIDE 2

CONVOLUTION

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.

mask

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

  • ther areas of science. Because it appears in many applications throughout this

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

  • convolution. In this book we therefore present only preinverted masks of the form:

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

  • ther areas of science. Because it appears in many applications throughout this

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

  • convolution. In this book we therefore present only preinverted masks of the form:

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

CONV : [[q0 = p0h0 + p1h1 + p2h2 + p3h3

f(x) ⋆ g(x) = ∫

+∞ −∞

f(u)g(x − u)du ⇒ f(i) ⋆ g(i) =

m

k=1

f(k)g(i − k)

+p4h4 + p5h5 + p6 + h6 + p7h7 + p8h8]]

slide-3
SLIDE 3

3

CHARACTERISTICS OF CONVOLUTION

  • Linear (convolution of a sum is the sum of the

convolutions)

  • Convolution of a scaled image is the scaled convolution
  • Spatially invariant
  • Convolution in the image domain correspond to

multiplication in the (spatial) frequency domain

  • Frequency-domain convolution used only for very large

kernels – not common in machine vision

  • The kernel defines the filter being used
  • We use non-linear filters as well; formalism does not

apply but many are used in a very similar way.

slide-4
SLIDE 4

4

Noise-free

Salt & pepper - Random black & white pixels Impulse - Only random white Gaussian – random gray level variations

Common Types of Noise

slide-5
SLIDE 5

5

ADDITIVE WHITE GAUSSIAN NOISE

slide-6
SLIDE 6

6

MEAN FILTER

Smoothing filter: pixel weights are not equal, but are usually symmetric and add 1.

Single-peak,

  • r main lope
slide-7
SLIDE 7

7

3×3 5×5 7×7 Mean Filter Applied to Noisy Images

slide-8
SLIDE 8

8

Result of using the smoothing filter seen previously

slide-9
SLIDE 9

9

MEDIAN FILTER

Nonlinear filter - effective to remove salt & pepper and impulse noise without removing too much image detail. MATLAB Example

slide-10
SLIDE 10

MATLAB EXAMPLE

I = imread('eight.tif'); figure imshow(I)

  • penExample('images/CompareResultsOfAveragingFilterAndMedianFilterExample')
slide-11
SLIDE 11

% 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)

slide-12
SLIDE 12

% 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')

slide-13
SLIDE 13

13

GAUSSIAN SMOOTHING

g[i, j] = exp ✓ −i2 + j2 2σ2 ◆ = exp ✓ − i2 2σ2 ◆ exp ✓ − j2 2σ2 ◆

slide-14
SLIDE 14

14

PROPERTIES OF GAUSSIAN FILTER

  • Rotational symmetry
  • Single lope in both space and frequency domain
  • Smoothing is controlled by a single parameter, σ
  • Separable
  • Will spread impulse and salt & pepper noise!
slide-15
SLIDE 15

15

Gaussian Mean space frequency

Multiple lopes can cause halos on image

slide-16
SLIDE 16

16

  • To generate the 1D kernel, we must discretize the gaussian
  • Require the mask width to subtend most of the gaussian area:

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

slide-17
SLIDE 17

62 CHAPTER 3 Basic Image Filtering Operations and

l6

1 2 1 2 4 2 1 2 1

1 4

" 1 1

7 ,

I j

f[l 2 1]

(3.6) Overall, this approach replaces a single nxn

  • perator whose load is 0(n^)

with two operators of load 0(n), and for « > 3 there are always worthwhile

  • savings. Ignoring scanning and other overheads we are summarize the situation

in Table 3.1, the final column of which represents the saving factor. It turns out that it is not possible to decompose the median filter in the same way without making approximations. However, it is quite common to try to perform a similar function by applying two 1-D median filters in turn (Narendra, 1978). Although the effect is similar in its outlier rejection properties to the corresponding 2-D median filter, by appealing to specific examples of image data it is simple to show that the two are not formally equivalent. An instance in which the same effect is obtained by a 3 x 3 median filter or by 3 x 1 and 1 x 3 median filters applied in either order is the following: 0 0 0 0 0 0 0 0 1 0 0 0

  • riginal image segment: 0 0 0

1 0 1 0 1 0 0 0 0 0 0 0 In this case, all the Ts immediately disappear after applying a 3 x 3 o r a 3 x l o r a 1 X 3 median filter. In the following instance, the situation is slightly more complex: 0 0 0 0 0 0 0 0 1 1 2 0 0 2 2 0 0 0 0 0 0 0 0

  • riginal image segment:

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

apply to whole image first

slide-18
SLIDE 18

18

slide-19
SLIDE 19

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.

slide-20
SLIDE 20

20

DESIGN OF GAUSSIAN FILTERS

  • Use the row n of Pascal’s Triangle as a one-dimensional,

n-point approximation of a Gaussian filter.

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

slide-21
SLIDE 21

21

Using the fifth row of Pascal’s triangle as a Gaussian filter. (a) original; (b) After smoothing in the horizontal dir. (c) After smoothing in the vertical direction

slide-22
SLIDE 22

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.

slide-23
SLIDE 23

23

After multiplying by 91 so that the smallest values (corners) become 1,

slide-24
SLIDE 24

24

3-D plot of the 7x7 Gaussian mask.

slide-25
SLIDE 25

25

Result of Gaussian smoothing using the 7x7 mask. Also see a MATLAB example

slide-26
SLIDE 26

MATLAB EXAMPLE SMOOTH IMAGE WITH GAUSSIAN FILTER

  • penExample('images/SmoothImageWithGaussianFiltersExample')

Original Image Gaussian filtered image, < = 2

% Filter the image with a Gaussian filter % with standard deviation of 2. Iblur = imgaussfilt(I, 2);

slide-27
SLIDE 27

27

The result of the convolution must be divided by the sum of the mask weights to ensure that regions of uniform intensity are not affected.

Another commonly used Gaussian mask

slide-28
SLIDE 28

28