Professional Documents
Culture Documents
between
is chosen as threshold. The bet+een1class /ariance is defined b! the
follo+ing e2uations7
between
2
=
dark
(
dark
image
)
2
+
bright
(
bright
image
)
2
().& a
dark
=
q=0
k1
p(r
q
) ().& b
bright
=
q=k
L1
p(r
q
) ().& c
15
dark
=
q=0
k1
r
q
p(r
q
)
dark
().& d
bright
=
q=k
L1
r
q
p(r
q
)
bright
().& e
image
=
q=0
L1
r
q
p(r
q
) ().& (
p(r
q
)=
h(r
q
)
N
().& g
N is the number of pi4els0 L is the number of gra! /alues0
r
q
is the qth gra! /alue0
h(r
q
)
is the histogram /alue of
r
q
>3?.
The Otsu method is implemented in 6cilab. The calculation and the result are sho+n in
#ig. 3.3.
#ig. 3.3 a7 Calculation of threshold using OtsuJs method.
#ig. 3.3 b7 Original image. #ig. 3.3 c7 In/erted image. #ig. 3.3 d7 .esulting image.
1D
The result is not /er! accurate0 because shado+s and comparati/el! dar3 regions in the
left part of the image ha/e a gra! /alue higher than the calculated threshold.
In #ig. 3.4 the bac3ground is anal!5ed b! calling the function ImageTool890 selecting a pi4el
and displa!ing a ro+ profile. ll pi4els on this ro+ belong to the bac3ground. The gra! /a1
lue strongl! /aries on the ro+ the selected pi4el belongs to. The bac3ground brightness is
inhomogeneous because the illumination +as inhomogeneous +hen the original photo1
graph +as ta3en. Therefore0 it is difficult to calculate a threshold automaticall! for the gra!
le/el image.
#ig. 3.4 a7 The function ImageTool89 is called for anal!5ing the image.
#ig. 3.4 b7 pi4el is selected. #ig 3.4 c7 @ra! /alue profile of the ro+ the
selcted pi4el belongs to.
In the follo+ing e4ample0 the image is cropped and the threshold is calculated on the crop1
ped in/erted image. The threshold is close to the manuall! determined one and the result
is 2uite accurate as +e can see in #ig. 3.5. The histogram of the in/erted image has a /er!
high pea3 as can be seen in #ig. 3.1. This pea3 ends at the threshold calculated on the ori1
ginal gra! le/el image. Contrasting this0 the cropped in/erted image does not ha/e a pea3
that is much higher than all other pea3s. The bac3ground brightness does not /ar! as
strongl! in the cropped image as in the original one.
The Otsu method is eas! to implement and fast. *o+e/er0 it is important to consider bac31
1)
ground brightness /ariations +hen tr!ing to segment an image using this method. Bac31
ground /ariations can be caused b! inhomogeneous illumination or b! specular reflection.
#ig. 3.5 a7 The image is cropped and the threshold is calculated on the cropped in/erted
image.
#ig. 3.5 b7 The result of thresholding. #ig. 3.5 c7 The histogram of the cropped
in/erted image.
).) *lob ,nalysis
Ob,ects can be found in a logical image b! searching the connected areas of true pi4els.
The pi4els of each connected area are mapped to an integer number greater than 5ero. ll
pi4els of the same area ha/e the same number +hereas pi4els belonging to different areas
ha/e different numbers. ll false pi4els are mapped to 5ero.
n algorithm for searching the connected components is described in >4? and this algo1
rithm is implemented in 6cilab. #ig. 3.D sho+s ho+ a blob anal!sis can be done in 6cilab.
1"
#ig. 3.D a7 blob anal!sis is performed using the function 6earchBlobs89. The result is
sho+n b! 6ho+Image89. The color map has as man! entries as the resulting image has
ob,ects.
#ig. 3.D b7 The logical image. #ig. 3.D c7 The result of blob anal!sis.
1F
).- .iltering
).-.& Introd'ction
#iltering means that a mas3 is placed on each pi4el and a ne+ gra! /alue or logical /alue
is calculated from the pi4els belo+ the mas3. Ob,ects of interest can be emphasi5ed and
irrele/ant ob,ects can be remo/ed appl!ing a filter.
In this document the coordinate s!stem of a filter mas3 ( is defined as sho+n in #ig. 3.)7
f8110 119 f8110 $9 f8110 19
f8$0 119 f8$0 $9 f8$0 19
f810 119 f810 $9 f810 19
#ig. 3.)7 The origin of a filter mas3 coordinate s!stem is on the central element.
The follo+ing t!pes of filtering are described in this document7
%inear filtering7 The ne+ gra! /alue is a +eighted sum of the gra! /alues of the
pi4els belo+ the mas3.
&edian filtering7 The median is calculated from the gra! /alues or logical /alues of
the pi4els belo+ the mas3.
&orphological filtering7 &orphological filters can e4pand or shrin3 ob,ects and con1
nect or di/ide areas.
).-.$ /inear .iltering
'hen an image I is filtered +ith a mas3 ( that has N ro+s and M columns0 the gra! /alue
I
filtered
(i , j )
at the pi4el (i , j ) is calculated in the follo+ing +a!7
I
filtered
(i , j )=
n=n
min
n
max
m=m
min
m
max
f (n , m) I (in, j m) ().$ a
knk , N=2 k+1
k+1nk , N=2k
().$ b
kmk , M=2k+1
k+1mk , M=2k
().$ c
n e4ample is sho+n in #ig. 3."7 The original image consist of an upper region +ith gra!
/alue 5ero and a lo+er region +ith gra! /alue one. The matri4
f =
1
3
(
1 1 1
0 0 0
1 1 1
)
().)
is used as filter mas3. In the filtered image0 the pi4els in the lo+est ro+ of the upper half
and the highest ro+ of the lo+er half ha/e the gra! /alue one +hereas all other pi4els ha1
/e the gra! /alue 5ero. The mas3 used in this e4ample emphasi5es hori5ontal edges.
2$
#ig. 3."7 n image is filtered +ith a mas3 that emphasi5es hori5ontal edges.
The matri4 of the pre/ious e4ample can be e4pressed at the product of a matri4 +ith onl!
one column and a matri4 +ith onl! one ro+7
f
column
=
1
3
(
1
0
1
)
().- a
f
row
=
1
3
( 1 1 1)
().- b
f =f
column
f
row
().- c
In other +ords0 this matri4 is separable. #ig. 3.F sho+s ho+ an image can be filtered +ith a
separable matri4. The column filter is applied to the columns and after this the ro+ filter is
applied to the ro+s or the other +a! around. This reduces the number of multiplications
and additions +hen compared to using a matri4 +ith se/eral ro+s and columns and there1
fore speeds up the computation.
21
#ig. 3.F7 The mas3 can be represented as a product of a ro+ filter and a column filter. The
function 6eparable#ilter89 applies both filters to the image. The result is the same as in #ig.
3.".
).-.) 0edian .iltering
'hen a median filter is applied to a gra! le/el image0 the median of the gra! /alues of the
pi4els belo+ the mas3 is calculated for each pi4el. 'hen a median filter +ith an odd num1
ber of elements is applied to a logical image0 the pi4el in the center is mapped to true0 if
there are more true than false pi4els belo+ the mas3.
The list of the gra! /alues at the pi4els belo+ the mas3 must be sorted and the median
must be searched if the number of elements is odd or e/en be calculated if the number of
elements is e/en. Therefore0 median filtering is /er! time consuming +hen compared to
other filtering methods.
&edian filtering can be applied for remo/ing small noise ob,ects as can be seen in #ig.
3.1$.
22
#ig. 3.1$7 In the original image there are a blob of nine ob,ect pi4els and a single ob,ect pi1
4el. The median filter remo/es the ob,ect consisting of onl! one pi4el. The other ob,ect is
still there e/en though some of its pi4els become bac3ground pi4els.
).-.- 0orphological .iltering
&orphological filters e4pand or shrin3 ob,ects and connect or disconnect areas in an ima1
ge. The mas3 of a morphological filter is a matri4 of logical /alues. If an element of this
matri4 is true0 the pi4el belo+ it is included into the calculation of the ne+ gra! /alue0 logi1
cal /alue or ob,ect inde4. If the element is false0 the pi4el belo+ it is not included into the
calculation. The set of true pi4els of the filter mas3 is also called <structuring element=.
The basic morphological operations are dilation and erosion. (ilation maps the gra! /alue
to the ma4imum of the gra! /alues blo+ the structuring element +hereas erosion maps
the gra! /alue to the minimum. &athematicall!0 the dilation and erosion of an image I +ith
a mas3 ( that has I ro+s and & columns are defined as follo+s7
23
I
dilated
( i , j)= max
f (n ,m)=true
I (i+n , j+m)
().1 a
I
eroded
(i , j )= min
f (n ,m)=true
I (i+n , j+m)
().1 b
knk , N=2 k+1
k+1nk , N=2k
().1 c
kmk , M=2k+1
k+1mk , M=2k
().1 d
#urther morphological operations are7
Closing7 dilation follo+ed b! erosion
Opening7 erosion follo+ed b! dilation
Top *at7 emphasi5es bright ob,ects on a dar3 bac3ground0
I
tophat
=I I
opened
Bottom *at7 emphasi5es dar3 ob,ects on a bright bac3ground0
I
bottomhat
=I
closed
I
#ig. 3.11 sho+s the effects of dilation0 erosion0 closing0 opening0 top hat and bottom hat.
&orphological operations are e4plained in detail in >3?.
#ig. 3.11 a7 The image and the structuring element of the follo+ing e4amples are defined.
24
#ig. 3.11 b7 (ilation ma3es the bright line broader +hereas erosion remo/es the bright line.
25
#ig. 3.11 c7 Closing lea/es the bright unchanged0 because the effect of dilation is canceled
out b! the follo+ing erosion. Contrasting this0 opening remo/es the bright line. Ob,ects that
are completel! remo/ed b! erosion can not restored b! dilation.
2D
#ig. 3.11 d7 The top hat filter lea/es the bright line intact +hereas the bottom hat filter com1
pletel! remo/es it.
).1 2atershed Trans(orm and Distance Trans(orm
6tarting from some seed points0 unlabeled pi4els are assigned to regions of pi4els that are
alread! labeled and ha/e a lo+er or the same gra! /alue. #ig. 3.12 sho+s ho+ the +ater1
shed transform +or3s.
#ig. 3.127 'ater fills se/eral basins. There are +atersheds +here the +ater le/el e4ceeds
the depth of basins. The bet+een +atersheds correspond to regions of an image segmen1
ted b! +atershed transform.
Ob,ects can be detected b! appl!ing a gradient filter and selecting seed points in regions
+here the gradient is lo+. #ig. 3.13 sho+s the results for manuall! selected seed points.
2)
la3e 1 la3e 2 la3e 3
#ig. 3.13 a7 The gradient is calculated and seed points are selected. Then the +atershed
transform is calculated.
2"
#ig. 3.13 b7 Original image. #ig. 3.13 c7 @radient image. #ig. 3.13 d7 .esult image.
possible +or3 flo+ for automated seed point selection is sho+n in #ig. 3.14.
#ig. 3.14 a7 6egmentation of an image using distance transform and +atershed transform.
2F
#ig. 3.14 b7 Original image. #ig. 3.14 c7 @radient image. #ig. 3.14 d7 In/erted edge
image.
#ig. 3.14 e7 (istance Image. #ig. 3.14 f7 &ar3er image. #ig. 3.14 g7 .esult image.
gradient image is calculated from the gra! le/el image. The gra! le/el image is threshol1
ded and in/erted. In the in/erted image0 bac3ground pi4els belong to edges and ob,ect pi1
4els are non1edge pi4els. The distance transform is calculated so pi4els as far as possible
from edge pi4els are found. The distance transform result is thresholded and blobs in the
thresholded distance transform image get mar3ers for +atershed transform.
similar algorithm is described in >3?.
3$
- !ow to Detect +b3ects in Images
-.& Introd'ction
The goal of ob,ect detection is demarcating each ob,ect of interest against the bac3ground
and to represent it b! one area that co/ers it as +ell as possible. In this chapter t+o me1
thods to achie/e this goal are introduced7
Thresholding and blob anal!sis7 The image is segmented b! a threshold to find
areas +ith gra! /alues t!pical for the ob,ects. Then the ob,ects are detected using
blob anal!sis. #ragmented ob,ects are connected b! morphological filtering and
small noise ob,ects are filtered out.
-dge detection and +atershed transform7 The edges are detected and seed points
for +atershed transform are determined. The biggest ob,ect after +atershed trans1
form is the bac3ground so the bac3ground is filtered out. Ob,ects that are fragmen1
ted are connected b! morphological filtering.
fter the ob,ects are detected0 their bounding bo4es are determined and dra+n into the ori1
ginal image.
-.$ Thresholding and *lob ,nalysis
In the image used in the pre/ious chapters0 the tea cup on the left has areas dar3er than
the bac3ground and the red tea po+der can is entirel! dar3er than the bac3ground. There1
fore0 these t+o ob,ects can be detected b! searching these comparati/el! dar3 regions.
This can be done the follo+ing +a!7 The image is con/erted from .@B to a gra! le/el ima1
ge. The gra! le/el image is in/erted and segmented using a manuall! selected threshold.
Then the connected areas are searched. This process and its result are sho+n in #ig. 4.1.
In the original image t+o ob,ects are /isible. *o+e/er0 more than t+o connected areas are
found as can be seen in #ig. 4.1 b. Therefore0 all ob,ects e4cept for the t+o biggest are fil1
tered out. #or this purpose0 a cumulated histogram of area si5es is calculated. The cumu1
lated histogram /alue of a specific si5e sho+s the percentage of connected areas that ha1
/e a number of pi4els less than or e2ual to this specific si5e. This is sho+n in #ig. 4.2.
The resulting image contains t+o ob,ects that co/er partiall! the ob,ects in the original ima1
ge. The bounding bo4es of these ob,ects are searched and dra+n into the gra! le/el ima1
ge. This is sho+n in #ig. 4.3.
s this e4ample sho+s0 it is important to distinguish not onl! bet+een ob,ects and bac31
ground0 but also bet+een the ob,ects of interest and noise ob,ects +hen +or3ing +ith thre1
sholding and blob anal!sis.
It is possible to merge the fragments of an ob,ect appl!ing a closing filter to the logical ima1
ge or the blob image. The t+o ob,ects to be detected are far from each other so the! are
still separate as can be seen in #ig. 4.4. *o+e/er0 if the ob,ects to be detected are nearer
to each other than the fragments belonging to the same ob,ects0 the! are merged. There1
fore0 it is necessar! to consi1der distances bet+een ob,ects +hen merging fragments.
31
#ig. 4.1 a7 The color image is transformed to a gra! le/el image. The gra! le/el image is
in/erted and segmented using a manuall! determined threshold. Then the connected
areas are searched.
#ig. 4.1 b7 The t+o biggest connected areas correspond to the ob,ects to be detected.
32
#ig. 4.2 a7 The cumulated si5e histogram of the ob,ect image is calculated and a minimum
si5e is determined from it. Connected areas smaller than this minimum si5e are filtered
out.
#ig. 4.2 b7 The cumulated si5e histogram of
the connected areas.
#ig. 4.2 c7 ll ob,ects e4cept for the t+o big1
gest are filtered out.
33
#ig. 4.3 a7 The bounding bo4es of the t+o detected ob,ects are determined and dra+n into
the original image.
#ig. 4.3 b7 The original image +ith the bounding bo4es of the detected ob,ects.
34
#ig. 4.4 a7 The logical image is filtered b! a closing filter +ith a structuring element of 21 G
21 pi4els. Then the connected areas in the filtered logical image are searched.
#ig. 4.4 b7 %ogical image. #ig. 4.4 c7 #iltered logical
image.
#ig. 4.4 c7 T+o connected
areas are found.
-.) Edge Detection and 2atershed Trans(orm
The ob,ects in the e4ample image can be demarcated against the bac3ground b! their ed1
ges. It is possible to detect the edges0 select points +ithin the areas surrounded b! edges
and appl! +atershed transform to detect the areas bet+een the edges.
*o+e/er0 there are also edges +ithin the ob,ects. Therefore0 it is necessar! to select seed
points for +atershed transform in se/eral areas. The biggest area found then is the bac31
ground. The bac3ground must be filtered out and then the remaining areas can be mer1
35
ged.
The seeds for +atershed transform are selected in the follo+ing +a!7 The edge image is
in/erted and a distance transform is carried out. The result of distance transform is thre1
sholded and the connected areas in the resulting logical image are searched. These areas
get the seeds of +atershed transform.
The process from edge detection to distance transform is sho+n in #ig. 4.5.
#ig. 4.5 a7 The edges are detected0 the edge image is in/erted and a distance transform is
applied to the in/erted edge image.
#ig. 4.5 b7 Original image. #ig. 4.5 c7 In/erted edge
image.
#ig. 4.5 d7 (istance trans1
form of in/erted edge image
3D
The result of distance transform is thresholded. The threshold is selected manuall!. #ig.
4.D sho+s the result of thresholding the distance transform image and +atershed trans1
form.
#ig. 4.D a7 The result of distance transform is thresholded and the connected areas are
used as mar3ers for +atershed transform.
#ig. 4.D b7 @radient image. #ig. 4.D c7 &ar3er Image. #ig. 4.D d7 .esult of +ater1
shed transform.
In the image resulting from +atershed transform the biggest blob is the bac3ground. The1
re are edge pi4els bet+een the blobs. The bac3ground and edges are set to 5ero and the
image is transformed to a logical image b! thresholding +ith the /alue one. This logical
image is filtered b! a closing filter +ith a 3G3 s2uare as structuring element. The blobs in
the resulting image are searched. This process is sho+n in #ig. 4.).
3)
#ig. 4.) a7 The bac3ground pi4els and edges in the ob,ect image are set to 5ero. Then the
image is transformed to a logical image0 filtered +ith a closing filter and transformed bac3
to an ob,ect image again. There are e4actl! t+o regions corresponding to the ob,ects to be
detected.
3"
#ig. 4.) b7 Ob,ect image after setting edges
and bac3ground to 5ero.
#ig. 4.) c7 %ogical image.
#ig. 4.) d7 %ogical image after closing. #ig. 4.) e7 .esult of blob anal!sis.
The blobs of the result image co/er the images to be detected. The bounding bo4es are
determined and dra+n into the original image 8s. #ig. 4."9.
'hen +or3ing +ith edge detection and +atershed transform0 it is important to select suita1
ble seed points and to detect and filter out the bac3ground in the image resulting from +a1
tershed transform.
The distance transform can help to find seed points for +atershed transform. *o+e/er0 it is
necessar! to find a threshold for segmenting the result of distance transform. This re2uires
some 3no+ledge concerning the smallest fragments +here seed points ha/e to reside.
3F
#ig. 4." a7 Bounding bo4es are determined and dra+n into the original color image.
#ig. 4." b7 The original color image +ith superimposed bounding bo4es.
4$
4e(erences
>1? 6tephen %. Campbell0 ;ean1Philippe Chancelier0 .amine Ii3ou3hah0 Modeling and
Simulation in Scilab/Scicos0 6pringer0 Ie+ Kor30 2$$D
>2? *arald @alda0 Development of a segmentation method for dermoscopic images based
on color clustering0 Lobe Eni/ersit!0 ugust 2$$3
>3? .afael C. @on5ales0 .ichard -. 'oods0 6te/en %. -ddins0 Digital Image Processing
Using MA!A"0 Pearson Prentice *all0 Epper 6addle .i/er0 Ie+ ;erse!0 2$$4
>4? %inda @. 6hapiro0 @eorge C. 6toc3man0 #omputer $ision0 Prentice1*all Inc.0 Epper
6addle .i/er0 Ie+ ;erse!0 2$$1
41