##### Contents

Decompose a printed circuit board in its main parts.

# Description

The input image is a binary image of a printed circuit board. The decomposition is created mainly using openings by structural elements that depends on the geometry of the circuit board.

# Script

The binary image of a printed circuit board is read.

```1. a = mmreadgray('pcb1bin.tif');
2. mmshow(a);```

## Detecting holes

A new image is created by filling the holes. The input image is subtracted from this new image with holes. The resulting residues are the holes.

```1. from ia870 import iaclohole
2. from ia870 import iasubm
3.
4.
5. b = iaclohole(a);
6. holes = iasubm(b,a);
7. mmshow(b);
8. mmshow(a, holes);```

## Detecting square islands

The square islands are detected using an opening by a square of size 17x17.

```1. from ia870 import iaopen
2. from ia870 import iasebox
3. from ia870 import iacdil
4.
5.
6. c = iaopen(b,iasebox(8));
7. square = iacdil(c, a);
8. mmshow(b, c);
9. mmshow(holes, square);```

## Detecting circle islands

The circle islands are detected using an opening by an Euclidean disk on a residues image.

```1. from ia870 import iasedisk
2.
3.
4. f = iasubm(b, c);
5. g = iaopen(f, iasedisk(8));
6. circle = iacdil(g,a);
7. mmshow(f, g);
8. mmshow(holes, square, circle);```

## Detecting rectangular islands

The rectangular islands are detected using an opening by a rectangle of size 25 x 8 on a residues image. The rectangle structuring element is built from the composition of vertical and horizontal lines.

```1. from ia870 import iasedil
2. from ia870 import iaseline
3.
4.
5. i = iasubm(f, g);
6. m = iaopen(i,iasedil( iaseline(8,90), iaseline(25)));
7. rect = iacdil(m,a);
8. mmshow(i, m);
9. mmshow(holes, square, circle, rect);```

## Detecting thick connections

The thick connections are detected using an opening by a square on a residues image.

```1. o = iasubm(i,m);
2. p = iaopen(o, iasebox(2));
3. thin = iacdil(p,a);
4. mmshow(o, p);
5. mmshow(holes, square, circle, rect, thin);```

## Detecting thin connections

The thin connections are detected using an opening by a square on a residues image.

```1. r = iasubm(o,p);
2. s = iaopen(r, iasebox());
3. thick = iacdil(s,a);
4. mmshow(r, s);
5. mmshow(holes, square, circle, rect, thin, thick);```

## Displaying all together

The main components of the circuit are overlayed and presented in a single image.

`1. mmshow(holes, square, circle, rect, thin, thick);`