Defects Detection in PCB Images by Scanning Procedure, Flood-filling
and Mathematical Comparison
ROMAN MELNYK, ANDRII SHPEK
Software Department,
Lviv Polytechnic National University,
12 Stepan Bandera St., Lviv, 79013,
UKRAINE
Abstract: - The basis of the approach is a scanning procedure with the movement of windows on the printed
circuit board to detect defects of various types. Mathematical image comparison, pixel distribution histograms,
padding algorithms, statistical calculations, and histogram deviation measurements are applied to the small
parts of the PCB image in a small window area. The paper considers K-mean clustering of pixel intensities to
simplify the printed circuit board image, separation of elements on the printed circuit board image by filling
with colors, determination of defect intensity, and subtraction formulas.
Key-Words: - Scanning, printed circuit boards, chains, defects, clustering, flood-filling, pixel histogram,
statistical features, greyscale, tolerance.
Received: February 13, 2023. Revised: November 22, 2023. Accepted: December 12, 2023. Published: December 31, 2023.
1 Introduction
Scanning methods are used in various scientific
studies. The purpose of their research is to increase
the amount and accuracy of data for designing and
researching objects. As a rule, special devices based
on lasers, ultrasound, and X-ray machines are used
for scanning. The data is collected effectively via
laser-scanning microscopy, or they are used for
image-recognition algorithms in the context of post-
fabrication defect detection, [1], [2]. Such devices
and algorithms are inserted into powerful software
classifying faults in different surface boards, [3],
[4].
The main advantage of scanning is the relative
increase in the area with the objects of attention due
to the rejection of the prevailing other surroundings.
That is why scanning is applied to problems of
defect detection in printed circuit boards.
For inspection of inaccuracies in PCB
production, neural networks are used and described
in articles, [5], [6], [7], [8], [9]. Other works contain
subtraction algorithms, [10], [11], [12]. The earlier
article uses a table of connection traces based on
contacts from the etalon image, [13]. Defects in
traces and contacts of such types as shift, and extra
metal are not analyzed.
The surveys contain many references in
publications describing approaches and methods for
the detection and classification of defects in printed
circuit boards, [14], [15]. The main ideas of]
subtraction of images, defects extraction, thinning,
and increasing the visibility of elements on the
board are considered in the works, [16], [17], [18].
The subtraction operations between PCB images are
sensible to a deviation of the sizes of traces and
contacts from the etalon. They give extra or lacking
pixels that do not affect the correct operation of the
electrical scheme.
Short, open circuits and depression changes in
computer vision and artificial intelligence inspection
systems are subjects in publications, [19], [20]. All
mentioned approaches differ between themselves by
complexity, input data, and characteristics of their
implementation.
In this paper, the following approaches are
applied to solving the problem: principles of
scanning windows on the board, mathematical
formulas of comparison, histograms of pixels from
the OX and OY axes, the filling algorithm for
dividing and selecting chains, the K-means
clustering algorithm, formulas for calculating the
statistical characteristics of circuit components.
The advantages of the proposed method are the
detection of three classes of defects: connection,
excess, and lack of metal on tracks and contacts.
Areas with found defects are marked with colored
zones directly in the places of their permanent
location. This creates the possibility of additional
analysis of suspicious areas of the installation for
repairability or complete failure.
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
206
Volume 22, 2023
2 Determination of Defect Intensity
Some examples of PCB defects that often occur are
shown in Figure 1. They are short, open, incorrect
sizes, and various inaccuracies of contacts.
Fig. 1: Three types of defects: short and open (a),
sizes and inner defects (b), extra or lacking metal (c)
Some of these types of defects are presented on
manufactured PCB samples. An example of the
PCB image with four defects is shown in Figure 2.
They are marked by serial numbers. Open (4) and
short (3) defects are made by very thin black and
white lines of the one-pixel width. Two contacts
(1,3) are deformed by a lack of metal.
Fig. 2: PCB image with four defects
To measure these defects two histograms of
pixels on the OX or OY axis are calculated for the
reference and defective PCB images. The numbers
of pixels in columns or rows are calculated for the
interval of intensity
(int)I
=0÷10 as follows in the
formulas:
( ) {( , ) ( , ) (int)},
( ) {( , ) ( , ) (int)},
( 0,1, ..., ; 0,1, ..., ).
h c card x y I x y I
h r card x y I x y I
c w r H



