neighborhood processing - psu

34
Neighborhood Processing 1. Spatial domain refers to the image plane itself, and methods in this category are based on direct manipulation of pixels in an image. 2. For spatial filtering, sometimes is referred to as neighborhood processing, or spatial convolution.

Upload: others

Post on 23-Feb-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Neighborhood Processing - PSU

Neighborhood Processing

1. Spatial domain refers to the image plane itself,and methods in this category are based on directmanipulation of pixels in an image.

2. For spatial filtering, sometimes is referred to asneighborhood processing, or spatial convolution.

Page 2: Neighborhood Processing - PSU

neighborhood processingThe process of moving the center point creates new neighborhoods, one for each pixel in the input image. • The two principal terms used to identify this operation are neighborhood processing and spatial filtering.

• If the  computation performed on the pixels of the neighborhoods are linear, – the operation is called linear spatial filtering (the term spatial convolution also used); 

– otherwise, it is called nonlinear spatial filtering.

Page 3: Neighborhood Processing - PSU

BASIC TERMINOLOGY

(a)4‐neighborhood; (b) diagonal neighborhood; (c) 8‐neighborhood.

Page 4: Neighborhood Processing - PSU

• The process consists simply of moving the center of the filter mask w from point to point in an image, f.

• At each point (x, y), the response of the filter at that point is the sum of products of the filter coefficients and the corresponding

neighborhood pixels in the area spanned by the filter mask. 

• For a mask of size m × n, we assume typically that m = 2a + 1 and n = 2b + 1, where a and b are nonnegative integers.

Page 5: Neighborhood Processing - PSU

Spatial FilteringSpatial filtering is a neighborhood processing consisting of:

1. defining a center point, (x, y); 2. performing an operation that involves only the 

pixels in a predefined neighborhood of the center point;

3. letting the result of that operation be the "response" of the process at that point;

4. repeating the process for every point in the image.

Page 6: Neighborhood Processing - PSU

Filtering• Linear Filters: Output pixel is computed as a sum of products of the pixel values and mask coefficients in the pixel’s neighborhood in the original image. Ex: mean filter.

• Nonlinear Filters: Output pixel is selected from an ordered (ranked) sequence of pixel values in the pixel’s neighborhood in the original image. Ex: median filter.

The coefficients are arranged as a matrix, called a filter, mask, filter mask, kernel, template, or window, with the first three

terms being the most prevalent. For reasons that will become obvious shortly, the terms convolution filter, mask, or kernel, also are used.

Page 7: Neighborhood Processing - PSU

CONVOLUTION• In one‐dimensional

• Ex: Let A = {0, 1, 2, 3, 2, 1, 0}, and B = {1, 3,−1}.1. A(x=1)

(0 × (−1)) + (0 × 3) + (1 × 1) = 1

Page 8: Neighborhood Processing - PSU

CONVOLUTION (cont.)

7. A(x=7)

(0 × (−1)) + (1 × 3) + (2 × 1) = 5

2. A(x=2)

(1 × (−1)) + (0 × 3) + (0 × 1) = −1

Page 9: Neighborhood Processing - PSU

2D Convolution/

/

/

/

EXAMPLE

Page 10: Neighborhood Processing - PSU

2D Convolution

Page 11: Neighborhood Processing - PSU

Image filteringFiltering operations use masks as the spatial filters, which are named based on their behavior in the spatial frequency:• Low‐pass filters (LPFs) preserve low‐frequency components (i.e., coarser details and homogeneous areas in the image).

• High‐pass filters (HPFs) enhance high‐frequency components (i.e., fine details in the image)

Page 12: Neighborhood Processing - PSU

Image filtering

Original image LPF image HPF image

Page 13: Neighborhood Processing - PSU

Spatial Averaging and Spatial Low‐Pass Filtering

where g and f are output and input images.w is weighted matrix with the size  .

For average filter, all elements in w are 1, so that

w and is numbers of element in w

Page 14: Neighborhood Processing - PSU

Spatial Averaging and Spatial Low‐Pass Filtering

,12 ,14 1, 1, , 1 , 1

1 11 1 ,

1 1 11 1 11 1 1

, 0 0

0 0

,1

, ,

14 ,

14 , , 1 1, 1, 1

Page 15: Neighborhood Processing - PSU

156  159  158  155  158160  154  157  158  157156  159  158  155  158160  154  157  158  157156  153  155  159  159

Nw = 4;for x=1:4

for y=1:4w = f(x:x+1,y:y+1);g(x,y) = sum(w(:))/Nw;

endend

14 ,

14 , , 1 1,

1, 1=(156+159+160+154)/4=157.25

157.25  157.00 157.00  157.00157.25  157.00  157.00  157.00157.25  157.00  157.00  157.00155.75  154.75  157.25  158.25

157.25  159  158  155  158160        154  157  158  157156        159  158  155  158160        154  157  158  157156        153  155  159  159

