07 binary images
TRANSCRIPT
Binary images
Alain Boucher - IFI
Image processing & Computer visionXử lí ảnh và thị giác máy tính
2
Binary images
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
Several techniques exist to manipulate and process binary images (0:1)
Useful to process images resulting from segmentation
3
Pixel connexity
4-Connexity p and q are 4-connected if q is in N4(p)
8-Connexity p and q are 8-connected if q is in N8(p)
111
111
111
111
111
111
How many objects do you see here?
4
4 or 8 connexity?
Advice: Use different connexities for edges and regions
4-Connexity for regions 8-Connexity for edges
Region : 8-connectedEdge : 4-connected
Region : 4-connectedEdge : 8-connected
5
How to measure distances?
A
B
What is the distance between A and B?
6
Discrete distance between pixels
Distance D4 (Manhattan distance)D4(p,q) = |x-s | + |y-t |
Diamond shape centered on (x,y) Ex: D4 ≤ 2
2
212
21012
212
2
7
Discrete distance between pixels
Distance D8 (chessboard distance)D8(p,q) = maximum (|x-s| , |y-t|)
Square shape centered on (x,y) Ex: D8 ≤ 2
22222
21112
21012
21112
22222
8
Freeman coding
For coding directions in images, we use the Freeman code:
765
0x4
123
Using this, we can code contours (edges) starting from one pixel (top left pixel) and following it clockwise
3
0x2
1
Freeman code in 4-connexity
Freeman code in 8-connexity
9
Contour coding vs connexity
Source : Gonzalez and Woods. Digital Image Processing. Prentice-Hall, 2002.
10
Connected component labeling
Connected component = all adjacent pixels (neighbors) belonging to the same entity (region)
A segmented image is only a map of pixels We wish to give a common tag (value) for each pixels belonging to
the same region/contour We wish to have a different tag for each region/contour
Used in post-segmentation
11
Connected component labeling
← Background← Segmented objects
We loop over all the image to give a unique number (label) for each region
All pixels from the same region must have the same number (label)
12
Connected component labeling
1
First loop over the imageFor each pixel in a region, we set
or the smallest label from its top or left neighbors
or a new label
Loop
Neighbors?X
X
13
Connected component labeling
11
First loop over the imageFor each pixel in a region, we set
or the smallest label from its top or left neighbors
or a new label
Loop
Neighbors?X
X
14
Connected component labeling
2111
First loop over the imageFor each pixel in a region, we set
or the smallest label from its top or left neighbors
or a new label
Loop
Neighbors?X
X
15
Connected component labeling
3111
22111
First loop over the imageFor each pixel in a region, we set
or the smallest label from its top or left neighbors
or a new label
Loop
Neighbors?X
X
16
Connected component labeling
23111
22111
First loop over the imageFor each pixel in a region, we set
or the smallest label from its top or left neighbors
or a new label
Loop
Neighbors?X
X
17
Connected component labeling
55
5555
265555
2
22111
2234111
223111
22111
First loop over the imageFor each pixel in a region, we set
or the smallest label from its top or left neighbors
or a new label
Loop
Neighbors?X
X
18
Connected component labeling
55
5555
265555
2
22111
2234111
223111
22111
Second loop over the imageFor each pixel in a region, we set
the smallest from its own label and the labels from its down and right neighbors
Loop
NeighborsX
XX
19
Connected component labeling
55
5555
225555
2
22111
2234111
223111
22111
Second loop over the imageFor each pixel in a region, we set
the smallestfrom its own label and the labels from its down and right neighbors
Loop
NeighborsX
XX
20
Connected component labeling
55
5555
225555
2
22111
2222111
222111
22111
Second loop over the imageFor each pixel in a region, we set
the smallestfrom its own label and the labels from its down and right neighbors
Loop
NeighborsX
XX
21
Connected component labeling
In two loops, we finished to label all regions
Sometimes, we need more than two loops example: spiral region !
We continue, go and back two ways, until no new change in labels
22
Connected component labeling
It is possible to do only one loop Manage a table of equivalences when 2 different
labels are neighbors
23
Edge labeling
To label edges, we can use the same algorithm We proceed the same way, escept that we use 8-
connexity we compare 4 neighbors instead of 2
Take care: normally the thickness of an edge is only one pixel erase all redondant pixels (non-maxima)
There are other algorithms for edges
?4
321
24
Closing contours
From gradient to contours (edges) The methods for gradient seen in that cours does not
necessarily closed contours Many holes and several isolated segments
We must « close the contours » for obtaining a segmentation equivalent to regions
Several methods exist, but nothing easy
25
Closing contours
Edge thickness Important condition: an
edge must have a thickness of 1 pixel (everywhere)
If the edge is too thick, or if it has many paths, we must follow the line of highest gradient
Source : lagaule.org/downloads/TC3_03_segmentation.ppt
26
Closing contours
Compute and follow the best path in the gradient At the end of edges, we look for the path leading to join
another edge extremity Follow the path of the highest gradient
We can have many possible paths Graphs of path possibilities Choosing paths the shortest / the strongest (gradient)
P0
Pf
edge
Arch of a possible solution
Source : lagaule.org/downloads/TC3_03_segmentation.ppt
27
Closing contours
Hysteresis thresholding Define two thresholds
low threshold: minimum to be an edge high threshold: minimum to be edge of an object
(1) Threshold using the high threshold(2) Add the connected edges higher than the low
threshold
Source : Jérome Vicente. Cours de Traitement d'images. IUSTI. iusti.polytech.univ-mrs.fr/~vicente/
(1) Edges found with the high threshold
(2) Edges added using the low
threshold
28
Morphological operators
Widely used on binary images (mask images) but also on gray level images
Can change the shape (morphology) of objects To clean the result of segmentation
Fill in the holes, eliminate the noise To smooth the result of segmentation
Used in post-segmentation
Main characteristics a structuring element transforms
erosion, dilation, opening (erosion & dilation), closing (dilation & erosion)
29
Morphological operators
Given a binary images with background=0 and object=1
The structrural element « moves » on the object borders (inside and outside) and transform them:
object pixels into background pixels (erosion) background pixels into object pixels (dilation)
Examples of structural elements:
4-Connexity 8-Connexity
There exist other shapes for structural elements, symmetric or not
30
Morphological operators
Erosion If a mask pixel is background (value = 0)
then the central pixel becomes background Dilation
If a mask pixel is object (value > 0)then the central pixel becomes object
Opening Erosion then dilation
Closing Dilation then erosion
31
Erosion
We put the element B on each pixel x of A like convolution
If all pixels of B are onto object pixels (A), then the central pixel belongs to object
otherwise, set to background
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
Structuringelement B
32
Dilation
Moving B onto A, for each pixels of A, check if the intersection (pixels belonging to object) is not empty
If yes, the center of B belongs to the result image
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
Structuringelement B
33
How many objects?
How many objects? 1 or 2 ?
And after one erosion? And after one dilation?
Risk of merging or splitting of objects...
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
34
Example: erosion + dilation
X X X X X X X X X X X XX X X X X X X XX X X X X X X X X X X X
InitialAfter erosion
X After dilation (final)
35
Example of dilation
Source : Gonzalez and Woods. Digital Image Processing. Prentice-Hall, 2002.
36
Erosion - dilation
AvantAprès
AvantAprès
Source : Pascal Bertolino, LIS, www.lis.inpg.fr/pages_perso/bertolino/
structural element
erosion
dilation
beforeafter
beforeafter
37
Opening - closing
Source : Pascal Bertolino, LIS, www.lis.inpg.fr/pages_perso/bertolino/
structural element
opening
closing
38Source : Gonzalez and Woods. Digital Image Processing. Prentice-Hall, 2002.
39
Influence of the structural element
Input imageDilation 4-neighbors Dilation 8-
neighbors
Erosion 4-neighbors Erosion 8-neighbors
4-neighbors 8-neighbors
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
40
Summary example
Input image
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
Erosion Opening
Closing Dilation
41
Morphological gradient
Input image – Erosion image = internal gradient
Dilation image – Input image = External gradient
Internal gradient: inside contour/edge
External gradient: outside contour/edge
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.
42
Morphological gradient
Dilation image – Erosion image = Morphological gradient
Source : Caroline Rougier. Traitement d'images (IFT2730). Univ. de Montréal.