An example of defects affecting the quantitative
histogram function in a column is demonstrated by
the graphs in Figure 3. The graphs are calculated for
reference and defective PCB images in the
intensity 0÷10 interval. Only two very small
differences mark defects 3 and 4. The contribution
to the graph from all four defects is very small. For
the row function, the difference is even smaller.
Fig. 3: Two histograms of black pixels in two PCB
images along the OX axis
The reason is that the number of pixels reflecting
defects is very small compared to the number of
white or black pixels of the whole image. Even
having the reference image, they are superimposed
on the inaccuracies of manufacturing PCBs.
The opposite case is observed when only two
chains or their fragments are measured by the
number of pixels. Examples of the two fragments
and their histograms along the OY axis are shown in
Figure 4. Values differ by 20-40 percent due to the
location of the defect and by 2-4 percent due to
different widths of traces.
a b
Fig. 4: PCB fragments (a) and histograms of black
pixels along the OY axis (b)
3 Comparison Formulas for Detection
and Separation of Defects
Traditionally, defects in the PCB image are detected
by XORing the binary images. The XOR operations
with pixels are as follows:
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
207
Volume 22, 2023
0 ^1 1, 1^ 0 1, 0 ^ 0 0, 1^1 0,
where
denotes white and
1
denotes black or vice
versa.
These operations show the inaccuracies and
defects of the manufactured printed circuit board
about the reference sample. Surpluses and shortages
of metal on tracks and contacts belong to one class.
To separate positive and negative defects,
subtraction operations are applied to the binary
images:
, , ,
Such operations are repeated twice: until a
positive and negative result is obtained. Different
results are achieved by exchanging the input images
after the first subtraction. The resulting images
contain white areas and lines representing various
types of defects. Two examples of result images
from [8], are shown in Figure 5. Two input binary
PCB images are not shown because only results are
presented for comparison with the below-following
approach.
Fig. 5: Images after subtraction of binary PCB
images
The results obtained are not good enough in
terms of the location, size, and intensity of the white
figures. The main drawback is their separation from
the elements of the scheme. It is a significant
problem, especially for the printed circuit boards of
large sizes.
That is why a new approach has been developed
to increase the visibility of defective pixels. It is
used for their separation, determination of
coordinates, visual inspection of defects, and future
application of neural networks. The separation is
both from structural elements and between classes
with excess and shortage of metal.
When two images are compared, they are input
data for the following comparison formulas:
( , ) ( , ) | ( , ) ( , ) |
r d e d
I x y I x y I x y I x y Tol
,
)(),00|,),(),((|),( redyxIyxIRGByxI der
TolyxIyxI de |),(),(|
,
and a sign is +,
)(),0|,),(),(|,0(),( blueyxIyxIRGByxI der
( , ) ( , ) ,
de
I x y I x y Tol
and a sign is -,
where
),( yxIr
is the pixel intensity of the resulting
image,
),( yxIe
is the pixel intensity of the first
image,
),( yxId
is the pixel intensity of the second
image,
Tol
is the tolerance value for controlling
the difference between the pixel intensity of the
etalon and controlled sample.
The comparison formula is applied to the etalon
and the PCB image with four defects. The marked
defects with blue and red in the difference between
them are shown in Figure 6. The short defect is blue,
and the shortage of metal is marked with red
(including the open defect).
Fig. 6: Difference image with four marked defects
Every type of defect has its color (intensity).
Thus, for them, a histogram of pixels on the OX or
OY axis is applied. The colors (blue and red) are of
29 and 79 intensities. So, for these points of
intensity from the interval 29-79, the numbers of
blue and red pixels in columns are calculated and
shown in Figure 6.
The number of blue pixels is small about the
number of red pixels. The histogram reflects the
relative numbers of pixels. That is why values for
blue pixels are small. It is convenient to use the
cumulative histogram for calculations:
,,...,2,1,,...2,1
,)()(,)()(
11
HrWc
rhrHchcH i
kki
i
kki
The cumulative histogram together with its
piecewise linear approximation is shown in Figure
8.
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
208
Volume 22, 2023
Fig. 7: Histogram of blue and red pixels in PCB
image by the OX axis
When approximating the cumulative histogram
by the piecewise linear function the obtained points
in Figure 8 indicate the amount of red and blue
pixels. Concretely, a vertical difference of the
ordinate values gives the relative number of pixels
with a defined OX coordinate.
Fig. 8: Cumulative histogram and its approximation
of red and blue pixels in PCB image by the OX axis
There are four groups of pixels having the
following numbers:
)7()8(),4()3(
),6()5(),1()2(
43
21
HHNHHN
HHNHHN
,
where N1,.. and N4 are amounts of red and blue
pixels distributed within the coordinates on the OX
axis.
When three graphs built by their scales are
presented in one field the axis OY reflects only the
maximal interval of one graph and shows the
relative values. They are different in the different
measurements. It is demonstrated in Figure 9.
;
Fig. 9: Three histograms in PCB image along the
OX axis: for black (grey), blue (yellow), and red
(violet) pixels
The experiment confirms that for the separation
of pixels, different histograms are needed to
measure different types of defects. In both cases, the
actual number of blue and red pixels is considered.
This number is calculated from cumulative
histograms or by the following formulas:
),(*)()(),(*)()(
1111
sKsSblueNrKrSredN i
Nc
i
Nc
where
)(),(sSrS
are the numbers of pixels in the
whole etalon and sample images,
)(),(sKrK ii
are the
relative numbers of pixels in one column,
c
N
is the
number of columns containing red (blue) pixels.
The interval must be indicated because error
values are very small, and the number of black
pixels is very large.
They are also very small for the interval as this is
shown in Figure 2 where absent pixels in defective
places are almost invisible. There is one way to
increase the visibility of pixels indicating blue and
red pixels of defects. The relative weight of
defective pixels must be increased, and the relative
weight of surrounding pixels must be decreased. It
can be reached by decreasing the area for
measurement. One of the possible approaches is to
measure consequently quantitative characteristics of
parts of the PCB image to be compared by the
scanning procedure.
4 Scanning Procedure
In the scanning process, two input images are
covered with the same grid at the step of the user.
The image with marked defects covered with a 5x3
grid is shown in Figure 10.
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
209
Volume 22, 2023
Fig. 10: Defective PCB image covered by 15 cell-
windows
Then all corresponding pairs of rectangles in the
input and defective PCB images are compared by
one of the developed approaches. For the 5x3 grid
such operations are repeated 15 times.
To reduce the influence of the positions of the
grid lines on the results of calculation the PCB
image is covered by a sequence of rectangles with
intersecting areas. The sequence is built when the
rectangle window scans the surface of the image.
Then informative pixels are included into rectangles
two times. Figure 11 shows two not intersected and
two intersected windows: in the first case, the
second window does not contain the defect together
with the contact, the second window contains them.
The intersected area is marked with an orange color.
a b
Fig. 11: Two windows of different sizes in the
image: not intersected (a), intersected (b)
The comparison procedure repeats its work step
by step covering the whole image area in a sequence
of the smaller areas. Intersection occurs on the right
(left) and down (top) borders of the scanning
rectangle (Figure 12). Twice intersected areas are
marked with a pink color. Areas belonging to four
scanning windows are marked with a red color.
Only four scanning windows are shown in Figure
12.
Fig. 12: Four scanning windows on the board
Every window is analyzed as being fully
independent. Previous and subsequent data are not
considered. The sizes of windows and intersections
are set by the user given the need for accuracy and
time consumption.
Examples of three fragments with defects are
shown in Figure 13. These fragments are input data
for scanning windows. Defects are marked with red
and blue colors.
a b c
Fig. 13: Three fragments with defects: short (a),
open (b), and lack of metal (c)
Measurement of defects is made by calculation
of two histograms like those given in Figure 7.
Histograms are data for the determination of the
numbers of blue and red pixels separately according
to their intensity:
cr
.
The criterion function is built to check possible
defects of any type in the examined fragment of the
printed circuit board in the window according to the
formulas:
},{
;....,2,1,)()({)(
tolDDsortD
wiiHiHwD
ffs
srf
,
where
)(),(iHiH sr
are the histogram values of the
reference and sample images in the window,
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
210
Volume 22, 2023
fs DD ,
are the function values in sorted and
unsorted arrays, and tol is the tolerance value to
control the intensity of marked inaccuracies on the
board.
After the scanning process is completed, all
windows are characterized by the coordinates and
values of the criterion function stored in the
array Ds. The array is sorted in ascending order.
Windows with features exceeding the tolerance are
superimposed on the red or blue image. The color
depends on the type of defect: lack of metal on the
board with a red rectangle, excess metal on the
board with a blue rectangle. An overlay is realized
by the following formula applied to every channel
of the pixel:
),(),()1(),(),( ryxIyxIyxI iiibiicr
where Ir, Ic, Ib are the pixel intensity of the resulting,
colored, and printed board images, α is the
coefficient of transparency.
Scanning the defective image in Figure 2 reveals
all four defects that were not present in the PCB
reference image. The result is shown in Figure 14.
Fig. 14: Four places with defects after scanning
The red rectangles of different intensities contain
the locations of four defects: open, short, and metal-
free in the contacts. The intensity of blue and red
colors is proportional to the value of the criterion.
The types of defects are not defined.
5 Connection Defects Detection
The scan detects defect locations and visually
illustrates their intensity. But that doesn't answer the
question “Is there a connection defect? And if so,
what type? The following approach provides such
an answer.
A flood-filling algorithm is used to separate and
compare connected circuits on the reference and
fabricated PCB images with short and open defects.
For example, they are marked with different colors
and shown in Figure 15 and Figure 16. Four
histograms for them are calculated and shown in
Figure 17 and Figure 18.
Fig. 15: Input flood-filled image
Fig. 16: Flood-filled image with defects
The two filled images contain the same
components with different colors. The reason is that
the second image contains open and short defects
that provoke changes in the distribution of pixels.
The second reason is that a special procedure is
needed to find the starting points belonging to the
same chains on both PCB images.
To detect connection defects, it does not matter
what colors the circuits are filled with.
As a rule, if the number of components is
different, there is a connection defect in the circuit.
Sometimes two defects can be observed if the
number of components is the same as in the input
image. In this case, an open defect is compensated
by a short defect.
Calculation of the number of pixels in all circuits
of the input image of the printed circuit board gives
the following distribution (in percentages) of the
components: 0.5 (5), 1.4 (2), 3.4, 3.5, 4.8. This
distribution is related to the total number of pixels in
the image. It is calculated by traversing the pixels of
the image matrix to form the ordinary and
cumulative histograms.
The image of the defective printed circuit board
gives the following distribution (in percentages) of
the components: seven as in the reference image 0.5
(5), 1.4 (2), and three as the new components 1.6,
1.8, 8.4. The new values 1.6 and 1.8 correspond to
the broken chain 3.4. The combined chains 3.5, and
4.8 correspond to the value 8.4. Thus, three new
components were created.
This fact is illustrated by the two cumulative
histograms in Figure 17. The blue histogram
belongs to the input image and the red histogram
represents the defective image. Each histogram has
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
211
Volume 22, 2023
ten steps representing ten components. The step’s
height corresponds to the number of pixels. The OX
coordinates indicate the intensity values of the
components. Two histograms do not coincide due to
the different colors of the same components in two
images, and three different components.
Fig. 17: Cumulative histograms of two flood-filled
images: input (blue) and with defects (red)
The component distributions found are the basis
for detecting connection defects. Among other
methods, simply comparing elements from two
arrays and eliminating similar components answers
two questions: Are there any connectivity defects in
the region? And "What circuits cause these
defects?"
Each component has its identification number
and color. The colors selected in the fill algorithm
do not affect the number of steps in the cumulative
histogram but only change their distribution on the
OX (intensity) axis. The main requirement is that
they be different. That way, when found, they can
be selected and showcased.
To illustrate how colors change the pitch
distribution, two cumulative histograms are
calculated only for the reference PCB image. But
once components are with one set of colors and then
they are redrawn into the second set of other colors.
The first histogram is marked in red and the second
in blue, and they are shown in Figure 18. The
coordinates of the steps do not coincide.
Fig. 18: Cumulative histograms of two flood-filled
images: input (blue) and input with other colors
(red)
Each window represents a cropped part of the
printed circuit board image in the scanning process.
Three examples with different defects are fragments
of the entire PCB image. Using the filling algorithm,
the black components of these parts are redrawn
with different colors, and shown in Figure 19.
a b c
Fig. 19: Three fragments with defects: short (a),
open (b), and lack of metal (c)
Calculation of the number of pixels in all circuits
of the input image of the printed circuit board gives
the following distribution (in percentages) of the
components: Figure 11a) for the standard 0.034,
0.116, 0.04; for sample 0.04, 0.150; Figure 11b) for
the standard 0.042, 0.071, 0.030; for the sample
0.007, 0.065, 0.029, 0.042; Figure 11c) for the
standard 0.062, 0.062, 0.062; for the sample 0.056,
0.061, 0.061.
The number of components in the sample is
changed: reduced to two instead of three in the
reference image (Figure 19a) and increased to four
instead of three in the image (Figure 19b). In the
first case, there is a short defect and in the second -
an open one. In Figure 19c no connection defect.
Only the lack of metal is captured by quantitative
analysis, which is detected and measured in the
previous approach.
Mathematically, the problem is solved in two
ways. In the first, the average size (number of
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
212
Volume 22, 2023
pixels) in one window is calculated using the
following formulas:
}),(),,{( jj CyxIyxcardS
,
,,...,2,1,/1 cjc NjSNS
where I(x,y) is the intensity of pixels in the j-th
component with its color, Cj is the color of the j-th
component, Nc is the number of components.
The variance or mean standard deviation of the
calculated function is used to estimate changes in
the component sizes in each window:
2
1
2))( )(()/1()w( wSwSNE i
N
i
c
,
where
)(wS
is the mean size of components in the
w-th window,
)(wSi
is the size of the i-th
component in the w-th window,
)a(
2
E
is the
variance value of the corresponding window,
)(wE
is the standard deviation.
For the above-described examples, these
parameters are as follows.
1) The reference images:
)(aS
=0.063,
)a(
2
E
=0.001393,
)(aE
=0.037.
)(bS
=0.047,
)b(
2
E
=0.000281,
)(bE
=0.017.
)(cS
=0.062,
)(
2cE
=0.0,
)(cE
=0.0.
2) The sample images:
)a(
2
E
=0.003025,
)a(E
=0.055.
)b(
2
E
=0.000464,
)b(E
=0.022.
)(
2cE
=0.000006,
)c(E
=0.002.
The first two variances of the controlled PCB
images are larger than the etalon. In the latter case,
the deviation changes are significantly smaller than
in previous experiments due to a very small defect
of the contact.
In conclusion, open and short defects cause the
component size variance to change its value. The
tolerance value divides these changes into two
classes: insignificant due to inaccuracies and
significant due to connection defects.
The second approach is also simple and accurate.
It requires some mathematical calculations.
The components of the printed circuit board
image contain many pixels, which are characterized
by various distributed features. Among them, the
average coordinates of the component are as
follows:
)(/1( sXks)xs
,
)(/1( sYks)ys
,
)(),(sYysXx ii
where s is the component number, X, Y are sets of the
pixel coordinates.
To obtain a parametric feature associated with
pixel coordinates, the surface of the pattern is
divided by a grid with steps along the OX and OY
coordinates as shown in Figure 20. The grid cells
are numbered as 1, 2, …, Lx*Ly from left to right
and down from the top of the grid, where Lx, Ly are
the column and row numbers on the OX and OY
axes.
a b
Fig. 20: Two PCB fragments covered by a grid:
without defects (a), open defect (b),
The grid step is selected as a tolerance value when
comparing two windows containing the reference part
of the PCB image and the part of the controlled PCB
image.
Each pixel with the average coordinates x
(s), y
(s) is
associated with the cell number Cn and its coordinates
by the corresponding formulas:
1)/(( ceilx
Ls)xi
,
1)/(( ceily
Ls)yj
.
jLiC xn *)1(
For images in Figure 20 characteristics of cell
numbers are represented by two diagrams in Figure
21. Two coordinate axes are the cell number 0÷Cn
and the intensity interval 0÷255.
a b
Fig. 21: Number of cells containing average
coordinates of components: etalon image (a),
sample image (b)
In Figure 21a the cell ordinates are 19, 33, and
40. In Figure 21b, the four ordinates of the cells are
18, 28, 33, and 40. All these cells are marked with
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
213
Volume 22, 2023
colors in the corresponding grids in Figure 20. On
both diagrams in Figure 21 the identical ordinates
are indicated by two parallel lines. Thus, one
component of the reference image is split into two
components. The conclusion is made that an open
defect is in the current window.
The final function of the criterion is built from
the two components: the difference in the variances
of the component sizes on the two parts of the
different boards and the difference between the cell
numbers with the average coordinates of the
components of the two boards. It is built to check
for possible existing connection defects in the
examined fragment of the printed circuit board
according to the formula:
tolsCrCwEEwF ni
K
ni
sr
)()({
11
2
22
1
,
where
),( rrni jiC
),( ssni jiC
are the numbers of the
rows and columns of the two cells containing the
average coordinates of components,
sr EE 22 ,
are
the variances of the component sizes,
21,ww
, are the
weighting factors. Summing up takes place by all
components; K is their number.
The weighting factors play an important role
because the order of values in the two terms is
different. When the second term is nonzero, the
monitored sample has a new component, or some
component is shifted. At the end of the procedure,
this part of the PCB image is marked as defective.
6 Full Colored Images
An example of the printed circuit board image with
two defects (broken and short) is shown in Figure
22. The image has three main colors: a dark green
background, green traces, and yellow contacts.
Fig. 22: Fragment of the PCB image with green
routes and yellow contacts
Mathematical formulas are calculated to compare
both images: the original in full color and grayscale
to detect the pixels that mark defects. The results are
shown in Figure 23. The number of red and blue
pixels is very small in each image, and it does not
affect the calculated function based on the pixel
intensity.
a b
Fig. 23: Fragments of image difference: full color
(a), grey gradations (b)
It is also difficult to separate these pixels because
their intensity values are the same as the intensity
values of the surrounding pixels according to the
interval 0÷255. Examples are shown in Figure 24.
Fig. 24: Intensity levels containing red and blue
pixels
Better results are achieved when the greyscale
image is clustered. Pixels in clusters have the same
color, and pixels of other colors are easy to separate.
Figure 25 shows three and two groups of pixels in
K=3 and K =2 cluster images. The first image
contains three groups of pixels: contacts, traces, and
backgrounds. The second image contains the
background and the chains with the contacts.
a
b
Fig. 25: Fragments of the defective PCB image:
three clusters (a), two clusters (b)
Then mathematical formulas of the comparison
are applied to the clustered images: the etalon and
sample. Fragments after their logical subtraction are
shown in Figure 26. The blue area is very small.
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
214
Volume 22, 2023
a b
Fig. 26: Fragments after comparison of the etalon
PCB image with the sample image: three clusters
(a), two clusters (b)
Red and blue pixels indicate open and short
defects in the full-color and grayscale images. They
are very small and almost invisible. However, they
are easy to separate and calculate because their
intensity values are significantly different from
those of all other objects on the board. Examples of
histograms for the number of red and blue pixels in
columns are shown in Figure 27.
Fig. 27: Histograms of blue (blue) and red pixels
(yellow)
These histograms are characteristics of the scan
window. They are the input data to calculate the
total number of red or blue pixels in the window:
),(*)()(),(*)()(
1111
sKsSblueNrKrSredN i
Nc
i
Nc
where
)(),(sSrS
are the numbers of pixels in the
entire etalon and sample images,
)(),(sKrK ii
are the
relative numbers of pixels in one column,
c
N
is the
number of columns containing red (blue) pixels.
In addition, the clustered images are suitable for
finding connectivity defects, since the colors of the
board objects are uniform, and suitable for filling
algorithms.
One feature of clustered images should be
considered. For the three formed clusters, contacts
and traces are separate objects. With two clusters,
contacts in combination with traces are considered as
one object. When applying the filling algorithm, the
first case is shown in Figure 28a, and the second in
Figure 28b.
a b
Fig. 28: Filling in fragments of PCB image: three
clusters (a), two clusters (b)
In the case of three clusters, the lack of metal
cannot be classified as a connection defect because
it is between components of different colors. From
this point of view, two clusters in the image are a
simpler and more reliable mechanism for further
processing.
7 Experiments
Three approaches are realized for testing and
comparing their effectiveness. They are 1)
calculation of two histograms for the etalon and
sample PCB images, 2) calculation of one histogram
for red and blue pixels obtained from the
mathematical comparison of the input images, 3)
calculation of statistical features (variance and
average coordinates) for components in two
windows.
The developed algorithms are tested on different
types of images. Three images of the following
dimensions 440x140, 650x480, and 740x640 are
input data for the developed software. Two clustered
greyscale and one full-color image were taken for
the experiments. In all cases, open and short defects
are detected by scanning with nearly 1500 windows.
The results are shown in Figure 29.
a
b
Fig. 29: PCB images after scanning: greyscale (a),
full color (b)
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
215
Volume 22, 2023
The next PCB image has contacts of a grey
color, and the board surface is fully covered by
conducting metal (Figure 30). One contact is
defective. The dimension of the scanning window is
30x20 with a cross-section of 10 along the OX axis
and 5 along the OY axis. Nearly 6000 windows
were analyzed with these initial conditions.
Fig. 30: PCB image after scanning
The third experiment is with the largest full-color
PCB image shown in Figure 31. It has two defective
contacts with extra metal. More than 7000 windows
were analyzed to find and mark areas containing
contacts with defects.
Fig. 31: PCB image with integrated circuits after
scanning
All image transformations, calculations of
functions, and formulas are implemented in the
developed software and are invisible to the user.
The engineer controls the window sizes, the
tolerance values, and the method to be used in the
analysis.
8 Conclusion
The approach is based on a scanning procedure in
which the analysis of the entire large image is
replaced by many analyses in much smaller areas of
the printed circuit board. The analysis includes such
approaches and methods as mathematical formulas
of comparison, histograms of pixels from the OX
and OY axes, the filling algorithm for dividing
chains, the K-means clustering algorithm, and
formulas for calculating the statistical characteristics
of circuit components.
The proposed approach contains operations for
the selection of three classes of defects: negative,
positive, and connection. Marked with different
colors, these defects are designed to train neural
networks with different architectures for further
automatic detection of defects and their
classification. Together with the developed
software, they will also indicate their locations and
determine their intensity. In total, such software will
reduce the hardware and make the PCB diagnostic
process cheaper.
References:
[1] Sayed Hoseini, Gaoyuan Zhang, Alexander Jo
ngbloed, Christian Schmitz, Christoph Quix,
Automated defect detection for coatings via
height profiles obtained by laser-scanning
microscopy, Machine Learning with
Applications, Vol. 10, December 2022,
100413.
[2] S. Zhang, Z. Chen, K. Granland, Y. Tang ,C.
Chen, Machine Vision-Based Scanning
Strategy for Defect Detection in Post-Additive
Manufacturing, NICOM
2022: Nanotechnology in Construction for
Circular Economy, Lecture Notes in Civil
Engineering book series (LNCE), Vol. 356,
pp. 271–284.
[3] Zahia Guezoui, Aicha Baya Goumeidane,
Nafaa Nacereddine, Weld Defect
Radiographic Image Segmentation with Finite
Mixture Model (FMM), Engineering World,
2020, Vol. 2, pp. 134-138.
[4] Stella Vetova, Covid Image Classification
using Wavelet Feature Vectors and NN,
Engineering World, 2021, Vol. 3, pp. 38-42.
[5] Cai L., Li J., PCB defect detection system
based on image processing, Journal of
Physics: Conference Series, 2022, Vol. 2383,
No. 1. pp. 012077.
[6] S. McClure. Extracting and Classifying
Circuit Board Defects using Image Processing
and Deep Learning, Feb. 4, 2020, [Online].
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
216
Volume 22, 2023
https://towardsdatascience.com/building-an-
end-to-end-deep-learning-defect-classifier-
application-for-printed-circuit-board-pcb-
6361b3a76232, (Accessed Date: February 1,
2024).
[7] V. A. Adibhatla, H.-C. Chih, C.-C. Hsu, J.
Cheng, M. F. Abbod, and J.-S. Shieh, Defect
Detection in Printed Circuit Boards Using
You-Only-Look-Once Convolutional Neural
Networks, Electronics, Vol.9, No.9, 2020, pp.
1547.
[8] Abhiroop Bhattacharya, Sylvain G. Cloutier,
End-to-end deep learning framework for
printed circuit board manufacturing defect
classification, Scientific Reports,2022,
[Online].
https://www.nature.com/articles/s41598-022-
16302-3, (Accessed Date: February 1, 2024).
[9] Jungsuk Kim, Jungbeom Ko, Hojong Choi
and Hyunchul Kim, Printed Circuit Board
Defect Detection Using Deep Learning via A
Skip-Connected Convolutional Autoencoder,
Sensors, No.21(15), 2021, 4968.
[10] Zhu, A. Wu and X. Liu, Printed circuit board
defect visual detection based on wavelet
denoising, IOP Conference Series: Materials
Science and Engineering, Vol. 392, 2018, pp.
062055.
[11] Y. Hanlin and W. Jun, Automatic Detection
Method of Circuit Boards Defect Based on
Partition Enhanced Matching, Information
Technology Journal, Vol.12, No.11, 2013, pp.
2256-2260.
[12] Vikas Chaudhary, Ishan R. Dave and Kishor
P. Upla, S. V., Visual Inspection of Printed
Circuit Board for Defect Detection and
Classification. International Conference on
Wireless Communications, Signal Processing
and Networking (WiSPNET), 2017, pp. 732-
737.
[13] M. H.Tatibana, R. and de A. Lotufo. Novel
Automatic PCB Inspection Technique Based
on Connectivity, Proceedings X Brazilian
Symposium on Computer Graphics and Image
Processing, 1997, pp. 187-194.
[14] K. P. Anoop, N.S. Sarath and V. V. Sasi
Kumar, Review of PCB Defect Detection
Using Image Processing, International
Journal of Engineering and Innovative
technology (IJEIT), Vol.4, Is.11, 2015, ISSN:
2277-3754.
[15] D.B. Anitha, and M. Rao, A survey on Defect
Detection in Bare PCB and Assembled PCB
using Image Processing Techniques,
International Conference on Wireless
Communications, Signal Processing and
Networking, 2017, pp. 39-43.
[16] M. Moganti, F. Ercal, C. H .Dagli, and
S. Tzumekawa, Automatic PCB inspection
algorithms: A review, Computer Vision and
Image Understanding, Vol. 63, No. 2, 1996,
pp. 287-313.
[17] F. B. Nadaf and V. S. Kolkure, Detection of
Bare PCB Defects by using Morphology
Technique, Morphology Technique
International Journal of Electronics and
Communication Engineering, Vol. 9, No. 1,
2016, pp. 63-76.
[18] Y. Hanlin, W. Jun, Automatic Detection
Method of Circuit Boards Defect Based on
Partition Enhanced Matching, Information
Technology Journal, Vol.12(11), 2013, pp.
2256-2260.
[19] J. Nayaka, K. Anitha, B.D. Parameshachari,
R. Banud and P. Rashmi, PCB Fault Detection
Using Image Processing, IOP Conference
Series: Materials Science and Engineering,
Vol.225, 2017, pp. 1-5.
[20] S. Guan, F. Guo, A New Image Enhancement
Algorithm for PCB Defect Detection,
International Conference Intelligence Science
and Information Engineering (ISIE), 2011, pp.
454-456.
Contribution of Individual Authors to the
Creation of a Scientific Article (Ghostwriting
Policy)
The authors contributed in the ratio of 70 (Melnyk)
to 30 (Shpek) in the present research, at all stages
from the formulation of the problem to the final
findings and solution.
Sources of Funding for Research Presented in a
Scientific Article or Scientific Article Itself
No funding was received for conducting this study.
Conflict of Interest
The authors have no conflicts of interest to declare.
Creative Commons Attribution License 4.0
(Attribution 4.0 International, CC BY 4.0)
This article is published under the terms of the
Creative Commons Attribution License 4.0
https://creativecommons.org/licenses/by/4.0/deed.en
_US
WSEAS TRANSACTIONS on CIRCUITS and SYSTEMS
DOI: 10.37394/23201.2023.22.23
Roman Melnyk, Andrii Shpek
E-ISSN: 2224-266X
217
Volume 22, 2023