Opening and Closing Change Shape
Tiny bright specks and small holes remain in the leaf mask.
Read the full lesson and open its transcript below. A narrated video will be added after production.
What you will learn
Tiny bright specks and small holes remain in the leaf mask.
A practical question
Our leaf mask has bright flecks in the background and little dark holes inside the leaf. Could one cleanup command fix both without changing the outline? Usually we need to examine them separately.
The useful idea
Opening applies erosion and then dilation with the chosen structuring element. It tends to remove foreground specks and small protrusions that cannot survive the erosion. Closing applies dilation and then erosion. It tends to fill small holes and narrow gaps. The order changes what survives, even though the two basic operations are the same.
Work through the example
Try each on a separate copy of the mask. Count how many isolated flecks remain, then look at the holes and at the thin stem. A large element may make the mask look tidy while also changing the measured leaf shape. Compare the area and boundary with the original before selecting a setting. Opening and closing are sequences of simple shape operations, yet their effects are not interchangeable. Opening can clear small foreground specks; closing can fill narrow gaps inside foreground objects. Put a known speck and a real narrow structure in the same test mask. If the operation removes both, size alone cannot tell which was noise. Check the downstream measurement after the operation, since a tiny edit to a boundary may change area or object count. Now check the idea on a concrete example: Use opening for isolated foreground specks and closing for small interior gaps. A possible trap is worth naming: Large elements can merge objects or erase delicate structures. The answer follows from that evidence: Opening is erosion followed by dilation; closing reverses that order. Inspect the leaf stem after removing background specks. If opening disconnects it, the cleaned mask may look tidy but measure a different object. Compare object count and area before calling the operation useful.
Limits and next step
Keep the original and the precise element and operation order. Next, we'll use a marker to preserve a selected connected structure while excluding unrelated debris.
Worked example
Use opening for isolated foreground specks and closing for small interior gaps.
Quick check: test your understanding
Try it yourself: Consider this case: Use opening for isolated foreground specks and closing for small interior gaps. Explain how you would check the result. In your answer, address this limitation: Large elements can merge objects or erase delicate structures.
Check the reasoning
Opening is erosion followed by dilation; closing reverses that order. Large elements can merge objects or erase delicate structures.
What is the main idea behind opening and closing change shape?
Opening is erosion followed by dilation; closing reverses that order.
How is it used in the example?
Use opening for isolated foreground specks and closing for small interior gaps.
What limitation should be checked?
Large elements can merge objects or erase delicate structures.
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 59 transcript324 words · Narration ready for the upcoming videoOpen transcript
Our leaf mask has bright flecks in the background and little dark holes inside the leaf. Could one cleanup command fix both without changing the outline? Usually we need to examine them separately.
Opening applies erosion and then dilation with the chosen structuring element. It tends to remove foreground specks and small protrusions that cannot survive the erosion. Closing applies dilation and then erosion. It tends to fill small holes and narrow gaps. The order changes what survives, even though the two basic operations are the same.
Try each on a separate copy of the mask. Count how many isolated flecks remain, then look at the holes and at the thin stem. A large element may make the mask look tidy while also changing the measured leaf shape. Compare the area and boundary with the original before selecting a setting. Opening and closing are sequences of simple shape operations, yet their effects are not interchangeable. Opening can clear small foreground specks; closing can fill narrow gaps inside foreground objects. Put a known speck and a real narrow structure in the same test mask. If the operation removes both, size alone cannot tell which was noise. Check the downstream measurement after the operation, since a tiny edit to a boundary may change area or object count. Now check the idea on a concrete example: Use opening for isolated foreground specks and closing for small interior gaps. A possible trap is worth naming: Large elements can merge objects or erase delicate structures. The answer follows from that evidence: Opening is erosion followed by dilation; closing reverses that order. Inspect the leaf stem after removing background specks. If opening disconnects it, the cleaned mask may look tidy but measure a different object. Compare object count and area before calling the operation useful.
Keep the original and the precise element and operation order. Next, we'll use a marker to preserve a selected connected structure while excluding unrelated debris.