Demo iadcalc

Extract the keys of a calculator.

Description

This procedure detects the keys in a gray-scale image of a calculator. The approach used is watershed Beucher's paradigm. The internal markers are the numbers on the keys and the external markers are obtained by the skiz of the keys background.

Script

Reading

The gray-scale image of the calculator is read.

1. from ia870 import *
2. 
3. a = adreadgray('keyb.tif');
4. adshow(a);

Gradient image

The image edges are enhanced by the gradient operator.

1. b = iagradm(a, iasebox());
2. adshow(b);

Inside marker: Opening top-hat

The opening top-hat procedure enhances the small objects relatively to its background. In the calculator image, the digits are enhanced.

1. c = iaopenth(a,iasebox(5));
2. adshow(c);

Inside marker: Thresholding

The threshold operator is used to separated the enhanced objects. This procedure is quite robust, since the background was reduced to very low levels with the opening top-hat.

1. d = iathreshad(c, uint8(150));
2. adshow(d);

Inside marker: Final

In order to have just one object (i.e., connected component) inside each key, a dilation is applied.

1. e = iadil(d, iasebox(3));
2. adshow(e);

Outside markers

The outside markers are built by taking the watershed (skiz) of the complement of internal markers image.

1. f = iawatershed(ianeg(e));
2. adshow(f);

Both markers

The markers used are the union of the internal and external markers detected. They are displayed as overlay on the gradient image.

1. g = iaunion(e,f);
2. adshow(iagshow(b,g));

Constrained watershed

The calculator keys are extracted by applying the watershed operator on the gradient image, constrained by the markers detected.

1. h = iacwatershed(b,g,iasebox());
2. adshow(h);

Show the result

Superposition of the detected contours on the input image.

1. adshow(iagshow(a,h));