Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

EECE\CS 253 Image Processing

Lecture Notes on Mathematical Lecture Notes Morphology: Grayscale Images

Richard Alan Peters II


Department of Electrical Engineering and Computer Science
Fall Semester 2011

. 1

.... . .

This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.

Grayscale Morphology
Grayscale morphology is a multidimensional generalization of the binary operations. Binary morphology is defined in terms of set-inclusion of pixel sets. So is the grayscale case, but the pixel sets are of higher dimension. In particular, standard RC, 1band intensity images and the associated structuring elements are defined as 3-D solids wherein the 3rd axis is intensity and set-inclusion is volumetric.
set setinclusion inclusion (explained (explained on onp. p.11 11) ) (a) (a)binary, binary, (b) & (b) &(c) (c) grayscale grayscale

(a)

(b)

(c)

2 December 2011

1999-2011 by Richard Alan Peters II

Extended Real Numbers


Let R represent the real numbers. Define the extended real numbers, R*, as the real numbers plus two symbols, and such that
< x < ,

for all numbers xR. That is if x is any real number, then is always greater than x and is always less than x. Moreover,
x + = , x = , = 0,

for all numbers x R.


2 December 2011 1999-2011 by Richard Alan Peters II 4

Real Images
In mathematical morphology a real image, I, is defined as a function that occupies a volume in a Euclidean vector space. I comprises a set, Sp, of coordinate vectors (or pixel locations), p, in an n-dimensional vector space Rn. Associated with each p is a value from R*. The set of pixel locations together with their associated values form the image a set in Rn+1:
I = { p, I ( p) p S p R n , I ( p) R }

Thus, a conventional, 1-band, RC image is a 3D structure with Sp R2 and I(p)R. By convention in the literature of MM, Sp Rn, a real image is defined over all of Rn.
2 December 2011 1999-2011 by Richard Alan Peters II 5

Support of an Image
The support of a real image, I, is
supp ( I ) = p R n I ( p ) R .
That is, the support of a real image is the set pixel locations in Rn such that

I(p) and I(p) .


The complement of the support is, therefore, the set of pixel locations in Rn where

I(p) = or I(p) = .

2 December 2011

1999-2011 by Richard Alan Peters II

Grayscale Images
If over its support, I takes on more than one real value, then I is called grayscale. The object commonly known as a black and white photograph is a grayscale image that has support in a rectangular subset of R2. Within that region, the image has gray values that vary between black and white. If the intensity of each pixel is plotted over the support plane, then
I = { [ p, I ( p) ] p supp ( I ) }

is a volume in R3. In the abstraction of MM we assume the image does exist outside the support rectangle, but that I(p) = there.
2 December 2011 1999-2011 by Richard Alan Peters II 7

Grayscale Images

grayscale image 3D solid representation

In In MM, MM, a a 2D 2D grayscale grayscale image image is is treated treated as as a a 3D 3D solid solid in in space space a a landscape landscape whose whose height height above above the the surface surface at at a a point point is is proportional proportional to to the the brightness brightness of of the the corresponding corresponding pixel. pixel.
2 December 2011 1999-2011 by Richard Alan Peters II 8

Representation of Grayscale Images

image

landscape

Example: grayscale cones


2 December 2011 1999-2011 by Richard Alan Peters II 9

Aside: Brightness Perception


The previous slide demonstrates the WeberFechner relation. The linear slope of the intensity change is perceived as logarithmic.

The green curve is the actual intensity; the blue curve is the perceived intensity.

2 December 2011

1999-2011 by Richard Alan Peters II

10

Set Inclusion in Grayscale Images


In grayscale morphology, set inclusion depends on the implicit 3D structure of a 2D image. If I and J are grayscale images then
J I supp ( J ) supp ( I )
AND

{ J ( p ) I ( p ) p supp ( J ) }.

That is J I if and only if the support of J is contained in that of I and the value of J is nowhere greater than the value of I on the support of J.
J
binary

I
grayscale

I
grayscale

JI JI
2 December 2011

JI JI

JI JI
11

1999-2011 by Richard Alan Peters II

Recall: Binary Structuring Element (SE)


