What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word...

73

Transcript of What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word...

Page 1: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological
Page 2: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

What are Morphological Operations? What are Morphological Operations?

Morphological operations come from the word “morphing”in Biology which means “changing a shape”.

Morphing

Image morphological operations are used to manipulateobject shapes such as thinning, thickening, and filling.

Binary morphological operations are derived fromset operations.

Page 3: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Basic Set Operations Basic Set Operations

Concept of a set in binary image morphology:Each set may represent one object. Each pixel (x,y) has

its status: belong to a set or not belong to a set.

Page 4: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Translation and Reflection Operations Translation and Reflection Operations

A

(A)z

z = (z1,z2)

Translation Reflection

B

BbbwwB ∈−== for ,ˆ( ) AazaccA z ∈+== for ,

Page 5: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Logical Operations* Logical Operations*

*For binary images only

Page 6: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Logical Operations* Logical Operations*

Page 7: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Dilation Operations Dilation Operations

φ≠∩=⊕ ABzBA zˆ

AABzBA z ⊆∩=⊕ ]ˆ[

This equation is based on obtaining the reflection of B about its original and shifting this reflection by z. The dilation of A by B the is the set of all displacement, z, such and A overlap by at least one element.

Set B is commonly referred to as the structuring element.In

Page 8: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Dilation Operations Dilation Operations AABzBA z ⊆∩=⊕ ]ˆ[

Matlab à Dilation: The value of the output pixel is the maximum value of all the pixels in the input pixel's neighborhood. In a binary image, if any of the pixels is set to the value 1, the output pixel is set to 1.

Page 9: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Dilation Operations Dilation Operations

φ≠∩=⊕ ABzBA zˆ

φ = Empty set

A = Object to be dilatedB = Structuring element

Dilate means “extend”

Page 10: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Application of DilationExample: Application of Dilation

“Repair” broken characters

Page 11: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Application of DilationExample: Application of Dilation

>> B=[0 1 0; 1 1 1; 0 1 0]B =

0 1 01 1 10 1 0

>> A=imread('fig0905.tif');>> A2=imdilate(A,B);>> imshow(A);>> figure;imshow(A2);

Remember! Dilation is an operation that “grows” or “thickens” objects in a binary image. The specific manner and extent of this thickening is controlled by a shape refer to as a structuring element

Page 12: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Application of DilationExample: Application of DilationRemember! Dilation is an operation that “grows” or “thickens” objects in a binary image. The specific manner and extent of this thickening is controlled by a shape refer to as a structuring element.

Page 13: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Erosion Operation Erosion Operation

( ) ABzBA z ⊆=

A = Object to be erodedB = Structuring element

Erosion means “trim”

A B

The Erosion of A by B is the set of all points z such that B, translated by z is contained in A.

Page 14: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Erosion Operation Erosion Operation

MatlabàErosion: The value of the output pixel is the minimum value of all the pixels in the input pixel's neighborhood. In a binary image, if any of the pixels is set to 0, the output pixel is set to 0.

Page 15: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Application of Dilation and ErosionExample: Application of Dilation and Erosion

Remove small objects such as noise

Remember! Erosion “shrinks” or “thins” objects in binary image.

Page 16: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Duality Between Dilation and ErosionDuality Between Dilation and Erosion

BABA cc ˆ) ( ⊕=

Proof:where c = complement

( )( )( )

BA

ABz

ABz

ABzBA

c

cz

ccz

cz

c

ˆ

) (

⊕=

≠∩=

=∩=

⊆=

φ

φ

Page 17: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Opening Operation Opening Operation

BBABA ⊕= ) (o

( ) ( ) ABBBA zz ⊆∪=oor

= Combination of all parts of A that can completely contain B

Opening eliminates narrow and small details and corners.

Page 18: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Example of Opening Example of Opening

Page 19: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Closing Operation Closing Operation

BBBA )A( ⊕=•

Closing fills narrow gaps and notches

Page 20: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Example of Closing Example of Closing

B

Page 21: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Duality Between Opening and ClosingDuality Between Opening and Closing

( ) BABA cc ˆo=•

Properties OpeningProperties Opening

( ) BABBABDBCDC

ABA

ooo

oo

o

=⊂⊂

.3 then If 2.

.1

( ) BABBABDBCDC

BAA

•=•••⊂•⊂

•⊆

.3 then If 2.

.1Properties ClosingProperties Closing

Idem potent property: can’t change any more

Page 22: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Application of Morphological OperationsExample: Application of Morphological Operations

(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Finger print enhancementf=imread('fig911.tif');se=strel('square',3)fo=imopen(f,se);imshow(fo);foc=imclose(fo,se);figure;imshow(foc);

Page 23: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

HitHit--oror--Miss Transformation Miss Transformation

)( XWAXABA c −∩=*

where X = shape to be detectedW = window that can contain X

Page 24: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.)

)( XWAXABA c −∩=*

Page 25: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.) )( XWAXABA c −∩=*

21 BABABA c∩=*

However, if we consider B is a structuring pair, B = (B1, B2) where B1=X and B2 =(W-X). We can rewrite as:

Original Image

Erosion of A by B1

Complement of the original image Ac

Erosion of Ac by B2

Output Image

Page 26: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

HitHit--oror--Miss Transformation (cont.) Miss Transformation (cont.) Matlab command

C=bwhitmis(A,B1,B2);

Example:

>>f=imread(‘Fig0913.tif’);

>>B1=strel([0 0 0;0 1 1; 0 1 0]);

>>B2=strel([1 1 1;1 0 0; 1 0 0]);

>>g= bwhitmiss(f,B1,B2);

>>imshow(g);

Page 27: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Boundary Extraction Boundary Extraction

BAAβ(A) −=

Original image

Boundary

The boundary of set A, denoted by , can be obtained by first eroding A by B (suitable structuring element) and then performing the set difference between A and its erosion.

)(Aβ

Page 28: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Boundary Extraction Boundary Extraction

BAAβ(A) −=

Original image

Boundary

A=imread('fig914.jpg');B=strel('square',3)

AeB=imerode(A,B);Bon=A-AeB;imshow(Bon);

Page 29: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Region Filling Region Filling

( ) ckk ABXX ∩⊕= −1

Original image

Results of region filling

where X0 = seed pixel p

Page 30: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Extraction of Connected Components Extraction of Connected Components

( ) ABXX kk ∩⊕= −1 where X0 = seed pixel p

Page 31: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Extraction of Connected Components Example: Extraction of Connected Components

X-ray imageof bones

Thresholdedimage

Connectedcomponents

(Images from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Page 32: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Convex Hull Convex Hull

i

iDAC

=

=4

1)(

4,3,2,1 , 1 =∪= − iABXX ik

ik *

iconv

i XD =

Convex hull has no concave part.

Convex hull

Algorithm: where

convergence

Page 33: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Convex Hull Example: Convex Hull

4,3,2,1 , 1

=∪= −

iABXX i

kik *

Page 34: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Thinning Thinning

cBAABAABA

) ( ) (

∩=

−=⊗ *

*

{ } ))...))((...(( 21 nBBBABA ⊗⊗⊗=⊗

Page 35: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Thinning Example: Thinning

Make an object thinner.

{ } ))...))((...(( 21 nBBBABA ⊗⊗⊗=⊗

Page 36: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Thickening Thickening

* ) ( BAABA ∪=

{ } ) )...) ) ((...(( 21 nBBBABA =

Make an object thicker

*

However, we can do as follow:

1. C=Ac

2. Thin C

3. Form Cc

Page 37: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Skeletons Skeletons

Dot lines are skeletons of thisstructure

Skeleton, S(A), of a set A is:

(a) If z is a point of S(A) and (D)z, is the largest disk centered at z and contained in A, one cannot find a larger disk (not necessarily centered at z) containing (D)z, and included in A. The disk (D)z, is called a maximum disk.

(b) The disk (D), touches the boundary of A at two or more different places.

Page 38: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Skeletons (cont.) Skeletons (cont.)

)()(0

ASAS k

K

k=

=

with

where ...) ) ) (...( ( BBBAkB)A =

BkB)AkB)AASk o ( ()( −=

k times

and ( ) φ≠= kBAkK max

Page 39: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Skeletons Skeletons

Page 40: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Pruning Pruning

{ }BAX ⊗=1

AHXX ∩⊕= )( 23

) ( 1

8

12

k

kBXX

=

= *

314 XXX ∪=

= thinning

= finding end points

= dilation at end points

= Pruned result

Page 41: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Pruning Example: Pruning

Originalimage

Prunedresult

After Thinning3 times

End points

Dilationof end points

Page 42: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

(Tables from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Summary of Binary Morphological Operations Summary of Binary Morphological Operations

Page 43: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)

(Tables from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Page 44: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)

(Tables from Rafael C.Gonzalez and Richard E. Wood, Digital Image Processing, 2nd Edition.

Page 45: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Summary of Binary Morphological Operations (cont.) Summary of Binary Morphological Operations (cont.)

Page 46: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Basic Types of Structuring ElementsBasic Types of Structuring Elements

x = don’t care

Page 47: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

GrayGray--Scale Dilation Scale Dilation

{ }bf DyxDytxsyxbytxsfbf ∈∈−−+−−=⊕ ),(;)(),(|),(),(max

{ }bf DxDxsxbxsfbf ∈∈−+−=⊕ and )(|)()(max2-D Case1-D Case

Page 48: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

SubimageOriginal image

Moving window

Max

Output image

GrayGray--Scale Dilation (cont.) Scale Dilation (cont.)

+

Reflectionof B

Structuring element B

Note: B can be any shape and subimage must have the same shape asreflection of B.

Page 49: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

GrayGray--Scale ErosionScale Erosion

{ }bf DyxDytxsyxbytxsfbf ∈∈++−++=− ),(;)(),(|),(),(min2-D Case1-D Case { }bf DxDxsxbxsfbf ∈∈+−+=− and )(|)()(min

Page 50: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

SubimageOriginal image

Moving window

Min

Output image

GrayGray--Scale Erosion (cont.) Scale Erosion (cont.)

-B

Structuring element B

Note: B can be any shape and subimage must have the same shape as B.

Page 51: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: GrayExample: Gray--Scale Dilation and ErosionScale Dilation and ErosionOriginal image After dilation

After erosion

Darker Brighter

Page 52: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

GrayGray--Scale OpeningScale Opening

bbfbf ⊕−= )(o

Opening cuts peaks

Page 53: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

GrayGray--Scale ClosingScale Closing

bbfbf −⊕=• )(

Closing fills valleys

Page 54: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: GrayExample: Gray--Scale Opening and ClosingScale Opening and Closing

Original image After closingAfter opening

Reduce whiteobjects

Reduce darkobjects

Page 55: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

GrayGray--scale Morphological Smoothing scale Morphological Smoothing

Smoothing: Perform opening followed by closing

Original image After smoothing

Page 56: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

GrayGray--scale Morphological Smoothing scale Morphological Smoothing

Smoothing: Perform opening followed by closing

Page 57: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Morphological Gradient Morphological Gradient

Original image Morphological Gradient

)()( bfbfg −−⊕=

Page 58: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Morphological Gradient Morphological Gradient

)()( bfbfg −−⊕=

Page 59: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

TopTop--Hat Transformation Hat Transformation

Original image Results of top-hat transform

)( bffh o−=

Page 60: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

TopTop--Hat Transformation Hat Transformation

)( bffh o−=

Page 61: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Texture Segmentation Application Example: Texture Segmentation Application

Algorithm:1. Perform closing on the image by using successively larger structuring elements until small blobs are vanished.2. Perform opening to join large blobs together3. Perform intensity thresholding

Original image Segmented result

Small blob

Large blob

Page 62: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Granulometry Example: Granulometry Objective: to count the number of particles of each sizeMethod:1. Perform opening using structuring elements of increasing size2. Compute the difference between the original image and the result

after each opening operation3. The differenced image obtained in Step 2 are normalized and used

to construct the size-distribution graph.

Original imageSize distribution

graph

Page 63: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Granulometry Example: Granulometry

Page 64: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Example: Granulometry Example: Granulometry

Page 65: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

MatlabMatlab: morphological processing: morphological processing

Page 66: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

MatlabMatlab: morphological processing: morphological processing

Page 67: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

MatlabMatlab: Create Structural Element: Create Structural ElementSE=strel(‘shape’, parameter)

>>se=strel('diamond',3)

0 0 0 1 0 0 00 0 1 1 1 0 00 1 1 1 1 1 01 1 1 1 1 1 10 1 1 1 1 1 00 0 1 1 1 0 00 0 0 1 0 0 0

Size distribution graph

Page 68: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

MatlabMatlab: morphological processing: morphological processingbwmorphMorphological operations on binary imagesSyntaxBW2 = bwmorph(BW,operation)BW2 = bwmorph(BW,operation,n)

Page 69: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

MatlabMatlab: : bwmorph

Page 70: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

MatlabMatlab: : bwmorph

Original imageSize distribution

graph

Page 71: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Matlab:LabelMatlab:Label connected components in binary imageconnected components in binary imagebwlabelSyntaxL = bwlabel(BW,n)[L,num] = bwlabel(BW,n)DescriptionL = bwlabel(BW,n) returns a matrix L, of the same size as BW, containing labels for the connected objects in BW. n can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it defaults to 8.

The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on.

[L,num] = bwlabel(BW,n) returns in num the number of connected objects found in BW.

Page 72: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Matlab:LabelMatlab:Label connected components in binary imageconnected components in binary imageExamplesLabel components using 4-connected objects. Notice objects 2 and 3; with 8-connected labeling, bwlabel would consider these a single object rather than two separate objects.BW = [1 1 1 0 0 0 0 0

1 1 1 0 1 1 0 01 1 1 0 1 1 0 01 1 1 0 0 0 1 01 1 1 0 0 0 1 01 1 1 0 0 0 1 01 1 1 0 0 1 1 01 1 1 0 0 0 0 0];

L = bwlabel(BW,4)L =

1 1 1 0 0 0 0 01 1 1 0 2 2 0 01 1 1 0 2 2 0 01 1 1 0 0 0 3 01 1 1 0 0 0 3 01 1 1 0 0 0 3 01 1 1 0 0 3 3 01 1 1 0 0 0 0 0

[r,c] = find(L==2);rc = [r c]rc =

2 53 52 63 6

Page 73: What are Morphological Operations?jan/204584/09-morph.pdfMorphological operations come from the word “morphing” in Biology which means “changing a shape”. Morphing Image morphological

Matlab:MorphologicalMatlab:Morphological process usagesprocess usages

Examples>> f=imread('rice.png');>> imshow(f);>> figure;imhist(f);>> figure;imshow(f>140);>> se=strel('disk',10);>> fo=imopen(f,se);>> figure;imshow(fo);>> f2=imsubtract(f,fo);>> figure;imshow(f2);>> figure;imhist(f);>> figure;imshow(f2>50);