september 10, 2013computer vision lecture 3: binary image processing 1thresholding here, the right...

19
September 10, 2013 Computer Vision Lecture 3: 1 Thresholding Here, the right image is created from the left image by thresholding, assuming that object pixels are darker than background pixels. As you can see, the result is slightly imperfect (dark background pixels).

Upload: ann-harrell

Post on 17-Dec-2015

226 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

1

Thresholding

Here, the right image is created from the left image by thresholding, assuming that object pixels are darker than background pixels.

As you can see, the result is slightly imperfect (dark background pixels).

Page 2: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

2

Geometric PropertiesLet us say that we want to write a program that can recognize different types of tools in binary images.

Then we have the following problem:

The same tool could be shown in different

• sizes,

• positions, and

• orientations.

Page 3: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

3

Geometric Properties

Page 4: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

4

Geometric PropertiesWe could teach our program what the objects look like at different sizes and orientations, and let the program search all possible positions in the input.

However, that would be a very inefficient and inflexible approach.

Instead, it is much simpler and more efficient to standardize the input before performing object recognition.

We can scale the input object to a given size, center it in the image, and rotate it towards a specific orientation.

Page 5: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

5

Computing Object SizeThe size A of an object in a binary image is simply defined as the number of black pixels (“1-pixels”) in the image:

1

0

1

0

],[m

i

n

j

jiBA

A is also called the zeroth-order moment of the object.

In order to standardize the size of the object, we expand or shrink the object so that its size matches a predefined value.

Page 6: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

6

Computing Object PositionWe compute the position of an object as the center of gravity of the black pixels:

A

jijB

x

m

i

n

j

1

0

1

0

],[

These are also called the first-order moments of the object.

In order to standardize the position of the object, we shift its position so that it is in the center of the image.

A

jiiB

y

m

i

n

j

1

0

1

0

],[

Page 7: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 17, 2012 Introduction to Artificial Intelligence Lecture 4: Computer Vision II

7

Computing Object PositionCentering the object within the image:

Binary image:

5

4

3

2

1

54321

x

y

Compute the center of gravity:

6.26

16

6

443221

x

38.16

11

6

322211

y

Finally, shift the image content so that the center of gravity coincides with the center of the image.

Page 8: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

8

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 9: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

9

ProjectionsProjections of a binary image indicate the number of 1-pixels in each column, row, or diagonal in that image.

We refer to them as horizontal, vertical, or diagonal projections, respectively.

Although projections occupy much less memory that the image they were derived from, they still contain essential information about it.

Page 10: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

10

ProjectionsKnowing only the horizontal or vertical projection of an image, we can still compute the size of the object in that image.

Knowing the horizontal and vertical projections of an image, we can compute the position of the object in that image.

Knowing the horizontal, vertical, and diagonal projections of an image, we can compute the orientation of the object in that image.

Page 11: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

11

Projections

Horizontal projection

Vertical projection

Page 12: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

12

Projections

Diagonal projection

Page 13: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

13

Some DefinitionsFor a pixel [i, j] in an image, …

[i, j]

[i-1, j]

[i, j-1] [i, j+1]

[i+1, j]

…these are its 4-neighbors

(4-neighborhood).

[i, j]

[i-1, j]

[i, j-1] [i, j+1]

[i+1, j]

…these are its 8-neighbors

(8-neighborhood).

[i-1, j-1] [i-1, j+1]

[i+1, j-1] [i+1, j+1]

Page 14: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

14

Some DefinitionsA path from the pixel at [i0, j0] to the pixel [in, jn] is a sequence of pixel indices [i0, j0], [i1, j1], …, [in, jn] such that the pixel at [ik, jk] is a neighbor of the pixel at [ik+1, jk+1] for all k with 0 ≤k ≤ n – 1.

If the neighbor relation uses 4-connection, then the path is a 4-path; for 8-connection, the path is an 8-path.

4-path 8-path

Page 15: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

15

Some DefinitionsThe set of all 1 pixels in an image is called the foreground and is denoted by S.

A pixel pS is said to be connected to qS if there is a path from p to q consisting entirely of pixels of S.

Connectivity is an equivalence relation, because• Pixel p is connected to itself (reflexivity).• If p is connected to q, then q is connected to p (commutativity).• If p is connected to q and q is connected to r, then p is connected to r (transitivity).

Page 16: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

16

Some DefinitionsA set of pixels in which each pixel is connected to all other pixels is called a connected component.

The set of all connected components of –S (the complement of S) that have points on the border of an image is called the background. All other components of –S are called holes.

4-connectedness: 4 objects, 1 hole

8-connectedness: 1 object, no hole

To avoid ambiguity, use 4-connectedness for foreground and 8-connectedness for background or vice versa.

Page 17: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

17

Some DefinitionsThe boundary of S is the set of pixels of S that have 4-neighbors in –S. The boundary is denoted by S’.

The interior is the set of pixels of S that are not in its boundary. The interior of S is (S – S’).

Region T surrounds region S (or S is inside T), if any 4-path from any point of S to the border of the picture must intersect T.

original image boundary, interior, surround

Page 18: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

18

Component LabelingComponent labeling is one of the most fundamental operations on binary images.

It is used to distinguish different objects in an image, for example, bacteria in microscopic images.

We find all connected components in an image and assign a unique label to all pixels in the same component.

333

3333

2211

22211

Page 19: September 10, 2013Computer Vision Lecture 3: Binary Image Processing 1Thresholding Here, the right image is created from the left image by thresholding,

September 10, 2013 Computer Vision Lecture 3: Binary Image Processing

19

Component LabelingA simple algorithm for labeling connected components works like this:

1. Scan the image to find an unlabeled 1-pixel and assign it a new label L.

2. Recursively assign a label L to all its 1-neighbors.

3. Stop if there are no more unlabeled 1-pixels.

4. Go to step 1.

However, this algorithm is very inefficient.

Let us develop a more efficient, non-recursive algorithm.