Detect defects in a ruler.
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.
The gray-scale image of the ruler is read.
1. a = adreadgray('mm3.tif') 2. adshow(a)
The close top-hat operator followed by a thresholding is applied.
1. from ia870 import iacloseth 2. from ia870 import iasebox 3. 4. 5. b = iacloseth(a,iasebox(5)) > 40 6. adshow(b)
The vertical lines longer than 50 pixels are detected.
1. from ia870 import iaopen 2. from ia870 import iaseline 3. 4. 5. c = iaopen(b,iaseline(50,90)) 6. adshow(c)
Ruler tick marks filtering
It closes ruler tick marks gaps.
1. from ia870 import iaclose 2. 3. 4. d =iaclose(c,iaseline(15)) 5. adshow(d)
Ruler tick marks connection
It detects all objects connected to the ruler tick markers.
1. from ia870 import iainfrec 2. 3. e = iainfrec(d,b) 4. adshow(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.
1. f = iainfrec(d,b,iaseline(3,90)) 2. adshow(f)
Non ruler tick mark vertical connection
The residues obtained from the previous image.
1. from ia870 import iasubm 2. 3. g = iasubm(e,f) 4. adshow(g)
Ruler tick marks detection
It uses an opening by an elementary cross structuring element to eliminate the artifacts.
1. h = iaopen(g) 2. adshow(h)
It detects the objects connected to ruler tick marks. A reconstruction from the ruler marks detected is applied.
1. i = iainfrec(h, b) 2. adshow(i)
Overlay the detected defect over the original image
1. import ia870 2. adshow(ia870.iagshow(a,i))