# mmdcalc
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.

## Demo Script

### Reading

The gray-scale image of the calculator is read.

    >>> a = mmreadgray('keyb.tif');

    >>> mmshow(a);

a |

### Gradient image

The image edges are enhanced by the gradient operator.

    >>> b = mmgradm(a, mmsebox());

    >>> mmshow(b);

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.

    >>> c = mmopenth(a,mmsebox(5));

    >>> mmshow(c);

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.

    >>> d = mmthreshad(c, uint8(150));

    >>> mmshow(d);

d |

### Inside marker: Final

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

    >>> e = mmdil(d, mmsebox(3));

    >>> mmshow(e);

e |

### Outside markers

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

    >>> f = mmwatershed(mmneg(e));

    >>> mmshow(f);

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.

    >>> g = mmunion(e,f);

    >>> mmshow(b,g);

b,g |

### Constrained watershed

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

    >>> h = mmcwatershed(b,g,mmsebox());

    >>> mmshow(h);

h |

### Show the result

Superposition of the detected contours on the input image.

    >>> mmshow(a,h);

a,h |

[`mmdbrain`] [Up] [`mmdcells`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.