Binary image operations pine spruce friday & monday GW 2.5, - - PDF document

binary image operations
SMART_READER_LITE
LIVE PREVIEW

Binary image operations pine spruce friday & monday GW 2.5, - - PDF document

Binary image operations pine spruce friday & monday GW 2.5, 11.1.1, 11.1.5, 11.2.2, 11.4 different objects different shape different texture stina@cb.uu.se recognition and interpretation using computerized image analysis Friday 22/3


slide-1
SLIDE 1

1

Binary image operations

friday & monday GW 2.5, 11.1.1, 11.1.5, 11.2.2, 11.4 stina@cb.uu.se pine spruce different objects different shape different texture recognition and interpretation using computerized image analysis

Friday 22/3

  • connectedness

– neighbourhood relations – connected components

  • identification of connected components

– labelling

  • measuring distances in an image

– distance transforms

partitioning of 2D space

square rectangular (non-square) hexagonal

slide-2
SLIDE 2

2

neighbours

6-neighbours (hexagonal) 4-neighbours 8-neighbours (square)

  • neighbourhood
  • neighbours of a pixel

– horizontal/vertical, edge, kant – diagonal, point, punkt, hörn, vertex

neighbourhood

pixel p with coordinates (x,y) N4(p): 4-neighbourhood

( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , ) ( , ) x y x y x y x y x y x y x y x y − − − + − − + − + + + + 1 1 1 1 1 1 1 1 1 1 1 1 ( , ) ( , ) ( , ) ( , ) x y x y x y x y − − + + 1 1 1 1

N8(p): 8-neighbourhood

similarity

binary (bi-level!) images: only 0s and 1s

  • bject/region (1) and background (0)
  • bject O – all pixels with a certain ”similarity”

example: grey-level in V={20,21,…,30}

V – set of grey-levels

O O

adjacency

  • 4-adjacent

– p & q belongs to O and q is in N4(p)

  • 8-adjacent

– p & q belongs to O and q are in N8(p)

  • m-adjacent (mix)

– q is in N4(p) – q is a point neighbour AND p and q have no edge neighbours in common

slide-3
SLIDE 3

3

path

path between two pixels p=(x,y) and q=(s,t) p and q are connected if there is a path between p and q (x,y)=(x0,y0) (xn,yn)=(s,t) (x1,y1) (xn-1,yn-1)

adjacent adjacent

... 4-path 8-path

connected component

  • a pixel p belongs to the object O
  • connected component in O containing p:

– all pixels that are connected with p

  • every two pixels in a connected

component are connected

if O consists of only one connected component connected set

connected component labelling

  • every connected component is given an

identity

  • represented by a grey-level image

– label image – grey-level for each pixel = identity

  • connected components are 4- or 8-

connected

slide-4
SLIDE 4

4

labelling using FloodFill

  • initially all pixel in the label image = 0
  • given the binary image

– find a pixel in the first connected component – fill the first connected component with label 1 – look for the next connected component pixel in the binary image having 0 in the label image – fill the next connected component – ...

example of FloodFill labelling using a two scan algorithm

  • initially

– object pixels = 255 – background pixels = 0

  • if object pixel A<255

– if object pixel B or C<255

  • A=min(B,C)

– otherwise

  • A=new label
  • equivalence table

updated

  • change all labels in

the equivalence table to the smallest

4-connectedness 8-connectedness

example of two scan algorithm

scan 1 scan 2

slide-5
SLIDE 5

5

label image in IMP

connectivity – object and background

  • connected components of the
  • bject (Oi)
  • the object O is the union of all

Oi

  • the complement of O (OC)

consists of

– background

  • subset of OC connected to the border
  • f the image

– holes

  • remaining part of OC

connectivity paradox

a closed curve divides the plane into two (distinct) connected components how many background components?!?

using connected component labelling

  • removal of connected components touching the

image border

– label – two scans

  • 1. store label for object pixel at image border
  • 2. if pixel=stored value set to 0
  • fill holes in the object

– label the inverse image – remove connected components touching the image border – holes + original image

