← Image Processing for EveryoneToolsInVisionLearning Center
Morphology in Depth · Lesson 58

Erosion and Dilation on Real Masks

A thin bridge joins two leaves in a thresholded mask.

Read the full lesson and open its transcript below. A narrated video will be added after production.

Lesson overview

What you will learn

A thin bridge joins two leaves in a thresholded mask.

  1. A practical question
  2. The useful idea
  3. Work through the example
  4. Limits and next step
01

A practical question

Two leaves touch through a one-pixel bridge in our mask. We might erode the foreground to break the bridge. Erosion removes foreground pixels that don't satisfy the chosen neighborhood rule. But the real thin stem can disappear for exactly the same reason.

02

The useful idea

Dilation goes the other way: it expands foreground according to the chosen element. It can fill a small gap, but it may also join leaves that should be separate. Neither operation knows whether a particular narrow shape is an error or a real part of the plant.

03

Work through the example

Run one erosion and one dilation on separate copies. Inspect the bridge, the stem, and an untouched wide leaf. What changed in each? If you later combine operations, don't assume the second step perfectly reverses the first; information about tiny structures may already be gone. Erosion can remove isolated foreground specks, but it also eats into a narrow stem. Dilation can join nearby components, but it may merge objects that should stay separate. Compare the mask with the original image after each operation. Count what disappeared or joined, rather than judging only whether the result looks tidy. Set the element size with real specimen dimensions in mind, and preserve the raw mask for a different decision later. Use this case to test your understanding: Try one erosion step, then inspect whether the bridge and a real narrow stem both disappear. Here is the limitation to watch for: Morphology operates on shape without knowing which pixels are botanically meaningful. This supports a careful conclusion: Erosion removes foreground near boundaries; dilation expands it under the chosen element. Set one narrow stem beside an isolated speck. After erosion, see whether both vanished. The operation knows their shapes, not their meaning, so the inspector must decide what to preserve.

04

Limits and next step

Write down the foreground definition and element shape, then save all three masks. Next, we'll combine these two operations in different orders to target small specks and small holes.

Worked example

Try one erosion step, then inspect whether the bridge and a real narrow stem both disappear.

Knowledge check

Quick check: test your understanding

Try it yourself: Consider this case: Try one erosion step, then inspect whether the bridge and a real narrow stem both disappear. Explain how you would check the result. In your answer, address this limitation: Morphology operates on shape without knowing which pixels are botanically meaningful.

Check the reasoning

Erosion removes foreground near boundaries; dilation expands it under the chosen element. Morphology operates on shape without knowing which pixels are botanically meaningful.

What is the main idea behind erosion and dilation on real masks?

Erosion removes foreground near boundaries; dilation expands it under the chosen element.

How is it used in the example?

Try one erosion step, then inspect whether the bridge and a real narrow stem both disappear.

What limitation should be checked?

Morphology operates on shape without knowing which pixels are botanically meaningful.

Further reading

Digital Image Processing, 4th edition — Rafael C. Gonzalez and Richard E. Woods.

Original ToolsInVision teaching examples. Editorial approach · Suggest a correction

Accessible referenceLesson 58 transcript323 words · Narration ready for the upcoming videoOpen transcript

Two leaves touch through a one-pixel bridge in our mask. We might erode the foreground to break the bridge. Erosion removes foreground pixels that don't satisfy the chosen neighborhood rule. But the real thin stem can disappear for exactly the same reason.

Dilation goes the other way: it expands foreground according to the chosen element. It can fill a small gap, but it may also join leaves that should be separate. Neither operation knows whether a particular narrow shape is an error or a real part of the plant.

Run one erosion and one dilation on separate copies. Inspect the bridge, the stem, and an untouched wide leaf. What changed in each? If you later combine operations, don't assume the second step perfectly reverses the first; information about tiny structures may already be gone. Erosion can remove isolated foreground specks, but it also eats into a narrow stem. Dilation can join nearby components, but it may merge objects that should stay separate. Compare the mask with the original image after each operation. Count what disappeared or joined, rather than judging only whether the result looks tidy. Set the element size with real specimen dimensions in mind, and preserve the raw mask for a different decision later. Use this case to test your understanding: Try one erosion step, then inspect whether the bridge and a real narrow stem both disappear. Here is the limitation to watch for: Morphology operates on shape without knowing which pixels are botanically meaningful. This supports a careful conclusion: Erosion removes foreground near boundaries; dilation expands it under the chosen element. Set one narrow stem beside an isolated speck. After erosion, see whether both vanished. The operation knows their shapes, not their meaning, so the inspector must decide what to preserve.

Write down the foreground definition and element shape, then save all three masks. Next, we'll combine these two operations in different orders to target small specks and small holes.