A set of foreground pixels
A binary image can be represented by the set of foreground pixel locations. Morphological operations modify that set according to a chosen shape, rather than averaging intensities. We work first on the whole integer lattice, where translation and complements have unambiguous meanings.
Definition 8.1.1
(Dilation and erosion)
Let be the foreground and let be a fixed finite nonempty structuring element. With define
The orientation matters: dilation adds , whereas erosion tests a translated copy . Neither definition requires . The symbols and act on arbitrary subsets of the whole lattice, not just finite foregrounds. The same definitions apply verbatim on , which we use for small examples.
Common mistake
(Testing instead of )
For an asymmetric the two tests give different sets. On with and , the condition holds for , while holds for . The second set is , a translate of the first. Mixing the conventions shifts the output and breaks the adjunction below, which pairs with .
An adjunction and its consequences
Theorem 8.1.2
(Dilation–erosion adjunction)
For any ,
Both operators are monotone under set inclusion. Define opening and closing . Then
Proof
(Unfolding the quantifiers, then using only the adjunction)
The left side says for every ; this is exactly for every , the right side. Inclusion of inputs preserves both existential dilation and the erosion subset test, proving monotonicity. Taking in the adjunction gives ; taking gives .
For opening, the first inclusion applied to the set gives . The second inclusion applied to gives , and dilating both sides gives the reverse inclusion. For closing, extensivity applied to gives ; applying the first inclusion to gives , and eroding both sides gives the reverse. ∎
Proof X-ray
Only the adjunction and monotonicity are used
The first paragraph is the one place where the definitions are opened: the adjunction is a rewriting of “for all and all ” in two orders. Everything after that uses only the adjunction and monotonicity, never the shape of or the presence of the origin, which is why the opening is anti-extensive even when . The two inclusions and are each used twice, once directly and once after composing with a monotone operator. Idempotence comes from this sandwich, so it holds for the compositions but not for erosion alone; the second worked example shows erosion shrinking twice.
Worked examples
Worked example 8.1.3
(A one-dimensional row)
Use the definitions on with and . The only translations of contained in start at and , so and
Dilation first gives . Eroding it gives . In this example opening removes the isolated point and closing fills the gap at . These are consequences of this particular , not a promise to remove every kind of noise.
Worked example 8.1.4
(Erosion is not idempotent, opening is)
Take and . The translates inside start at and , so . Eroding again leaves only , so . The opening is : the interval is a union of translates of , so opening returns it unchanged, and opening it again changes nothing.
Reflection and finite boundaries
For a subset of the whole lattice, write and .
Proposition 8.1.5
(Complement duality)
For every , . The identity holds for every input if and only if .
Proof
(Negating an existential statement)
A point fails to lie in exactly when for every , that is, when ; this is . Taking complements of , the second identity says for every . If this holds by substitution. Conversely, gives and , so is necessary. Individual inputs can still agree for an asymmetric .
Worked example 8.1.6
(Checking the duality on a row)
With and on , the first example gives . Now , so means and . Every qualifies, qualifies because , and every qualifies. The candidates fail because , and fails at once. The two sets agree.
The theorems so far live on the whole lattice. A finite image forces a boundary convention, and the convention interacts with the composition.
Counterexample mode
Cropping between operations changes the result
On the finite one-dimensional domain , suppose each intermediate result is cropped to and outside pixels are treated as background. With and , the cropped dilation is ; eroding that zero-extended set gives the empty set. Thus this finite implementation of closing is not extensive. On the whole integer line, the dilation is and the closing is . The whole-lattice theorem did not authorize cropping between the two stages.
Choose and document boundary extension, cropping and structuring-element orientation in an actual image pipeline. Binary morphology does not by itself define a grayscale rule or a segmentation quality measure.
Common mistake
(Assuming dilation always contains its input)
The inclusion holds when , but not in general: and give . The opening and closing inclusions of the adjunction theorem still hold for such , because their proof never uses the origin.
Exercises
Quick check
(On , let and . Compute , and .)
Solution · Answer
The translates inside start at and only ( fails at , at ), so and : opening removes the isolated point . Next , and holds for , so . Closing adds nothing here because has no one-pixel gap.
Quick check
(Why is true even if ?)
Solution · Answer
The adjunction gives without requiring the origin to lie in .
Quick check
(With and on , find and .)
Solution · Answer
The dilation is ; erosion by returns , so closing is .
Quick check
(Why must a finite implementation specify what happens outside the image between stages?)
Solution · Answer
Intermediate cropping or extension can change results and invalidate whole-lattice properties, as the two-pixel counterexample shows.
Further reading
MIT OpenCourseWare, biomedical image-processing lab discusses morphological operations in an image-processing setting.