Let I be an image and Z a SE. Z+p means that Z is moved so that its origin coincides with location p in SP. Z+p is the translate of Z to location p in SP. The set of locations in the image delineated by Z+p is called the Z-neighborhood of p in I denoted N{I,Z}(p).

2 December 2011

1999-2011 by Richard Alan Peters II

12

Grayscale Structuring Elements


A grayscale structuring element is a small image that delineates a volume at each pixel [p , I(p)] through out the image volume.
grayscale SE flat SE translated flat SE Translation of a flat SE on its support plane and in gray value.

SE Translation:
2 December 2011

marks the location of the structuring element origin.


1999-2011 by Richard Alan Peters II 13

Grayscale Structuring Elements


grayscale SE flat SE translated flat SE Translation of a flat SE on its support plane and in gray value.

If Z = [ p, Z(p) ] is a structuring element and if q = [ qs, qg ] is a pixel [location, value] then Z+q = [ p+qs, Z(p)+qg ] for all p supp{Z}.
2 December 2011 1999-2011 by Richard Alan Peters II 14

Reflected Structuring Elements


Note Notethat thatthe the SE, ,,is SE,Z Z isto tothe the bright brightregions regions

as asthe thereflected reflected SE, ,,is SE, isto tothe the dark darkregions. regions.
2 December 2011 1999-2011 by Richard Alan Peters II 15

Grayscale Morphology: Basic Operations

2 December 2011

1999-2011 by Richard Alan Peters II

16

Dilation: General Definition


The dilation of image I by structuring element Z at coordinate pRn is defined by

[ I Z ](p) = max {I (q) + Z (p q)} = max {I (q) Z (q p)}. qsupp Z+p qsupp Z+p
( ) ( )

This can be computed as follows: 1. 2. 3. 4. Translate to p. Trace out the neighborhood of I at p. Let p be the origin of I temporarily during the operation Compute the set of numbers

D = I (q) + Z (q) q supp ( Z) = I (q ) Z (q ) q supp ( Z) .


