lecture #18engr.case.edu/merat_francis/eecs490f07/lectures/lecture18.pdf · eecs490: digital image...

34
EECS490: Digital Image Processing Lecture #18 Connectivity: convex hull, thinning, thickening, skeletons, end point location Geodesic dilation and erosion Morphological reconstruction Automated hole filling, edge object removal Summary of binary morphology Morphological operations in MATLAB Gray scale morphology: image functions and SE’s Basic gray scale operations: erosion, dilation, opening, closing Advanced operations: smoothing, gradient, top-ha

Upload: others

Post on 04-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Lecture #18

• Connectivity: convex hull, thinning, thickening,skeletons, end point location

• Geodesic dilation and erosion

• Morphological reconstruction

• Automated hole filling, edge object removal

• Summary of binary morphology

• Morphological operations in MATLAB

• Gray scale morphology: image functions and SE’s

• Basic gray scale operations: erosion, dilation,opening, closing

• Advanced operations: smoothing, gradient, top-ha

Page 2: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Connectivity

© 2002 R. C. Gonzalez & R. E. Woods

The convex hull built objects up.We use a thinning operator basedupon 8-connectivity to reduceobjects to their basic structure.

Structuring elements. X’s indicate “don’t cares”.

1

1

1

11

Basically, if thestructuring elementmatches we remove thatpixel. In this case of 61’s B1 matches so weremove the center pixel.

A⊕B=A-(A B) =A (A B)C

1

Converted to m-connectivity

Page 3: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Connectivity

© 2002 R. C. Gonzalez & R. E. Woods

Thickening is the dual of thinning. The result of thinning thecomplement of A is the boundary of the thickened object.Thickening can result in some disconnected points which need tobe removed.

A 1. Complement A to get AC

2. Thin AC 3. Complement thinned AC

4. Remove unconnected points toget thickened object

Page 4: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Skeletons

© 2002 R. C. Gonzalez & R. E. Woods

A skeleton is the set of maximumdisks which fit inside A andtouch the boundary of A in twoor more places.

This is theunion of allskeletonsegments

S A( ) = Sk A( )k=0

K

Sk A( ) = A kB( ) A kB( ) B

Mathematically, a skeleton canbe written as a series ofopenings and closing where kindicates k successive erosionsof A by B

Note that this maximum disk(which is smaller) also touchesthe boundary at two points.

Page 5: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Skeletons

© 2002 R. C. Gonzalez & R. E. Woods 1. S

ucce

ssiv

ely

erod

e ob

ject

2. O

pen

each

eros

ion

wit

h B

to c

ompa

ct s

et

3. S

ubtr

act

from

kB

to

get

skle

ton

Sk

4. U

nion

of

all

skel

eton

s

5. D

ilat

e ea

chsk

elet

on S

k b

y B

6. U

nion

the

dilat

ions

to

reco

ver

the

orig

inal

obje

ct

K=0 row: no erosions ordilations since k=0

k=1 row: one erosion ordilation

k=2 row: two successiveerosions or dilations

Stops at k=2 since anothererosion would simply givethe empty set.

Originalobject

Reconstructedobject

Strick skeletoningdoes not guaranteeconnectivity

Page 6: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Connectivity

© 2002 R. C. Gonzalez & R. E. Woods

Want to remove this

{B} specifies usingB1 to B8 in sequence

2. Identify end pointsby matching

X2 = X1«B

k( )k=1

8X1 = A B{ }

3. Dilation from endpoints conditioned onA

X3 = X2 H( ) A

H is a 3x3 of 1’s

4. Union of thinnedand conditionallydilated imageseliminates parasiticbranches

X4 = X1 X3

1. Thin using Bi

Page 7: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Geodesic Dilation

1. Dilatemarker image Fby structuringelement B

2. Intersect with mask Gto form the geodesicdilation DG

(1)(F)

The marker imagecontains thestarting point(s)

The maskconstrains thetransformation

The structuringelement definesthe connectivity

This operation can beperformed iterativelywith the iterationdetermined by thesuperscript.

Page 8: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Geodesic ErosionErode marker image F bystructuring element B

Union with mask G toform geodesic erosionEG

(1)(F)

The geodesicerosion is similar tothe geodesicdilation in that it isa erosion of amarker which isconstrained by amask

This operation can beperformed iterativelywith the iterationdetermined by thesuperscript.

Page 9: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Morphological Reconstruction

Dilate DG(1)(F) by B;AND

with mask G to get DG(2)(F)

Dilate DG(2)(F) by B; AND

with mask G to get DG(3)(F)

Dilate DG(3)(F) by B; AND

with mask G to get DG(4)(F)

When DG(j+1)(F)= DG

(j)(F) we call this RGD(F) the

reconstruction of the mask by dilation

Geodesic dilation can be iterated until the image does not change. Theresulting image is called the reconstruction of the mask by dilation.

Page 10: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Locating Tall Characters

Original image A;average characterheight is 50 pixels

1. Erosion of A with astructuring element ofsize 51x1 to locate tallletters. This is themask F

Opening of A with astructuring element ofsize 51x1 simply givesthe vertical stroke ofeach tall character

Opening byreconstruction of Fwith a structuringelement of size 51x1

Goal is to find characters with tall, vertical strokes so wechoose a structuring element of 51x1

OR

n( ) F( ) = RFD FsnB[ ]

Do n erosions of F byB followed bymorphologicalreconstruction bydilation. This exampleis for n=1

Morphological reconstruction is a very powerfultechnique for finding complete objects in an image.

