Presentation is loading. Please wait.

Presentation is loading. Please wait.

7. Neighbourhood operations A single pixel considered in isolation conveys information on the intensity and colour at a single location in an image, but.

Similar presentations


Presentation on theme: "7. Neighbourhood operations A single pixel considered in isolation conveys information on the intensity and colour at a single location in an image, but."— Presentation transcript:

1 7. Neighbourhood operations A single pixel considered in isolation conveys information on the intensity and colour at a single location in an image, but it can tell us nothing about the way in which these properties vary spatially. The point processes described in the preceding chapter, which change a pixel's value independently of all other pixels, cannot be used to investigate or control spatial variations in image intensity or colour.

2 For this, we need to perform calculations over areas of an image; in other words, a pixel's new value must be computed from its old value and the values of pixels in its vicinity. These neighbourhood operations are invariably more costly than simple point processes, but they allow us to achieve a whole range of interesting and useful effects.

3 In this chapter, we consider several neighbourhood operations which include Convolution, Linear Filter, and Edge Detection. These operations employ same approach in which a pixel's new value is a weighted sum of its old value and those of its neighbourhood. We also assume that these operations are being performed on greyscale images.

4 Convolution Convolution is the fundamental neighbourhood operations of image processing. In convolution, the calculation performed at a pixel is a weighted sum of grey levels from a neighbourhood surrounding a pixel (including the pixel under consideration). Clearly, if a neighbourhood is centred on a pixel, then it must have odd dimensions, e.g., 3 x 3, 5 x 5, etc.

5 Grey levels taken from the neighbourhood are weighted by coefficients that come from a matrix or convolution kernel. The kernel's dimensions define the size of the neighbourhood in which calculations take place. Usually, the kernel dimensions of 3 x 3 are the most common. Figure 7.1 shows a 3 x 3 kernel and the corresponding 3 x 3 neighbourhood of pixels from an image. The kernel is centred on the shaded pixel.

6 725360 765665 887882 012 001 1-202 201 Y X Fig.7.1. A 3 x 3 convolution kernel and the corresponding image neighbourhood.

7 The result of convolution will be a new value for this pixel. During convolution, we take each kernel coefficient in turn and multiply it by a value from the neighbourhood of the image lying under the kernel. We apply the kernel to the image in such a way that the value at the top ‑ left corner of the kernel is multiplied by the value at the bottom-right corner of the neighbourhood.

8 Denoting the kernel by h and the image by f, the entire calculation is g(x, y) = h(0,0) f (X + 1, Y + 1) + h(1,0) f (X, Y + 1) + h(2,0) f (X ‑ 1, Y + 1) + h(0,1) f(X+1,Y) + h(1,1) f (X, Y) + h(2,1) f (X ‑ 1, Y) + h(0,2) f (X + 1, Y ‑ 1) + h(1,2) f (X, Y ‑ 1) + h(2,2) f (X ‑ 1, Y ‑ 1)

9 This summation can be expressed as 1 1 g (x, y) = ∑ ∑ h (j+1, k+1) f (x ‑ j, y ‑ k). k=-1 j=-1 For the kernel and neighbourhood illustrated in Figure 7. 1, the result of convolution is g(x, y) = ( ‑ 1 x 82) + (1 x 88) + ( ‑ 2 x 65) + (2 x 76) + ( ‑ 1 x 60) + (1 x 72) = 40

10 Algorithm 7.1. Convolution of an image using a 3 x 3 convolution kernel. Create an M x N input image, f Create a kernel, h, with dimension 3 x 3 Let g be an output image of M x N. /* setting the borders pixels to zero */ for all pixel coordinates, x & y, do g(x,y) = 0 end for

11 for y = 1 to N - 2 do for x = 1 to M - 2 do sum = 0 sum = h(0,0)f(x+1,y+1) + h(1,0)f(x,y+1) + h(2,0)f(x-1,y+1) + h(0,1)f(x+1,y) + h(1,1)f(x,y) + h(2,1)f(x-1,y) + h(0,2)f(x+1,y-1) + h(1,2)f(x,y-1) + h(2,2)f(x-1,y-1)

12 g(x,y) = sum /* when convolution produces a negative result, the output is set to zero. Similarly, when convolution produces a result exceeding 255, the output is fixed at 255 */ if sum < 0 then g(x,y) = 0 else if sum > 255 then g(x,y) = 255 end if end for


Download ppt "7. Neighbourhood operations A single pixel considered in isolation conveys information on the intensity and colour at a single location in an image, but."

Similar presentations


Ads by Google