slide-6
SLIDE 6

6

filling holes

holes

  • riginal image

labelled inverse image remove connected components at image border

  • utput

inverse image

  • riginal image

using connected component labelling

  • count number of connected components
  • extract information for a specific

connected component

– size – compactness – ...

boundary, border, contour, edge, ...

consider an object O (connected set) boundary = the set of pixels with one or more neighbours not in O NOTE! connectivity used for object/background in case 8-connected object: boundary = pixels with 4-neighbour in background

distances

length, straightness, ... thickness

slide-7
SLIDE 7

7

measuring distances in an image

  • distance functions: x=(x1,x2),y=(y1,y2)∈Z

Z2

– dE(x,y)=||x-y||2={(x1-y1)2+(x2-y2)2} l2 – dcity(x,y)=||x-y||1=|x1-y1|+|x2-y2| l1 – dchess(x,y)=||x-y||=max(|x1-y1|, |x2-y2|) l

  • intuitively: Euclidean distance
  • often represented by a distance transform

– each object pixel is labelled with distance to closest voxel in background

distance

Euclidean city block, number of steps is 4-path chessboard, number of steps in 8-path 7 3

2 2

+ 7 3 + 3 4 +

metric – desired property

  • DEFINITION. A function d:Z2Z2 is a metric if and only if

for any points (=pixels) x,y,z∈Z2 the following holds:

  • d(x,y)0 and d(x,y)=0 only when x=y
  • d(x,y)=d(y,x)
  • d(x,z)d(x,y)+d(x,z)

positive definite symmetric fulfils -inequality

local vs. global

known distance from A A unknown distance from A l1 l2 l

slide-8
SLIDE 8

8

simple distance

  • number of steps in a minimal path
  • city block: 4-connectedness

– dcity(x,y)=||x-y||1=|x1-y1|+|x2-y2| l1

  • chessboard: 8-connectedness

– dchess(x,y)=||x-y||=max(|x1-y1|, |x2-y2|) l

  • mix octagonal distance

introduced by Rosenfeld and Pfaltz in 1966 & 1968

distance transform (DT)

  • representation of distances in an image
  • grey-level image

– replica of binary image – each object pixel is labelled with the distance to its closest pixel in the background

  • from binary image to DT by a distance

transformation

  • DT gives important information

examples of distance transforms

city block chess board

DTs with numbers

1 1 2 1 1 2 2 1 1 2 2 3 1 1 2 2 3 3 1 1 2 2 3 3 4 1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4 5 1 2 2 3 3 4 4 5 5 1 2 3 3 4 4 5 5 6 1 2 3 4 4 5 5 6 6 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

city block chess board

slide-9
SLIDE 9

9

computing DT

  • initially: object = , background = 0
  • one forward and one backward scan
  • current distance label of a pixel is

compared to the distance labels for its already visited neighbours

  • update if shorter distance

p city block p chess board

city block

forward backward

chess board

forward backward

comparison: discs

( )

{ }

B p Z d p p r

n

= ∈ ≤ ; ,

a disc is defined by centre pixel (p0) and radius (r): all pixels closer than r to p0 Euclidean city block chess board

slide-10
SLIDE 10

10

simple distance transforms

city-block chess board

  • ctagonal

(diagonal only every even) distance=number of steps dist=11 dist=7 dist=8

weighted distance transforms

  • use length of shortest path
  • assign weights to steps in path

corresponding to neighbourhood relation

– a for steps in edge directions – b for steps in point directions

more or less: city block chess board

b a,

1 , 1 2 , 1

b a b a p a b a b

by Rutovitz & Hilditch 1969 later Borgefors 1984/86 chamfering

algorithm for weighted DTs

weights

( ) { }

w i j i j , , , , , ∈ −1 0 1

( )

j i,

pixel used in forward (fwd) and backward (bwd) scan

( )

j i I ,

image of size n x n for y=1 to n for x=1 to n ( )

( )

( ) ( ) ( )

I x y I x i y j w i j

i j fwd

, min , ,

,

= + + +

for y=n downto 1 for x=n downto 1 ( )

