Title: Image processing
1Image processing
Lecture 3 Binary image processing
Dr inz. Wojciech Bieniecki Computer Engineering
Department wbieniec_at_kis.p.lodz.pl http//wbieniec.
kis.p.lodz.pl
2Binary Image Operations
Binary images have 1 bit per pixel
1 object pixel
0 non-object pixel (background pixel)
3Binary image operations
Binary images are obtained from segmentation
procedures such as
Thresholding (binarization at grey-level t)
Edge detection and filling
Region analysis
Binary Image Operations are used to
Correct or improve imperfect segmentation
Analysis of connectivity of components
Object selection using geometric features
4Binary image operations
5Binary images point operations
6Binary images point operations
Each operation is equivalent to the array with 29
512 entries
Examples Erosion, Dilation, Contour extraction,
Remove isolated pixels
7Binary images object operations
Examples skeleton exo-skeleton
propagation anchor-skeleton
It is impossible to state beforehand which pixels
from input image contribute to output No fixed
neighborhood size.
8Objects vs components
The image is an array of pixels
The object is a real thing or phenomenon
There must be a correspondence by segmentation
and binary image processing
8
9Neighborhood
The notation of pixel connectivity describes a
relation between two or more pixels. For two
pixels to be connected they have to fulfill
certain conditions on the pixel brightness and
spatial adjacency.
First, in order for two pixels to be considered
connected, their pixel values must both be from
the same set of values V. For a grayscale image,
V might be any range of graylevels, e.g.
V22,23,...40, for a binary image we simple
have V1.
9
10Neighborhood - connectivity
To formulate the adjacency criterion for
connectivity, we first introduce the notation of
neighborhood. For a pixel p with the coordinates
(x,y) the set of pixels given by
Two pixels p and q, both having values from a set
V are 4-connected if q is from the set N4(p) and
8-connected if q is from N8(p)
General connectivity can either be based on 4- or
8-connectivity. The 4-connectivity is direct.
10
11Path in a digital image
The path from the point p to point q is the
ordered list of unique points. Between all of
these points the relation of neighborhood must be
satisfied
12Pixel connectivity
A pixel p is connected to a pixel q if p is
4-connected to q or if p is 4-connected to a
third pixel which itself is connected to q. Or,
in other words, two pixels q and p are connected
if there is a path from p and q on which each
pixel is 4-connected to the next one.
A set of pixels in an image which are all
connected to each other is called a connected
component.
Finding all connected components in an image and
marking each of them with a distinctive label is
called connected component labeling.
12
13Pixel connectivity
How many connected components are there in the
figure?
Is there a unique path between p and q with N8 ?
13
14The paradox of the square grid
How many objects? And how many background
components?
Both N4 and N8 do not fulfil the Jordan Curve
Theorem (Jordan-Brouwer)
If J is a simple closed curve in R2 than R2 J
has two components (inside and outside) with J
the boundary of each
What is the source of trouble?
In the continous geometry the point p belongs to
the border of the region if every (even small)
round neighborhood contains both points that
belong to the region and do not belong.
It is not possible to define the smallest round
neighborhood in a discrete square space
15The paradox of the square grid
How to solve the problem?
Lets use N8 for points of the curve and N4 for
points of the background.
The drawback The points of the objects and the
background are not treated symmetrically
16The paradox of the square grid
Foreground connectivity
N4
N8
1,2
N4
3,2
1,2
Background connectivity
?
N8
1,1
3,1
3,1
17The paradox another solution
The use of hexagonal grid and N6 neighborhood
The advantage There are only one type of the
connectivity (all connections are direct) All
connections have the same distance
The drawback The lack of acquisition appliances
The drawback lack of symmetry
18The contour
n-contour of the region R is the set of all
points that have a N8 neighbor that does not
belong to R
b-contour of the region R is the set of all
points that have a N4 neighbor that does not
belong to R
19The contour and the edge
CONTOUR is the set of points
EDGE is the set of limits between points.
In fact in discrete geometry the edge does not
exist.
20Curve representation
Continuous geometry A curve is a non-empty set
which has an empty interior all its points
belong to the boundary
Discrete geometry A curve is a set of pixels, if
all its pixels belong to the contour.
Note this definition allows two-pixel thick
curves
21Solid region
A solid region R is a connected compontent which
- Has at least five points (a contour plus interior)
- Its contour is a simple path (does not cross)
- The difference between the region and its contour
is connected
Which region is solid?
22Contour tracing
We introduce the neighbor enumeration in N8
neighborhood
The procedure TraceContour(R, q)
R the region (connected component)
q?R the starting point
p q the current point
d 6 the current direction (initially south)
23Countour tracing
24Contour tracing
25Contour representation
Freeman chain code encodes the list of contour
points
Fixed or relative
Examples of definition for N8 connectivity
26Freeman chain code example
6,5, 4, 0, 7, 0, 0, 2, 1, 3, 3, 4, 4, 7
13
12
14
1
11
2
10
4
9
3-5
6, -1, -1 -4 -1, 1, 0, 2, -1, 2, 0, 1, 0, -3
6
7
8
27Binary image indexation (labeling)
Recursive algorithm
Non-recursive (iterative) algorithm
28Recursive labeling
N4 connectivity!
29Non-recursive labeling
After completing the scan, the equivalent label
pairs are sorted into equivalence classes and a
unique label is assigned to each class. As a
final step, a second scan is made through the
image, during which each label is replaced by the
label assigned to its equivalence classes.
30Mathematical morphology
Mathematical morphology shape processing
A wide range of operators to image processing,
all based around a few simple mathematical
concepts from set theory.
The operators are particularly useful for the
analysis of binary images and common usages
include edge detection, noise removal, image
enhancement and image segmentation.
- The opeartors
- Translation
- Minkowski sum
- Minkowski difference
31Image algebra definitions
Translation
b(x,y)
32Image algebra definitions
The set complement
The symmetrical reflection
The Minkowski difference
The Minkowski sum
Theorem the duality of Minkowski addition and
subtraction
33Dilation in continuous space
Let A,B?R2. We define the dilation of A by B as
Minkowski sum
B is a structuring element
34Erosion in continuous space
Let A,B?R2. We define the dilation of A by B as
Minkowski difference
B is a structuring element
35Dilation and erosion examples
Erosion
Dilation
36Dilation and erosion properties
Translation invariance
Monotonicity
Dilation - extensiveness
erosion anti-extensivenes only if (0,0)?B
37Open and Close
The opening of set A by structuring element B is
defined as the combinantion of erosion and
dilation
The closing of set A by structuring element B is
defined as the combination of dilation and
erosion
In the first phase we use reflection of the set B
38Open and Close examples
39Open and Close properties
Invariance to translation
Monotonicity
Closing - extensiveness
Idempotence repetition of the operation does
not change the result
40The morphological filter
- The morphological filter is a function that
- is monotonical
- is invariant to translation
Matheron theorem
Every morphological filter is a sum of some
erosions
Every morphological filter is an intersection of
some dilations
41The morphological filter
42Mathematical morphology for binary images
We define erosion for binary image as
We define dilation for binary image as
43Dilation for binary images
Expands each object pixel with its N4 (N8)
neighbors
44Erosion for binary images
Removes each object pixel having a neighbor in
the background.
Yields all pixels whose N4 (N8) neighbors are all
object pixels.
45Erosion and dilation algorithms
Which one is dilation, which erosion?
What is the structuring element here?
Why does the loop start from 1?
46Dilation and erosion duality
An 8-connected dilation of the object(s)
corresponds to an 8-connected erosion of the
background, and vice-versa.
The same holds for the 4-connected case.
47Binary image - opening
An opening consists of a number of erosions
followed by the same number of dilations.
Applications separation of connected objects
removing small objects (size discrimination)
48Binary image - closing
A closing consists of a number of dilations
followed by the same number of erosions.
Applications connection of disconnected object
parts closing of holes contour smoothing
49Opening and closing duality
50Contour extraction (without tracing)
As you remember, the contour is the set of object
pixels that are connected to the background
51Conditional erosion
A conditional erosion is an erosion under one or
more of the following conditions
W1 Do not remove a single pixel
and rotated
W2 Do not break the connectivity
and rotated
W3 Do not remove an end-pixel
The combination of conditions
W1 Reduction of the object to a single point
(seed point)
W2 Find the holes
W1 AND W2 Skeleton without end-pixel condition
W1 AND W2 AND W3 Skeleton with end-pixel
condition
52Conditional erosion object to point reduction
W1 Do not remove a single pixel
but not always one point per object ?
53Conditional erosion find holes
W2 Do not break the connectivity
54Conditional erosion skeleton 1
W1 AND W2 Do not remove a single pixel and do
not break connectivity - skeleton without
end-pixel condition
55Conditional erosion skeleton 2
W1 AND W2 AND W3 Do not remove a single pixel
and do not break connectivity and do not remove
an end-pixel. Skeleton with end-pixel condition.
56Skeleton
The skeleton of an object is a line connecting
points midway between the boundaries. A skeleton
has the same connectedness (topology) as the
original object.
The requirements for skeleton (for binary image)
1. has the same connectedness as the original
object, so it can be used as an representation of
the object.
2. is one pixel thick, so crossings and end
points can be found in a 3x3 neighborhood.
3. preserves isolated pixels and endpoints, so
long objects have long skeletons.
4. is in the middle of the object, so it can be
used as an object 'axis'.
57Skeleton in a discrete space
Sometimes we cannot satisfy all the conditions ?
Conflict between one pixel thick and in the
middle of the object
Conflict between same connectedness and one
pixel thick
58Skeleton - algorithms
Many different skeleton algorithms exist, and
also a variety of versions of the same
algorithm They differ in
handling conflicting wishes
noise sensitivity
'cleanness' of the result
sensitivity to details of the object contours
Well-known algorithms
the Hilditch algorithm for sequential machines
the algorithm by Arcelli and Levialdi for
parallel machines
59Implementationof the morphology filters
Define the matrix of weights
and calculate the sum to obtain the pattern
W69
W321
W65
W129
W73
W263
A current neighborhood of the examined pixel is
ANDed with the pattern weight
60Morphology filters salt and pepper
SALT isolated 0 points in the 1 neighborhood
PEPPER isolated 1 points in the 0 neighborhood
61Salt and pepper removal
62Conditional dilation exo-skeleton
The exo-skeleton is a dilation under the
condition Do not connect disconnected components.
Similar result by inverting the original image
and skeletonize it
However Most skeleton programs can only give an
8-connected result, i.e., areas remain 8-connected
63Propagation
Propagation is a dyadic conditional
dilation Dilate a (seed) image iteratively
within a given (object) mask until idempotence.
Seed find holes
Mask original image
S0 seed image M mask image
Propagated image
64Propagation example find nuts
Mask application
Conditional erosion
Propagation
65Propagation example filling holes
Inversion as the mask
Mask application
Propagation
Inversion
66Propagation example remove border objects
Mask application
Propagation
Original XOR Propagated
67Touching objects example
I2E(I)
I3Exoskeleton(I2)
I4NOT(I3)
I5 I AND I4
68Hit miss transform
HMT is a natural operation to select out pixels
that have certain geometric properties such as
- corner points
- isolated points
- boundary points.
In addition, the HMT performs
- template matching
- thinning
- thickening
- centering.
69Hit miss transform
Since an erosion or a dilation can be interpreted
as special cases of the hit-and-miss transform,
the HMT is considered to be the most general
image transform in mathematical morphology. This
transform is often viewed as the universal
morphological transformation upon which
mathematical morphology is based.
Let B (D, E) be a pair of structuring elements.
Then the hit-and-miss transform of the set A is
given by the expression
In practice D ? E ?.
Note, that, when E ?
Since a dilation can be obtained from an erosion
via the duality
a dilation is also a special case of the HMT.
70HMT find squares
71HMT Template representation
72HMT morphological filters
Isolated points detection
Erosion
end points detection
corner detection
Crossings detection
73Golays alphabet
symbol
Structuring element
erosion
dilation
hmt
C
Convex hull
D
Marker or centroid
Convex hull approx. Dc
E
pruning
SKIZ (Lc and next Ec)
end point detection
F
-
Detection of triple (cross) points
H
Edge detection
erosion
74Golays alphabet
symbol
Structuring element
erosion
dilation
hmt
I
Isolated points detection
L
skeleton
SKIZ (Lc and next Ec)
M
skeleton
Dilation of isolated points(Mc)
R
Line erosion
Line dilation (Rc)