[mmdPcb] [Up] [mmdPotatoes] Demonstrations

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

## Illustrated Source Code

The binary image of the pieces is read.

```Image a = mmBinary(mmReadgray("pieces_bw.tif"));
mmShow(a);
```

### Contour noise reduction

A thickening that preserves the number of connected objects is applied to reduce contour noise.

```unsigned char _rA[9] = {0,1,0,1,0,1,0,0,0};
unsigned char _rB[9] = {0,0,0,0,1,0,0,0,0};
Strel seA = mmImg2se(Image(3,3,1,"binary",(char *)_rA));
Strel seB = mmImg2se(Image(3,3,1,"binary",(char *)_rB));
Interval iAB = mmSe2hmt(seA,seB);
printf("%s\n", (char *)mmIntershow(iAB));
Image b = mmThick(a, iAB);
mmShow(b);
```

```. 1 .
1 0 1
. . .```

### Skeleton

The homotopic skeleton by thinning is created.

```Image c = mmThin(b);
mmShow(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.

```Image d = mmThin(c,mmEndpoints());
mmShow(c,d);
```

### Detect rings

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

```Image e = mmInfrec(d,b);
mmShow(e);
```

### Rings in the input image

Restriction of the objects detected to the input-image.

```Image f = mmIntersec(a,e);
mmShow(f);
```

### Skeleton of the remaining objects

It eliminates the skeleton of the rings.

```Image g = mmSubm(c,e);
mmShow(g);
```

### End points filtering

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

```Image h = mmThin(g, mmEndpoints(), 4);
mmShow(h);
```

### T-pins markers

It detects triple points, applying the union of matchings with the template rotated 90 degrees. These points will identify (mark) the T-pins.

```unsigned char _sA[9] = {0,1,0,1,1,1,0,0,0};
unsigned char _sB[9] = {1,0,1,0,0,0,0,1,0};
Strel seA2 = mmImg2se(Image(3,3,1,"binary",(char *)_sA));
Strel seB2 = mmImg2se(Image(3,3,1,"binary",(char *)_sB));
Image i = mmSupcanon(h, mmSe2hmt(seA2,seB2));
mmShow(h,mmDil(i,mmSedisk(2)));
```

### Detect T-pins

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

```Image j = mmInfrec(i,b,mmSebox());
mmShow(j);
```

### T-pins in the input image

Restriction of the objects detect to the input image

```Image k = mmIntersec(a,j);
mmShow(k);
```

### Detect nails

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

```Image l = mmSubm(mmSubm(a,f),k);
mmShow(l);
```

### Color composition

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

```Image m = mmGray(f,"uint8",1);
Image n = mmGray(k,"uint8",2);
Image o = mmGray(l,"uint8",3);
Image p = mmUnion(m,n,o);
mmLblshow(p);
```

 [mmdPcb] [Up] [mmdPotatoes] User Feedback Copyright (c) 1998-2008 by SDC Information Systems