( )

( ) ( )

( )

I x y I x i y j w i j

i j bwd

, min , ,

,

= + + +

+a +b +a +b +0 +b +a +b +a

4 , 3

forward backward

slide-11
SLIDE 11

11

DTs in IMP

  • riginal

region of interst DT (<3,4>)

using a larger neighbourhood

even better approximation using knight step (c)

b c a c a c b a b c a a p a a a b a b c b c a c b 2 2 2 2 2 2 2 2

11 , 7 , 5

gives maximum difference with Euclidean distance of 2%

discs

4 , 3 city block Euclidean 11 , 7 , 5

maximal difference – Euclidean

4 , 3 11 , 7 , 5

diff b a 7.3% 11 8 8.1% 4 3 13.4% 3 2 4.5% bopt aopt 41.4% 1 1 58.6% 2 1 9.0% 1.4142 1 diff c b a 1.4% copt bopt aopt 2.0% 11 7 5 2.8% 2.236 1 1.414 2 1

slide-12
SLIDE 12

12

a bit strange...

5 7 5 7 5 7 5 7 5 7 5 7 6 3 5 3 5 3 5 3 6 5 7 4 5 2 4 2 4 2 5 4 7 5 6 3 4 1 3 1 4 3 6 5 7 4 5 2 3 3 2 5 4 7 5 6 3 4 1 3 1 4 3 6 5 7 4 5 2 4 2 4 2 5 4 7 5 6 3 5 3 5 3 5 3 6 5 7 4 6 4 6 4 6 4 6 4 7 5 7 5 7 5 7 5 7 5 7 5

1 , 3

disc with radius = 5

DT as grey-level landscape 8SED

  • 2D EDT
  • Sequential Euclidean Distance (using 8

neighbours)

  • each pixel: vij=(vx,vy)

mask 1a 0,0 1,0 mask 1b 0,0 1,0 mask 2a 1,1 0,1 1,1 1,0 0,0 1,1 0,1 1,1 mask 2b 1,0 0,0 Danielsson 1980

Errors in (”fast”) sequential EDTs

  • 4 (3) scans with simple operations is not

enough

  • max error in 8SED:

0.090 pixel distances

slide-13
SLIDE 13

13

constrained DT

  • shortest path,

avoiding obstacles

  • special case: DT of

line patterns

  • same algorithm but

more scans necessary

reverse distance transform

  • start from seed pixels
  • propagate decreasing

distances

  • represent object by

just a few (distance labelled) pixels

1 2 3 2 1 3 4 5 6 5 4 3 1 4 7 8 9 8 7 4 1 2 5 8 11 12 11 8 5 2 3 6 9 12 15 12 9 6 3 2 5 8 11 12 11 8 5 2 1 4 7 8 9 8 7 4 1 3 4 5 6 5 4 3 1 2 3 2 1

algorithm for reverse DTs

weights

( ) { }

w i j i j , , , , , ∈ −1 0 1

( )

j i,

pixel used in forward (fwd) and backward (bwd) scan

( )

j i I ,

image of size n x n for y=1 to n for x=1 to n ( )

( )

( ) ( ) ( )

j i w j y i x I y x I

fwd j i

, , min ,

,

− + + =

for y=n downto 1 for x=n downto 1

( )

( )

( ) ( ) ( )

j i w j y i x I y x I

bwd j i

, , min ,

,

− + + =

  • a
  • b
  • a
  • b
  • b
  • a
  • b
  • a

Binary image operations ... continuing

friday & monday GW 2.5, 11.1.1, 11.1.5, 11.2.2, 11.

slide-14
SLIDE 14

14

4 , 3

distance by length of shortest path

  • steps in edge direction are weighted a(=3)
  • steps in point direction are weighted b(=4)

24 23 20 18 15 12 9 6 3 23 20 19 16 15 12 9 6 3 20 19 16 15 12 11 8 6 3 19 16 15 12 11 8 7 4 3 16 15 12 11 8 7 4 3 15 12 11 8 7 4 3 12 11 8 7 4 3 11 8 7 4 3 8 7 4 3 7 4 3

