Segmentation Demo

Date: 24/01/2008

Contour Detection

The original image is read and negated. The contour is obtained through a morphological gradient and a threshold.

 1 from ia636 import *
 2 from ia870 import *
 3 import ia870
 4 
 5 thresh = 20
 6 a = adreadgray('sign.jpg')
 7 b = iagradm(iaopen(a, iasebox(1)))
 8 adshow(a, title='Original')
 9 adshow(ia870.iagshow(a, b>thresh), title='Contour')
10 
11 print 'Image shape:', a.shape
Image shape: (245, 326)

Original

Contour

Gray Scale Segmentation

1 mxt = maxtree(b)
2 c = maxaopenth(mxt, 'bbox', 1000, 100)
3 adshow(c, title='Open top-hat on bounding box')
4 c = iaclose(c, iasebox(2))
5 adshow(c, title='Closing small holes')

Open top-hat on bounding box

Closing small holes

Processing.

Contour and Point Detection

1 c = iagradm(c,iasebox(3),iasebox(1))
2 d = iadil(iacloseth(b),iasecross(8))
3 
4 adshow(ianormalize(c),title='Thick contour')
5 adshow(ianormalize(d),title='Points only')

Thick contour

Points only

Contour.