september 25, 2014computer vision lecture 6: spatial filtering 1 computing object orientation we...

25
September 25, 2014 Computer Vision Lecture 6: Spatial 1 Computing Object Orientation We compute the orientation of an object as the orientation of its greatest elongation. This axis of elongation is also called the axis of second moment of the object. It is determined as the axis with the least sum of squared distances between the object points and itself. In order to standardize the orientation of the object, we rotate it around its center so that its axis of second moment is vertical.

Upload: scarlett-nichols

Post on 22-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

1

Computing Object OrientationWe compute the orientation of an object as the orientation of its greatest elongation.

This axis of elongation is also called the axis of second moment of the object.

It is determined as the axis with the least sum of squared distances between the object points and itself.

In order to standardize the orientation of the object, we rotate it around its center so that its axis of second moment is vertical.

Page 2: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

2

Intensity TransformationSometimes we need to transform the intensities of all image pixels to prepare the image for better visibility of information or for algorithmic processing.

Page 3: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

3

Gamma Transformation

Gamma

transformation:

m

InI '

Page 4: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

4

Gamma Transformation

Page 5: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

5

Linear Histogram Scaling

Page 6: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

6

Linear Histogram ScalingFor a desired intensity range [a, b] we can use the following linear transformation:

aIIII

abI

)(' minminmax

Note that outliers (individual pixels of very low or high intensity) should be disregarded when computing Imin and Imax.

Page 7: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

7

Image Filtering• Many basic image processing techniques are

based on convolution.• In a convolution, a convolution filter W

is applied to every pixel of an image I to create a filtered image I*.

• The filter W itself is a 2D matrix of real values.• To simplify the mathematics, we could consider W

to have a center [0, 0] and extend from –m to m vertically and –n to n horizontally.

• This means that W is of size (2m + 1)×(2n + 1).

Page 8: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

8

j

i

ConvolutionExample: Averaging filter:

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

Page 9: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

9

Convolution

Grayscale Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

Averaging Filter:

Page 10: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

10

Convolution

Original Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

Filtered Image:

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

value = 11/9 + 61/9 + 31/9 + 21/9 + 111/9 + 31/9 + 51/9 + 101/9 + 61/9 = 47/9 = 5.222

5

Page 11: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

11

Convolution

Original Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

Filtered Image:

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

value = 61/9 + 31/9 + 21/9 + 111/9 + 31/9 + 101/9 + 101/9 + 61/9 + 91/9 = 60/9 = 6.667

5 7

Page 12: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

12

Convolution

Original Image:

1 6 3 2 9

2 11 3 10 0

5 10 6 9 7

3 1 0 2 8

4 4 2 9 10

Filtered Image:

0 0 0 0 0

0 0

0 0

0 0

0 0 0 0 0

5 7 5

5

5

5 6

64

Now you can see the averaging (smoothing) effect of the 33 filter that we applied.

Page 13: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

13

Convolution• It needs to be noted that for convolution the filter

needs to be rotated by 180 before starting the computations (otherwise it’s a correlation).

• An intuitive explanation is that we would like convolution to be like a “local multiplication of patterns.”

• For example, if our image contains a few 1s and otherwise 0s, we would expect the convolution result to contain a copy of the filter pattern centered at each 1.

• Let us look at an image with one 1-pixel:

Page 14: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

14

Convolution

Image:

0 0 0 0 0

0 0 0 0 0

0 0 1 0 0

0 0 0 0 0

0 0 0 0 0

1 2 3

4 5 6

7 8 9

Filter: Result:

0 0 0 0 0

0 9 8 7 0

0 6 5 4 0

0 3 2 1 0

0 0 0 0 0

Oops! The copy of the filter is rotated by 180 !

Page 15: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

15

Convolution• If we rotate the filter by 180 beforehand, we get

the desired result. • This leads to the following definition of convolution

for image I, filter W, and result I*:

m

mk

n

nl

ljkilkjijiji ],[],[],[*],[],[* IWIWI

• This formula needs to be applied to all coordinates [i, j] in I in order to create the complete image I*.

• Convolution is commutative, i.e., W and I are exchangeable.

Page 16: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

16

Image FilteringMore common: Gaussian Filters

2

22

222

1),(),(

yx

eyxGyxW

14741

41626164

72641267

41626164

14741

Discrete version: 1/273

• implement decreasing influence by more distant pixels

Continuous version:

Page 17: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

17

Image Filtering

original 33 99 1515

Effect of Gaussian smoothing:

Page 18: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

18

Properties of Gaussian FiltersThe application of Gaussian convolution filters can be made more efficient.

This is important, for example, if we want to apply different Gaussian filters to a large number of big input images.

The basic idea is to separate the convolution with the 2D Gaussian filter into two successive convolutions with 1D Gaussian filters.

One of these filters is vertical, the other one horizontal.

Page 19: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

19

Properties of Gaussian FiltersThe general form of the Gaussian filter, without a normalizing factor, is given by:

2

22

2],[ ji

eji

G

The convolution of an image F with a Gaussian filter G of size (2m + 1)(2n + 1) is given by:

This formula needs to be applied to all coordinates [i, j] in F in order to create the convoluted image.

m

mk

n

nl

ljkilkjiji ],[],[],[*],[ FGFG

Page 20: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

20

Properties of Gaussian FiltersThen we have:

m

mk

n

nl

ljkilkjiji ],[],[],[*],[ FGFG

m

mk

n

nl

lk

ljkie ],[2

22

2 F

m

mk

n

nl

lk

ljkiee ],[2

2

2

2

22 F

m

mk

n

nl

lk

ljkiee ],[2

2

2

2

22 F

Page 21: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

21

Properties of Gaussian FiltersThe formula in the curly braces describes the convolution of F[i, j] with a horizontal one-dimensional Gaussian filter.

The remainder of the formula takes the result of this first convolution and performs a convolution with a vertical one-dimensional Gaussian filter on it.

So instead of applying an (2m + 1)(2n + 1) Gaussian convolution filter, we can successively apply a 1(2n + 1) filter and an (2m + 1)1 filter.

This increases the efficiency of the computation.

Page 22: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

22

Different Types of Filters

• Smoothing can reduce noise in the image.• This can be useful, for example, if you want to find

regions of similar color or texture in an image.

• However, there are different types of noise.• For so-called “salt-and-pepper” noise, for example,

a median filter can be more effective.• Note that it is not a convolution filter, but it works

similarly.

Page 23: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

23

Median Filter• Use, for example, a 33 filter and move it across

the image like we did before.• For each position, compute the median of the

brightness values of the nine pixels in question.– To compute the median, sort the nine values in

ascending order.– The value in the center of the list (here, the fifth

value) is the median.• Use the median as the new value for the center

pixel.

Page 24: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

24

Median Filter

• Advantage of the median filter: Capable of eliminating outliers such as the extreme brightness values in salt-and-pepper noise.

• Disadvantage: The median filter may change the contours of objects in the image.

Page 25: September 25, 2014Computer Vision Lecture 6: Spatial Filtering 1 Computing Object Orientation We compute the orientation of an object as the orientation

September 25, 2014 Computer Vision Lecture 6: Spatial Filtering

25

Median Filter

original image 33 median 77 median