[mmdHolecenter] [Up] [mmdLith] Demonstrations

mmdLeaf
Segment a leaf from the background

Description

This experiment demonstrate the use of the toggle to segment an image with ill defined borders.

Illustrated Source Code

Reading

The gray scale image to be processed is read.

Image f = mmReadgray("leaf.tif");
mmShow(f);

f

Simple thresholding

Although the leaf was pictured on a light background, it is not possible to fully segment the leaf using a simple thresholding

Image f_low  = mmThreshad(f,100);
Image f_med  = mmThreshad(f,128);
Image f_high = mmThreshad(f,160);
mmShow(f_low);
mmShow(f_med);
mmShow(f_high);

f_low f_med
f_high

Toggle

The toggle is a non-linear image enhancement that changes the pixel value to the maximum or the minimum in the neighborhood given by the structure element, depending which one is the nearest value. The result of the toggle is that near the edges, the image is better defined.

Image f1=mmToggle(f, mmEro(f, mmSedisk(7)), mmDil(f, mmSedisk(7)));
mmShow(f1);

f1

Thresholding and area open

The thresholding can now be applied resulting a good definition of the leaf boarder. Small white spots can be removed by the area open filter.

Image f2 = mmThreshad(f1,100);
Image f3 = mmAreaopen(f2,80);
mmShow(f2);
mmShow(f3);

f2 f3

Final display

For illustration, the contour of the segmented leaf is overlayed in red in the original image

Image f4 = mmGradm(f3);
mmShow(f, f4);

f, f4

[mmdHolecenter] [Up] [mmdLith]