# mmdpieces
Classify two dimensional pieces.

## Description

The input image is a binary image typically found in industrial automation applications. It has three types of objects: rings, nails and T-pins. Our procedure for identification of these classes of objects is based on thickening, thinning and reconstruction.

## Demo Script

### Reading

The binary image of the pieces is read.

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

    >>> mmshow(a);

a |

### Contour noise reduction

An homotopic thickening is applied to reduce contour noise.

    >>> seA = mmimg2se(mmbinary([[0,1,0],[1,0,1],[0,0,0]]))

    >>> seB = mmimg2se(mmbinary([[0,0,0],[0,1,0],[0,0,0]]))

    >>> iAB = mmse2hmt(seA,seB);

    >>> print mmintershow(iAB)

    . 1 .
    1 0 1
    . . .

    >>> b = mmthick(a, iAB);

    >>> mmshow(b);

b |

### Skeleton

The homotopic skeleton by thinning is created.

    >>> c = mmthin(b);

    >>> mmshow(c);

c |

### Skeleton pruning

The open lines of the skeleton are pruned by the end point thinning. The remaining skeleton components will be loops, identifying the rings.

    >>> d = mmthin(c,mmendpoints());

    >>> mmshow(c,d);

c,d |

### Detect rings

Extraction of the rings by reconstruction of the thicked image from the filtered skeleton.

    >>> e = mminfrec(d,b);

    >>> mmshow(e);

e |

### Rings in the input image

Restriction of the objects detected to the input-image.

    >>> f = mmintersec(a,e);

    >>> mmshow(f);

f |

### Skeleton of the remaining objects

It eliminates the skeleton of the rings.

    >>> g = mmsubm(c,e);

    >>> mmshow(g);

g |

### End points filtering

It removes sucessively 4 end-points to let T junctions just on T-pins.

    >>> h = mmthin(g, mmendpoints(), 4);

    >>> mmshow(h);

h |

### T-pins markers

It detects triple points, applying the union of matchings with two templates. These points will identify (mark) the T-pins.

    >>> seA1 = mmimg2se(mmbinary([[0,1,0],[0,1,0],[1,0,1]]))

    >>> seB1 = mmimg2se(mmbinary([[0,0,0],[1,0,1],[0,1,0]]))

    >>> seA2 = mmimg2se(mmbinary([[0,1,0],[1,1,1],[0,0,0]]))

    >>> seB2 = mmimg2se(mmbinary([[1,0,1],[0,0,0],[0,1,0]]))

    >>> i1 = mmsupcanon(h, mmse2hmt(seA1,seB1));

    >>> i2 = mmsupcanon(h, mmse2hmt(seA2,seB2));

    >>> i = mmunion(i1,i2);

    >>> mmshow(h,mmdil(i,mmsedisk(2)));

h,mmdil(i,mmsedisk(2)) |

### Detect T-pins

Detection of the T-pins by reconstruction of the ticked image from the T-pin markers.

    >>> j = mminfrec(i,b,mmsebox());

    >>> mmshow(j);

j |

### T-pins in the input image

Restriction of the objects detect to the input image

    >>> k = mmintersec(a,j);

    >>> mmshow(k);

k |

### Detect nails

The nails are imediatly detected by the subtration of the images of the rings and T-pints from the input image.

    >>> l = mmsubm(mmsubm(a,f),k);

    >>> mmshow(l);

l |

### Color composition

The result of the classification is presented in a pseudo color image.

    >>> m = mmgray(f,'uint8',1);

    >>> n = mmgray(k,'uint8',2);

    >>> o = mmgray(l,'uint8',3);

    >>> p = mmunion(m,n,o);

    >>> mmlblshow(p);

p |

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