Page 16: Neighborhood Processing - PSU

Variations of averaging filter 

Modified Mask Coefficients

Page 17: Neighborhood Processing - PSU

Variations of averaging filter 

a, b,c, da) Original imageb) 3x3 averagec) Modified Mask 

Coefficients

d) Gaussian blur filter, 0.5

0.0113 0.0838 0.0113 0.0838 0.6193 0.08380.0113 0.0838 0.0113

Page 18: Neighborhood Processing - PSU

Ex. Gaussian blur filters

Page 19: Neighborhood Processing - PSU

Ex. Gaussian blur filters

0

0.1

12

0.2

Gaussian Filter in 5x5,s=0.9

53 44 35 2

1

0

2

12

10-3

4

34

average Filter in 13x13

5

6

13126 117 108 99 810 7611 512 413 321

01

0.1

234

Gaussian Filter in 13x13,s=0.9

5

0.2

13126 117 108 99 810 7611 512 413 321

01

0.05

234

Gaussian Filter in 13x13,s=1.5

5

0.1

13126 117 108 99 810 7611 512 413 321

Page 20: Neighborhood Processing - PSU

Properties of the Gaussian blur filter• The window is symmetric with respect to rotation.

• The window’s coefficients fall off to (almost) zero at the kernel’s edges.

• The output image obtained after applying the Gaussian blur filter is more pleasing to the eye than the one obtained using other low‐pass filters.

• The kernel is separable, which can lead to fast computational implementations.

Page 21: Neighborhood Processing - PSU

Median filterThe median filter is a nonlinear filter used in image processing. It works by:• sorting the pixel values within a neighborhood, 

• finding the median value, and • replacing the original pixel value with the median.

Page 22: Neighborhood Processing - PSU

Median filtering process

Page 23: Neighborhood Processing - PSU

Median filteringMedian filter operates in the window W, given by:

Window W has the size, for ex.,  3 3, 5 etc. 

Page 24: Neighborhood Processing - PSU

Median filteringEx. Let  f(x) = [2 3 8 4 2], W=[‐1,0,1], the filtering operation can be performed by:

The output of median filter is g(x) = [2 3 4 4 2].

Page 25: Neighborhood Processing - PSU

Original Noise,var=0.005

Median,3x3 Median,5x5

Page 26: Neighborhood Processing - PSU

A Noisy Step Edge

0 10 20 30 40 50 60 700

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

[1:70];;

where unifrnd 0.25, 0.25,1,70

HHn H u

u

0.25 for 351.25 for 35

nH n

n

Page 27: Neighborhood Processing - PSU

0 10 20 30 40 50 60 700

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Blurred Noisy 1D Step Edge

4

4

19 k

h n H n k

Page 28: Neighborhood Processing - PSU

0 10 20 30 40 50 60 700

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Blurred Noisy 1D Step Edge

Hn(34-4:34+4)= 0.6008

0.02190.69660.54770.36651.43391.17801.34411.7223

Hn(33-4:33+4)=0.69660.54770.36651.43391.17801.34411.72231.41011.3909

0.8791

1.1211

mean

mean

Page 29: Neighborhood Processing - PSU

0 10 20 30 40 50 60 700

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Median Filtered Noisy 1D Step Edge

4

4med

kh n H n k

Page 30: Neighborhood Processing - PSU

0 10 20 30 40 50 60 700

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Median Filtered Noisy 1D Step Edge

Hn(34-4:34+4)=0.60080.02190.69660.54770.36651.43391.17801.34411.7223

0.02190.36650.54770.60080.69661.17801.34411.43391.7223

Hn(35-4:35+4)=0.02190.69660.54770.36651.43391.17801.34411.72231.4101

0.02190.36650.54770.69661.17801.34411.41011.43391.7223

sorted

sorted

median

median

Page 31: Neighborhood Processing - PSU

0 10 20 30 40 50 60 700

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

Median vs. Blurred

step

noisy

blurred

median

ตวักรองมธัยฐานจะคง

สภาพของขอบได้ดีกวา่

ตวักรองคา่เฉลีย่

ตวักรองมธัยฐานจะคง

สภาพของขอบได้ดีกวา่

ตวักรองคา่เฉลีย่

Page 32: Neighborhood Processing - PSU

Median vs. AverageOriginal

Noise,var=0.1

Median,3x3 Median,5x5

Average,3x3 Average,5x5

Page 33: Neighborhood Processing - PSU

Properties of the median filter• It is a nonlinear filter, thus, any x(m) and  y(m)

median(x(m)+y(m)) ≠ median(x(m))+median(y(m))

• Noise remove in spatial resolution, the median filter has performance better than the average filter.

• The performance of noise remove will be decreased, when the noisy quantity more than haft of the window.

Page 34: Neighborhood Processing - PSU

Original noise,var=0.1 average with 3x3

average with 5x5 average with 7x7 average with 9x9

Smoothing image containing Gaussian noise