5. The output value, [I Z](p), is the maximum value in the set, D.
1999-2011 by Richard Alan Peters II 17

} {

2 December 2011

Fast Computation of Dilation


The fastest way to compute grayscale dilation is to use the translates-ofthe-image definition of dilation. That is, use
Notethat thatif ifZ Zis isflat flat Note --all allits itsforeground foreground -elementsare are00--elements thenstep step(3) (3)is is then unnecessary. Then Thenit it unnecessary. isaamaximum maximumfilter. filter. is

max { [ I + q ] + Z ( q ) }. J = J Z = q supp{Z}

That is, (1) Make a copy of I for each foreground element, q, in Z. (2) Translate the qth copy so that its ULHC (origin) is at position q in Z. (3) Add Z(q) to every pixel in the qth copy. (4) Take the pixelwise maximum of the resultant stack of images. (5) Copy out the result starting at the SE origin in the maximum image.
2 December 2011 1999-2011 by Richard Alan Peters II

18

Grayscale Morphology: Dilation

dilation
SE,Z Z isaaflat flatdisk disk SE, , ,is thesize sizeof ofthe thetops topsof of the thetruncated truncatedcones. cones. the 2 December 2011

dilation over original

1999-2011 by Richard Alan Peters II

19

Grayscale Morphology: Dilation

SE, , ,is SE,Z Z isaaflat flatdisk. disk. 2 December 2011 1999-2011 by Richard Alan Peters II 20

Erosion: General Definition


The erosion of image I by structuring element Z at coordinate pRn is defined by

min {I (q ) Z (q p)}. [ I Z ](p) = qsupp ( Z+p)


This can be computed as follows: 1. 2. 3. 4. Translate Z to p. Trace out the Z neighborhood of I at p. Let p be the origin of I temporarily during the operation Compute the set of numbers

E = {I (q ) Z (q) q supp ( Z)} .


5. The output value, [I Z](p), is the minimum value in the set, E.
1999-2011 by Richard Alan Peters II 21

2 December 2011

Grayscale Morphology: Erosion

erosion
SE,Z Z isthe thesame sameflat flat SE, , ,is diskas asused usedfor forthe the disk dilationon onpage page19. 19. dilation 2 December 2011

erosion under original

1999-2011 by Richard Alan Peters II

22

Fast Computation of Erosion


The fastest way to grayscale erosion is to create a stack of images translated to minus the values of the reflected SE then take the pixelwise minimum:
Notethat thatif ifZ Zis is Note symmetricand andif ifall all symmetric theforeground foreground the elementsare are0, 0,then then elements Zand andstep step(3) (3)is is == Z unnecessary. Then Thenit it unnecessary. isaaminimum minimumfilter filter is

J=I

Z = min { [ I + q ] + Z (q )}
qZ

Z = { Z (q ) | q R 2 }

That is, (1) make a copy of I for each foreground element, q, in . (Note that if q is a foreground element in then -q is a foreground element in Z.) (2) Translate each copy so that its ULHC (origin) is at position q in (or -q in Z). (3) Then add (q) (or subtract Z(-q)) to every pixel in the qth copy. Finally, (4) take the pixelwise minimum of the resultant stack of images.
2 December 2011 1999-2011 by Richard Alan Peters II 23

Grayscale Morphology: Erosion

SE, , ,is SE,Z Z isaaflat flatdisk. disk. 2 December 2011 1999-2011 by Richard Alan Peters II 24

Grayscale Morphology: Opening

opening: erosion then dilation


SE,Z Z isaaflat flatdisk disk SE, , ,is thesize sizeof ofthe thetops topsof of the thetruncated truncatedcones. cones. the 2 December 2011

opened & original

1999-2011 by Richard Alan Peters II

25

Grayscale Morphology: Opening

erosion & opening


SE,Z Z isaaflat flatdisk disk SE, , ,is thesize sizeof ofthe thetops topsof of the thetruncated truncatedcones. cones. the 2 December 2011

erosion & opening & original

1999-2011 by Richard Alan Peters II

26

Opening and Closing


Opening is erosion by Z followed by dilation by Z.

I Z = (I

Z) Z .

The opening is the best approximation of the image FG that can be made from copies of the SE, given that the opening is contained in the original. I Z contains no FG features that are smaller than the SE. Closing is dilation by followed by erosion by .

I Z = (I Z) Z .
The closing is the best approximation of the image BG that can be made from copies of the SE, given that the closing is contained in the image BG. I Z contains no BG features that are smaller than the SE.
2 December 2011 1999-2011 by Richard Alan Peters II 27

Grayscale Morphology: Opening

SE, , ,is SE,Z Z isaaflat flatdisk. disk. 2 December 2011 1999-2011 by Richard Alan Peters II 28

Grayscale Morphology: Closing

closing: dilation then erosion


SE,Z Z isthe thesame sameflat flat SE, , ,is diskas asused usedfor forthe the disk dilationon onpage page19. 19. dilation 2 December 2011

closing & original

1999-2011 by Richard Alan Peters II

29

Grayscale Morphology: Closing

dilation over closing


SE,Z Z isaaflat flatdisk disk SE, , ,is thesize sizeof ofthe thetops topsof of the thetruncated truncatedcones. cones. the 2 December 2011

dilation & closing & original

1999-2011 by Richard Alan Peters II

30

Grayscale Morphology: Closing

SE, , ,is SE,Z Z isaaflat flatdisk. disk. 2 December 2011 1999-2011 by Richard Alan Peters II 31

Duality Relationships
Erosion in terms of dilation: Dilation in terms of erosion: Opening in terms of closing: Closing in terms of opening:
I Z = I C Z C . I Z = I C Z C .

I Z = I C Z C . I Z = I C Z C .

IC is the complement of I and is the reflected SE.


2 December 2011 1999-2011 by Richard Alan Peters II 32

Duality Relationships
C SE, ,,operates SE, operateson onIICas asif if it .. itwere wereZ Zoperating operatingon onII

C SE, ,,operates asif if SE,Z Z operateson onIICas it .. itwere were operating operatingon onII

2 December 2011

1999-2011 by Richard Alan Peters II

33

Gray Ops with Asymmetric SEs

L shaped SE O marks origin


2 December 2011

Foreground: white pixels Background: black pixels


1999-2011 by Richard Alan Peters II

Cross-hatched pixels are indeterminate. 34

Grayscale Morphology: Tophat

tophat + opened = original


SE,Z Z isthe thesame sameflat flat SE, , ,is diskas asused usedfor forthe the disk dilationon onpage page19. 19. dilation 2 December 2011

tophat: original - opening

1999-2011 by Richard Alan Peters II

35

Grayscale Morphology: Tophat

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011

shown as as a a negative negative for for visibility visibility shown


1999-2011 by Richard Alan Peters II 36

Grayscale Morphology: Bothat

region added by dilation


SE,Z Z isthe thesame sameflat flat SE, , ,is diskas asused usedfor forthe the disk dilationon onpage page19. 19. dilation 2 December 2011

superimposed on original

1999-2011 by Richard Alan Peters II

37

Grayscale Morphology: Bothat

region added by dilation


SE,Z Z isthe thesame sameflat flat SE, , ,is diskas asused usedfor forthe the disk dilationon onpage page19. 19. dilation 2 December 2011

Bothat: closing - original

1999-2011 by Richard Alan Peters II

38

Grayscale Morphology: Bothat

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011

shown as as a a negative negative for for visibility visibility shown


1999-2011 by Richard Alan Peters II 39

Grayscale Morphology: Tophat and Bothat


tophat tophat bothat bothat

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011

shown shown as as negatives negatives for for visibility visibility


1999-2011 by Richard Alan Peters II 40

Grayscale Morphology: Small Feature Detection


original tophat minus bothat middle gray = 0

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011 1999-2011 by Richard Alan Peters II 41

Algorithm for Grayscale Reconstruction


1. J = I 2. T = J, 3. J = J Zk , where k=4 or k=8, 4. J = min{I, J}, 6. else stop;
[pixelwise minimum of I and J.]

Z , where Z is any SE.

5. if J T then go to 2,
[ J is the reconstructed image. ]

This is the same as binary reconstruction but for grayscale images J(r,c) I if and only if J(r,c) I(r,c).
2 December 2011 1999-2011 by Richard Alan Peters II 42

Algorithm for Grayscale Reconstruction


1. J = I 2. T = J, 4. J = min{I, J}, 6. else stop;

Usuallyaaprogram programfor forreconstruction reconstruction Usually willtake takeboth bothJ Jand andIIas asinputs. inputs. E.g, E.g, will K= = ReconGray(I,J,Z); ReconGray(I,J,Z); K

Z , where Z is any SE.

Thenthe thealgorithm algorithmstarts startsat atstep step2. 2. Then

3. J = J Zk , where k=4 or k=8,


[pixelwise minimum of I and J.]

5. if J T then go to 2,
[ J is the reconstructed image. ]

This is the same as binary reconstruction but for grayscale images J(r,c) I if and only if J(r,c) I(r,c).
2 December 2011 1999-2011 by Richard Alan Peters II 43

Grayscale Reconstruction

opened image
SE,Z Z isaaflat flatdisk disk SE, , ,is thesize sizeof ofthe thetops topsof of the thetruncated truncatedcones. cones. the 2 December 2011

opened image & original

1999-2011 by Richard Alan Peters II

44

Grayscale Reconstruction

opened & recon. image


SE,Z Z isaaflat flatdisk disk SE, , ,is thesize sizeof ofthe thetops topsof of the thetruncated truncatedcones. cones. the 2 December 2011

opened, recon., & original

1999-2011 by Richard Alan Peters II

45

Grayscale Morphology: Reconstruction

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011 1999-2011 by Richard Alan Peters II 46

Grayscale Reconstruction
original reconstructed opening

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011 1999-2011 by Richard Alan Peters II 47

Grayscale Reconstruction
opening original

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011 1999-2011 by Richard Alan Peters II 48

Grayscale Reconstruction
reconstructed opening opening

SE,Z Z isaaflat flatdisk. disk. SE, , ,is 2 December 2011 1999-2011 by Richard Alan Peters II 49

You might also like