[mmdrobotop] [Up] [mmdsoil] Demonstrations

mmdruler
Detect defects in a ruler.

Description

The input image is a gray-scale image of a ruler, that has a number touching a tick mark. This number and mark are detected based on morphological and connected filtering.

Illustrated Source Code

Reading

The gray-scale image of the ruler is read.

a = mmreadgray('mm3.tif');
mmshow(a);
a

Segmentation

The close top-hat operator followed by a thresholding is applied.

b = mmthreshad( mmcloseth(a,mmsebox(5)),40);
Warning: converting image from scalar to uint8
mmshow(b);
b

Size filtering

The vertical lines longer than 50 pixels are detected.

c = mmopen(b,mmseline(50,90));
mmshow(c);
c

Ruler tick marks filtering

It closes ruler tick marks gaps.

d =mmclose(c,mmseline(15));
mmshow(d);
d

Ruler tick marks connection

It detects all objects connected to the ruler tick markers.

e = mminfrec(d,b);
mmshow(e);
e

Ruler tick mark vertical connection

It detects all objects vertically connected to the ruler tick mark. Note that the 3x1 rectangle is used as structuring element in the vertical reconstruction.

f = mminfrec(d,b,mmseline(3,90));
mmshow(f);
f

Non ruler tick mark vertical connection

The residues obtained from the previous image.

g = mmsubm(e,f);
mmshow(g);
g

Ruler tick marks detection

It uses an opening by an elementary cross structuring element to eliminate the artifacts.

h = mmopen(g);
mmshow(h);
h

Objects detection

It detects the objects connected to ruler tick marks. A reconstruction from the ruler marks detected is applied.

i = mminfrec(h, b);
mmshow(i);
i

Final presentation

Overlay the detected defect over the original image

mmshow(a,i);
a,i

[mmdrobotop] [Up] [mmdsoil]