Page 11: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Hole Filling

The goal of this example is to fill all holes in a simple image.

Ori

gina

l im

age

1. C

ompl

emen

t or

igin

alim

age

to b

uild

a w

all of

1’s

arou

nd h

ole

2. C

onst

ruct

mar

ker

imag

e F

(x,y

) :

1-I(

x,y

)on

the

imag

e bor

der

and 0

eve

ryw

her

e el

se.

3. D

ilat

e m

arke

r F

wit

h3

x3

SE

of

all 1’

s.S

tart

s ou

tsid

e an

dw

orks

inw

ard.

4. G

eodes

ic d

ilat

ion

ofm

arke

r im

age

F u

sing

com

plem

ent

Ic

as m

ask

5. R

epea

t dilat

ion

unti

lno

chan

ge in

resu

lt s

ost

op a

nd c

ompl

emen

t.H

oles

are

fille

d.

6. I

nter

sect

wit

hco

mpl

emen

t of

im

age

tolo

cate

hol

es t

hat

wer

efi

lled.

Page 12: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Morphological Reconstruction

Original image Complement image

Marker image Hole filling using geodesicdilation

f x, y( ) =1 I x, y( ) if x, y( ) is on image border

0 elsewhere

This is an example of applying the hole filling algorithm to amore complex image.

Page 13: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Morphological Reconstruction

Marker image

f x, y( ) =I x, y( ) if x, y( ) is on image border

0 elsewhere

Compute morphologicalreconstruction RI

D(F) usingmarker image to identify objectson edge.

Remove edge objects by simplesubtraction X=I- RI

D(F)

This is an example of removing objects on the edge of images.

Page 14: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Basic Binary Structuring Elements

Page 15: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Basic Morphological Operations

Page 16: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Page 17: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Page 18: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

MATLAB/Image Processing Toolbox

MATLAB morphological operations

>> f=imread(‘Fig0911(a)(fingerprint_cleaned).tif’);% load in noisy fingerprint>> se=strel(‘square’,3); % 3x3 structuring element>> fo=imopen(f,se); % open image>> imshow(f), figure, imshow(fo) % show both images

>> foc=imclose(fo,se); % now close the image>> figure, imshow(foc) % show both images

% strel can be used to make structuring elements of common shapes as% well as completely arbitrary shapes

% imopen and imclose implement opening and closing% imerode and imdilate implement erosion and dilation

SEE GWE, Section 9.2 Erosion and DilationGWE, Section 9.3 Combining Erosion and Dilation

Page 19: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

MATLAB/Image Processing Toolbox

MATLAB morphological operations

>> h=imread(‘fingerprint_clean.tif’);% load in fingerprint>> h1=bwmorph(f,’thin’,1); % apply thinning once>> h2=bwmorph(f,’thin’,2); % apply thinning twice>> imshow(h1), figure, imshow(h2) % show both images% you can actually apply thinning ‘inf’ times

% the bwmorph function can be used to implement erode, dilate,% open, close, shrink, skeleton, top-hat and many other% morphological operations

SEE GWE, Section 9.3.4 Function bwmorph

Page 20: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

gray-scale imagefunction f

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

Dilate by slidingthe structuringelement over thegray-scalefunction. Takingthe max pushesthe function up.

Drawing Error:top should beflat for adistance b

frb( ) s,t( ) = max f s x,t y( ) + b x, y( ) | s x( ) t y( ) Df ; x, y( ) Db{ }

Structuring element b

Page 21: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

fsb( ) s,t( ) = min f s + x,t + y( ) b x, y( ) | s + x( ) t + y( ) Df ; x, y( ) Db{ }

Erode by slidingthe structuringelement b overthe gray-scalefunction f.Taking the minpushes thefunction down.

Page 22: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology

Gray-scalestructuringelements canhave bothgeometry(connectivity)and intensity.

Page 23: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

original

dilated

eroded

Erosion1. Tends to darkenpositive images2. Bright details(smaller than SE) arereduced or eliminated

Dilation1. Tends to brighten images2. Dark details (smaller thanSE) are reduced or eliminated

Page 24: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology

Erosion using a 2-pixel disk SE

Dilation using a 2-pixel disk SE

Page 25: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

Opening“sharp” detailsreduced inamplitude andsharpness

original

ClosingRemoves“dark” detailswhile leavingbright alone

Upper profile of all balls

Lower profile of all balls

Page 26: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology

Opening andclosing withflat-topelement

Page 27: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

original opening closing

Page 28: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology

Opening using a 3-pixel disk SE

Closing using a 5-pixel disk SE

Page 29: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

original smoothed

SmoothingOpening followed bya closing removes“bright” and “dark”details

Page 30: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology

Opening followedby closing(“smoothing”)using diskstructuringelements ofdifferent radii

Page 31: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

original “gradient”

g = frb( ) fsb( )

An erosion subtractedfrom a dilation will give amorphological gradient

Page 32: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology

Dilation

Erosion

g = frb( ) fsb( )morphological gradient

Page 33: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

Gray Scale Morphology

© 2002 R. C. Gonzalez & R. E. Woods

original “top-hat”

h = f f b( )

A top-hat transformationsubtracts an opening fromthe image.

Enhances detail inthe presence ofshading

Page 34: Lecture #18engr.case.edu/merat_francis/eecs490f07/Lectures/Lecture18.pdf · EECS490: Digital Image Processing Lecture #18 • Connectivity: convex hull, thinning, thickening, skeletons,

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Gray-Scale Morphology