distance transform by two-scan algorithm!

Monday 25/3

  • shape description, simplification,

representation

  • application of distance transforms

– path planning – matching – skeletonization

  • chain code

shortest path between two pixels

  • compute DT: distances from pixel p0
  • search for pn in direction of max gradient
  • constrained DT in case of obstacles

( )

( )

j k j i j

w n p n grad − =

n n n n p n n n n

i 4 3 2 5 1 6 7 8

for path planning

  • bstacle

p0 constrained distance transform

slide-15
SLIDE 15

15

⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 19 16 13 10 7 4 3 4 12 9 6 3 3 13 10 7 4 3 4 17 14 11 18 15 14 19 22 23 25 26 35 32 29 28 29 36 33 32 31 32 33

constrained distance transform p0

  • bstacles

( )

( )

j k j i j

w n p n grad − =

climbing mountains using steepest path

matchning

  • find unknown objects in the image

– image to find objects or pattern – look for similar/equal objects/patterns in other images

  • part of image understanding
  • ... also later ...

matching by correlation

  • find position that gives highest correlation

with sub image

slide-16
SLIDE 16

16

hierarchical chamfer matching algorithm (HCMA)

  • match set of feature points to similar points in an

image

– often edge!

  • edge image distance transform
  • project template into image
  • root mean square for ”hits” distance
  • move template to minimize distance

– 0 means perfect match!

  • resolution pyramid hierarchic

1.85 1.98 1.38 1.07 2.49

thickness measurements

highest distance label in object gives maximum thickness

pixels as centres of discs

distance labels can be interpreted as centres of discs with radius = distance label, fully enclosed in the object chess board

slide-17
SLIDE 17

17

centres of maximal discs

if not completely covered by any other disc chess board

centres of maximal discs (CMD)

  • can be identified on the distance transform
  • union of all CMDs = object

CMDs för cityblock

<3,4> <5,7,11> cityblock chessboard Euklidisk

OBS! cityblock

  • centres of maximal discs

(weighted DT!)

  • A pixel is a centre of maximal disc if it is a

”local maximum” (OBS! local distance)

for pixel in a-b WDT labelled v: edge neighbours < v+a point neighbours < v+b for city-block: edge neighbours have lower or equal label for chessboard: neighbour have lower or equal label

slide-18
SLIDE 18

18

centres of maximal discs (Euclidean DT!)

  • not enough to investigate labels of

neighbours

  • problems occur very seldom
  • maximal disc: not covered by any other

single disc IN ITS 3x3 NEIGHBOURHOOD

  • simple label comparisions not possible:

use look-up tables

disc 1 covered by disc 2 (horiz.) & disc 4 (diag.) disc 2 covered by disc 5 (horiz.) & disc 8 (diag.) disc 4 covered by disc 8 (horiz.) & disc 9 (diag.)

complete description by CMDs

  • bject can be represented by its CMDs

use reverse DT to recover!

  • bject
  • bject = grey

CMDs = black reverse DT

skeletonization

  • represent a 2D object with a 1D curve
  • iterated removal of border pixels

– change object pixels to background pixels

  • wanted

– thin – topologically equivalent – centred – reversible

slide-19
SLIDE 19

19

simple pixels

pixels that can be removed without altering topology:

  • the number of object components and
  • the number of background components

are the same before and after removal not simple simple not simple (4) simple (8)

decide if simple or not

  • masks

– 3x3 hit or miss configurations

  • crossing numbers

– for 4- or 8-connectedness (Rutovitz/Hilditch) – if simple: X = 2 (X4) , 1 (X8)

  • =

+

= − =

8 1 1 9 1 4

|, |

i i i

n n n n X n n n n p n n n n

i 4 3 2 5 1 6 7 8

( )

  • =

+ −

  • =

= = = =

4 1 1 2 2 1 2 8

  • therwise

1

  • r

1 and if 1 ,

i i i i i i

n n n b b X

thinning

  • removal of border

pixels

  • preserve topology
  • do not care about

reversibility!

