Demo iadcornea

Cornea cells marking.


This procedure creates a maker for each cell in a very poor quality microscopic image of a cornea. The composition of an opening with the regional maximum is used to create the markers.


Reading and topographic view

The gray-scale image of the cornea is read and displayed. A topographic model is also displayed. We can notice that the cells are formed by small hills in the topographic model. We can also notice that the image is very noisy.

1. from ia870 import *
3. a = adreadgray('corneacells.tif')
4. adshow(a,'input')
5. b = iagsurf(a)
6. adshow(b,'surface view')


surface view

Filtering and cell detection

The image is filtered by an alternating sequential filtering with size 2. This filter is composed by openings and closings, removing small peaks and valleys. Next, the regional maxima are detected. For illustrative purpose, they are displayed overlayed on the topographic image view. These regional maxima are the markers for each cell. If anything goes wrong in this step, the error will be propagated throughout the process.

1. c = iaasf(a,'oc',iasecross(),2)
2. d = iaregmax( c)
3. adshow(iagsurf(c),'filtered, surface view')
4. adshow(iagshow(iagsurf(c), d),'with markers')

filtered, surface view

with markers

Find the background marker

Following the paradigm of segmentation by watershed, the background marker is detected by applying the constrained watershed on the negation of the cells image using the markers detected in the last step. These watershed lines partition the image in regions of influence of each cell. For illustrative display, the negative of the cell image is displayed overlayed by the markers on the left, and also overlayed by the watershed lines on the right.

1. e = ianeg(a)
2. f = iacwatershed(e, d, iasebox())
3. adshow(iagshow(e,d))
4. adshow(iagshow(e,f,d))

Labeling the markers and gradient

As the internal and external markers can be touching, we combine the external marker with value 1 with the labeling of the internal markers added by 1. The labeled marker image is shown on the left. The final watershed will be applied on the gradient of the original image, which is shown on the right.

01. import ia636 as ia
02. g = iagray(f, 'uint16', 1)
03. print 'g', ia.iaimginfo(g)
04. gr = ialabel(d)
05. print 'gr',ia.iaimginfo(gr)
06. h1 = iaaddm(gr, uint16(1))
07. print 'h1', ia.iaimginfo(h1)
08. h = iaintersec(iagray(d,'uint16'), h1)
09. print 'h', ia.iaimginfo(h)
10. i = iaunion( g, h)
11. print 'i', ia.iaimginfo(i)
12. adshow(iaglblshow(i))
13. j = iagradm( a)
14. adshow(ia.ianormalize(j))
g <type 'numpy.ndarray'> (256, 318) uint16 0.000000 1.000000
gr <type 'numpy.ndarray'> (256, 318) int64 0.000000 195.000000
h1 <type 'numpy.ndarray'> (256, 318) int64 1.000000 196.000000
h <type 'numpy.ndarray'> (256, 318) uint16 0.000000 196.000000
i <type 'numpy.ndarray'> (256, 318) uint16 0.000000 196.000000

Constrained watershed of the gradient from markers

Apply the constrained watershed on the gradient from the labeled internal and external markers. Show the watershed lines on the left and the results overlayed on the original image, on the right.

1. k = iacwatershed(j, i)
2. adshow( k)
3. adshow( iagshow(a, k, k))