skeletonization using iterative thinning

  • compute distance transform
  • remove border after border (iteration

number from distance labels) only if

– simple pixel – not centre of maximal disc

  • number of iterations – dependent on

thickness!

slide-20
SLIDE 20

20

  • bject

CMDs skeleton

skeletonization using path growing

  • compute distance transform
  • detect centres of maximal discs
  • connect CMDs by path growing on DT

– start from each CMD – walk in direction of max gradient

  • FAST!

( )

( )

j k j i j

w n p n grad − =

n n n n p n n n n

i 4 3 2 5 1 6 7 8

skeletons using different DTs

city block chess board

4 , 3 11 , 7 , 5

Euclidean

use of skeletonization

  • compression
  • ”travel” along elongated object
  • thickness measurements
  • exoskeleton

– organization (of cells) – find location of (cell) wall

slide-21
SLIDE 21

21

Dirichlet tesselation

  • seeds: pixels p1, p2, p3, .... (or sets of

pixels)

  • associate a region to each pi closer to pi

than to any other pj, j≠i

  • simple approach:

– label all pi – propagate label together with distance information

example of Dirichlet tesselations

Voronoï diagram = edges between the regions in the tesselation city block chess board & Euclidean

4 , 3

chain coding

  • by Herbert Freeman (1961 & 1974)
  • boundary as a sequence of straight lines
  • 4- or 8-connectedness

boundary, border, contour, edge, ...

consider an object O (connected set) boundary = the set of pixels with one or more neighbours not in O NOTE! connectivity used for object/background in case 8-connected object: boundary = pixels with 4-neighbour in background REMINDER!

slide-22
SLIDE 22

22

example of chain coding

4-connectedness 8-connectedness

problems with chain coding

  • long code
  • dependent on

– scale – starting point – rotation

  • a small change in the boundary (noise or

bad segmentation) can generate a chain code that does not reflect the shape of the

  • bject

more stable

  • use different scale
  • starting point

– treat as a circular sequence – define as starting point, the point giving the least magnitude

  • rotation

– use difference code

codes from different starting points

A B

1 2 1 2 2 3 2 3 3 3 1 1 Bx 2 3 2 3 3 3 1 1 1 2 1 2 Bo 1 1 1 2 1 2 2 3 2 3 3 3 B• 1 1 3 3 3 4 5 7 7 5 5 5 7 1 1 Ax 3 4 5 7 7 5 5 5 7 1 1 1 1 3 3 Ao 1 1 1 1 3 3 3 4 5 7 7 5 5 5 7 A•

slide-23
SLIDE 23

23

editing

  • straighten out jagged boundary

– replace 0710 by 0000

shape number

  • object descriptor by chain coded edge
  • difference code
  • starting point giving least magnitude
  • number of digits gives the order

rotation independent & unique ... ... but dependent on orientation of grid

shape numbers of order 8

3 3 3 3 3 3 3 3 1 2 3

  • rder 4

shape no. difference chain code

  • rder 6

3 3 3 3 3 3 3 3 1 2 2 3 3 3 3 3 3 3 3 3 1 1 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 2 3 3 3 1 3 3 3 3 3 3 1 3 3 1 1 2 2 3 3

  • rder 8

basic rectangle

  • diameter for a boundary B is defined as

diam(B)=max(D(pi,pj)), pi,pj∈B

– length – orientation

  • diameter defines major axis
  • minor axis perpendicular to major axis
  • basic rectangle – minimal enclosing

rectangle using minor & major

slide-24
SLIDE 24

24

shape number – using basic rectangle

  • shape order n
  • choose rectangle of order n best

approximating the basic rectangle

  • the rectangle gives gridsize

– n=12: 2×4, 3×3, 1×5

  • a unique shape number

GW Fig 11.12

principle component analysis

  • boundary points as 2D

vectors

– (a,b)

  • a – x-coordinate
  • b – y-coordinate
  • mean vector and

covariance matrix

  • find eigenvectors e1 and e2
  • rotate

summary

  • distance transforms
  • various applications of distance transforms
  • chain coding

representation description analysis