author's personal copy - nchu.edu.t€¦ · author's personal copy computers and...

12
This article was published in an Elsevier journal. The attached copy is furnished to the author for non-commercial research and education use, including for instruction at the author’s institution, sharing with colleagues and providing to institution administration. Other uses, including reproduction and distribution, or selling or licensing copies, or posting to personal, institutional or third party websites are prohibited. In most cases authors are permitted to post their version of the article (e.g. in Word or Tex form) to their personal website or institutional repository. Authors requiring further information regarding Elsevier’s archiving and manuscript policies are encouraged to visit: http://www.elsevier.com/copyright

Upload: others

Post on 15-Apr-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

This article was published in an Elsevier journal. The attached copyis furnished to the author for non-commercial research and

education use, including for instruction at the author’s institution,sharing with colleagues and providing to institution administration.

Other uses, including reproduction and distribution, or selling orlicensing copies, or posting to personal, institutional or third party

websites are prohibited.

In most cases authors are permitted to post their version of thearticle (e.g. in Word or Tex form) to their personal website orinstitutional repository. Authors requiring further information

regarding Elsevier’s archiving and manuscript policies areencouraged to visit:

http://www.elsevier.com/copyright

Page 2: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200

avai lab le at www.sc iencedi rec t .com

journa l homepage: www.e lsev ier .com/ locate /compag

An adaptive image segmentation algorithm for X-rayquarantine inspection of selected fruits

Joe-Air Jianga, Hsiang-Yun Changa, Ke-Han Wua, Cheng-Shiou Ouyanga,Man-Miao Yangb, En-Cheng Yangb, Tse-Wei Chenc, Ta-Te Lina,∗

a Department of Bio-Industrial Mechatronics Engineering, National Taiwan University, Taipei 106, Taiwanb Department of Entomology, National Chung Hsing University, Taichung 402, Taiwanc Division of Plant Quarantine, BAPHIQ, Council of Agriculture, Taipei 100, Taiwan

a r t i c l e i n f o

Article history:

Received 22 June 2006

Received in revised form

21 July 2007

Accepted 6 August 2007

Keywords:

X-ray

Insect pest inspection

Quarantine

Image processing

Adaptive thresholding

a b s t r a c t

Although X-ray scanners are commonly used in airports or customs for security inspec-

tion, practical application of X-ray imaging in quarantine inspection to prevent propagation

of alien insect pests in imported fruits is still unavailable. The first step to identify insect

infestation in fruit by X-ray imaging technique is image acquisition. This is followed by the

image segmentation procedure, which can locate sites of infestation. Since the grey level of

X-ray images depends on the density and thickness of the test samples, the relative con-

trast of infestation site to the intact region inside a typical fruit varies with its position. To

accurately determine whether a fruit has signs of insect infestation, we have developed an

adaptive image segmentation algorithm based on the local pixels intensities and unsuper-

vised thresholding algorithm. This paper presents the detailed image processing procedure

including the grid formation, local thresholding, threshold value interpolation, background

removal, and morphological filtering for the determination of infestation sites of a fruit in

X-ray image. The real-time image processing procedure was tested with X-ray images of

several types of fruit such as citrus, peach, guava, etc. Additional tests and analyses were

also performed using the developed algorithm on the X-ray images obtained with different

image acquisition parameters.

© 2007 Elsevier B.V. All rights reserved.

1. Introduction

With the globalization of commerce, the increasing movementof agricultural products across international borders has alsobrought about adverse pest invasions to the sanitary regions.Several cases, such as the Mediterranean fruit fly and theAsian longhorned beetle, have shown how alien pests cancause great irreversible damage to agriculture and ecology(Komitopoulou et al., 2004; Poland et al., 1998). Control mea-sures for quarantine service of agricultural products across

∗ Corresponding author at: Department of Bio-Industrial Mechatronics Engineering, National Taiwan University, No. 1, Roosevelt Road,Section 4, Taipei 106, Taiwan. Tel.: +886 2 23929416; fax: +886 2 23929416.

E-mail address: [email protected] (T.-T. Lin).

borders have thus been strengthened in many countries toreduce the propagation of alien pests. Although the impor-tance of establishing a secure quarantine system has been welladdressed and recognized, most of the quarantine methods inpractice mainly rely on visual inspection of external appear-ance, followed by dissecting examination if suspected. Thesevisual inspection methods are both laborious and time con-suming. X-ray scanning, on the other hand, provides a feasiblemeans to facilitate the quarantine operations by improvingefficiency, reliability, and accuracy.

0168-1699/$ – see front matter © 2007 Elsevier B.V. All rights reserved.doi:10.1016/j.compag.2007.08.006

Page 3: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200 191

Although X-ray scanners are commonly used in airportsor customs for security inspection, practical application ofX-ray imaging in quarantine inspections for detecting pos-sible alien pests in imported fruits is still not commerciallyavailable. With its ability to penetrate materials and be atten-uated according to the material’s thickness and density, X-raytechniques have been widely applied in many fields suchas medicine, manufacturing, and agriculture. For biologicalmaterials, mostly the purpose of X-ray inspections is to findinternal damage or alien material by the differential penetra-tion rate of X-ray between the original material and the targetmaterial. Many studies on the applications of X-ray inspec-tion or quality evaluation have been reported in the field ofagriculture. For example, the watercore of apples, an internaldisorder that leads to tissue breakdown, can be detected in dig-ital X-ray images (Kim and Schatzki, 2000). Shahin et al. (2002a)demonstrated that apple bruises were detectable using X-rayimaging and the extracted image features can be used to sortdefective apples. In another study, they also applied the sameapproach to line-scanned X-ray images of sweet onions andshowed that an overall classification accuracy of 90% can beachieved (Shahin et al., 2002b). X-ray imaging has also shownpromising results for detecting internal defects in grains orseeds. Wheat infested by weevils can be identified using theX-ray imaging technique (Karunakaran et al., 2003; Haff andSlaughter, 2004). Karunakaran et al. (2004) proposed a methodof measuring the mass of wheat by calculating the total greyvalue from the X-ray image of the wheat. Singh (1975) usedsoft X-ray to evaluate the quality of several plant seeds. Therewere also several papers reporting the use of X-ray methodsfor the detection of pests in seeds (Fesus, 1972; Wadhi, 1983;Chavagnat, 1985).

In general, the acquisition of X-ray images can be eitherfilm-based or digital. In film-based X-ray imaging, which issimilar to that of conventional photography, the X-ray is trans-mitted through the inspected object and a sensing film isexposed to form the object image. After developing the film,an X-ray image with high resolution can be obtained. With theadvent of modulized X-ray source and digital X-ray scanningsensors, digitized X-ray images can be acquired and analyzedin real time. Since this allows for online inspection of materi-als, the applications of digital X-ray imaging in industries haveincreased significantly in recent years. In developing a spe-cialized X-ray scanning system for the quarantine inspectionof fruits, the aim is to process and analyze the acquired X-rayimage to obtain information that can help a quarantine officerin identifying possible pest infestation of the examined fruits.To achieve this, the first step to identify internal infestation offruits by X-ray imaging technique is the image segmentationprocedure, which can locate the infestation site. Since the greylevel of X-ray images depends greatly on the composition, den-sity, and thickness of the test samples, the relative contrast ofinfestation site to the intact region within a typical fruit varieswith its position. Therefore, conventional thresholding algo-rithms using global threshold value are not directly applicableto segment the infestation site. To solve this problem, an adap-tive thresholding approach is necessary. In a series of studiesfor the inspection of deboned chicken meat, several image pro-cessing algorithms have been developed for the processing ofX-ray images. Tao and Ibarra (1999) demonstrated the need

for improved methods to detect bone fragments in debonedchicken fillet of uneven thickness. They proposed an imageprocessing algorithm to eliminate the false patterns and thusenhanced the X-ray sensitivity for bone fragment detection.Chen et al. (2000) proposed a multiresolution-analysis-basedlocal contrast transform to enhance the local structures ofthe X-ray image of chicken meat. Tao et al. (2001) proposeda method with the threshold function resulting from thesmoothing of an X-ray image of meat fillet. The thresholdfunctions associated with the adaptive segmentation processwere obtained by local averaging with a window whose sizewas dependent on the size of object to be detected. Chen etal. (2003) used a synergistic laser thickness detection to adjustthe grey value of the X-ray image and successfully ruled outthe effect from the uneven thickness of chicken meat.

To achieve the goal of detecting possible infestation sitesor pests in imported fruits using X-ray imaging, we previouslydesigned and established an X-ray system with functionsbased on the requirements of quarantine inspection, such asacquiring X-ray images of fruits in real time, an algorithm forimage processing, and the mechanical design of the system(Lin et al., 2005). Preliminary experiments were conducted inorder to segment the infestation site within the fruit usingthe X-ray scanning system. It was found that the cavity due toinsect pests caused a higher penetration rate of X-ray, and sothe cavity possessed a higher intensity in the X-ray image (orlower intensity in a negative image, as shown in this paper).However, it is difficult to segment the infestation site from theX-ray image by segmentation with a global threshold approachbecause the grey levels of the pixels have a wide range of distri-bution. The clusters of pixels representing the infestation siteand normal tissue were completely overlapped in the imagehistogram. In order to successfully segment the infestationsite in fruit, a real time and adaptive segmentation algo-rithm needs to be developed. Therefore, the objectives of thisresearch are: (1) to design and implement an adaptive thresh-olding algorithm to segment infestation site (cavity or pest) inX-ray images of selected fruits and (2) to test the algorithmwith X-ray images of various fruits and study the factors thatmay affect the performance of the segmentation algorithm.

2. Materials and method

2.1. The X-ray scanning system

The X-ray imaging system consists of a microfocus X-raysource (Hamamatsu L8601-01, Hamamatsu Photonics K.K.)and a line-scan sensor camera (Hamamatsu C8750-10FC,Hamamatsu Photonics K.K.), both of which are controlled by adesktop computer (Pentium IV CPU, 2.4 GHz). A frame grabberboard (PC-DIG, Coreco Imaging) is used to acquire and transferthe signal from the line-scan sensor to the host computer.

The schematic layout of the integrated X-ray scanningsystem is illustrated in Fig. 1. An adjustable fixture is imple-mented on the top of the system. The X-ray source tube anda color CCD camera (AVT Marlin F-131C, Allied Vision Tech-nology) are mounted on the adjustable fixture so that thedistance between the X-ray source tube and the line-scansensor camera can be adjusted from 70 cm to 80 cm manu-

Page 4: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

192 c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200

Fig. 1 – Schematic drawing of the X-ray scanning system(Lin et al., 2005).

ally to fine-tune the length of the X-ray beam that appearsover the detector. To geometrically magnify or minify the X-image, a height-adjustable acrylic box (as shown in Fig. 2) wasdesigned and used to change the distance between the fruitsbeing inspected and the belt from 0 cm to 30 cm. Therefore,the magnification ratio of the X-ray imaging system can bevaried roughly from 1.1× to 1.9×. The color CCD camera isimplemented along with the X-ray imaging unit so that bothexternal and internal characteristics of fruits can be assessedsimultaneously. All system components including the com-puter, dual LCD monitors, imaging chamber, and conveyor areintegrated into one compact module. The entire quarantinesystem has external dimension of 170 cm × 97 cm × 230 cm(L × W × H) and weighs about 250 kg. The conveyor system con-

Fig. 2 – Schematic layout for using the height-adjustableacrylic box.

sists of a PVC belt, a servo motor (Mitsubishi J2S series servo,Mitsubishi Electric Corporation) with its driver (MitsubishiMR-J2S, Mitsubishi Electric Corporation), and a motion con-trol card (NI PCI-7344, National Instruments Inc.) to preciselycontrol the conveyor displacement. To prevent the operatorfrom exposing to X-ray radiation, lead shielding sheet withthickness of 0.5 cm, calculated according to the safety regu-lation, was mounted in the interior wall of the X-ray imagingchamber. LabVIEW 7.1 Express (National Instruments Inc.) wasadopted as the software development and system integrationplatform. In addition, NI-IMAQ and NI-MOTION packages forLabVIEW (National Instruments Inc.) were used to developroutines associated with image processing and motion con-trol, respectively. The motion control routines ensure conveyordisplacement stability, which is important in acquiring high-quality X-ray images.

2.2. Sample preparation

The Oriental fruit fly, Bactrocera dorsalis (Hendel), is a seriouslocal pest and was used as a model insect to establish theinfestation in fruits for X-ray examination in this research.Fruit flies were supplied by the Insect Physiology and Biochem-istry Laboratory, National Chung Hsing University, Taichung,Taiwan. Larvae of B. dorsalis were fed an artificial diet, andadults were maintained at 28 ± 1 ◦C with a 12-h light and 12-hdark cycle. Flies were sexually mature 10 days after emergingunder these incubation conditions. A plastic film containerwith guava juice inside and about 20 pin-holes in the bottomserved as an egg collector. Fresh fly eggs were collected withthis collector on the top of the raising cage for 2 h immedi-ately before implantation into the fruit (Yang et al., 2006). Allpest-infested fruit were imitated by implanting fresh Orien-tal fruit fly eggs under the skin of the fruit. X-ray images ofselected fruits such as citrus, peach, and guava were acquiredand used to test the adaptive thresholding algorithm. Devel-opment of the infestation by the hatched fruit fly larvae wasmonitored, in different days after deployment of eggs, by bothX-ray imaging examination and visual inspection. Fig. 3 showsthe development of the insects in peach within 6 days. Usuallythe infestation could be found by the X-ray images in 2–3 daysafter implanting fruit fly eggs in the fruits. The sign of internalinfestation in X-ray images became very obvious after 6 dayswhile there were no visible infestation signs on the surface.

2.3. X-ray image acquisition

Before X-ray image acquisition, dark current correction andbrightness correction procedures were performed to reducenoise from the dark current of the detector and the non-uniform distribution of the X-ray beam, respectively, as muchas possible. During X-ray image acquisition, the fruit wasplaced on the conveyor belt and moved horizontally acrossthe line-scan sensor camera by the conveyor belt at a constantspeed. The X-ray source was hermetically sealed, air cooled,and featured RS-232C interface for external control. The tubevoltage could be adjusted in the range of 40–90 kV and the tubecurrent was also adjustable in the range of 110–250 �A via thehost computer. The quality of the X-ray image for differentkinds of fruits depends greatly on the selection of proper tube

Page 5: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200 193

Fig. 3 – Development of the insects after implanted into peach within 6 days.

voltage and current because of the variable thickness, densityand X-ray absorption characteristics of different fruits. Usu-ally we attempted to adjust the tube voltage to find out theoptimum contrast of the X-ray image, followed by the processof maximizing the tube current within the power restriction(10 W) to produce enough photons for each sensor elementto detect. The optimum contrast was obtained in the regionbetween the kernel and the edge of the sample in order toreduce the influence from the seeds and the belt in the kerneland edge regions, respectively. The line-sensor camera was512 mm in width with a resolution of 1280 pixels. The 12-bitdigital signal of each pixel was transferred to the frame grab-ber board through the RS-422 digital interface. The line datawere then composed in the host computer to form the two-dimensional image. In our application, the 12-bit data wereproportionally converted to 8-bit data to create images of 256grey levels.

The images were processed with the software developedin this research, which was implemented using the NI-IMAQfor LabVIEW package and Borland C++ Builder 6.0 (BorlandCo. Ltd.). The customized image processing procedure wasmainly based on the image processing components includedin NI-IMAQ for LabVIEW package. However, the algorithm ofadaptive thresholding was coded with C++ programming lan-guage and then compiled to a Dynamic Link Library (DLL) thatwas linked to the LabVIEW software environment.

2.4. The image segmentation procedure

One of the key characteristics of X-ray images of fruits is thatthe grey level of a pixel depends on the density and thick-

ness of the sample. For fruits with variable thickness due totheir nearly spherical or oval shape, the grey levels encompassa wide range that includes the grey levels of infestation siteinternal of the fruit. For example, Fig. 4 shows the results usingthe traditional standard thresholding algorithm (Gonzales andWoods, 2002). It is obvious that the infestation site could not beextracted; no matter how the threshold value was set. There-fore, it is difficult to segment the infestation site with global(single) threshold values and it is not useful for the follow-upimage processing. An adaptive thresholding algorithm basedon the local grey-level distribution is thus necessary to resolvethis problem. The flow chart of the overall image segmenta-tion procedure developed in this research is depicted in Fig. 5.The procedure starts with a pre-processing step to remove ran-dom noise in the background of the X-ray image. The adaptivethresholding is then applied to the X-ray image by first creatinga threshold value map with its threshold values being a func-tion of pixel coordinates. A binary image is obtained by usingthis threshold value map to determine the pixel value to be 0 or255. Possible locations of infestation are then located by a hole-filling processing followed by an image subtraction. Finally,morphological filtering is applied to screen small spots. Infes-tation sites, usually larger in area, are then selected basedon the number of iterations of morphological filtering, whilesmall irrelevant spots are removed.

2.5. Removal of background pixels

Removal of background pixels is necessary before the adap-tive thresholding algorithm is applied to the X-ray images offruits. This is because the random noise in the background

Page 6: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

194 c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200

Fig. 4 – Performance illustration of a traditional standard thresholding method: (a) original image, binary images obtainedfrom a traditional standard thresholding method with threshold values of (b) 40, (c) 80, (d) 120, (e) 160, and (f) 200.

region is suitable for global thresholding instead of adaptivethresholding, since the pixel values in the background regionsare not affected by the thickness or density of the fruit. Thesepixel values mainly represent the blank background and sig-

Fig. 5 – Flow chart of the internal infestation segmentationprocedure for X-ray images.

nal noise during image acquisition. Undesirable results willoccur if the adaptive thresholding is applied to the noise pix-els. By examining the histogram of a typical X-ray image (seeFig. 6), we can see that there is a distinct mode in the lowergrey level region. The pixels around the mode are the back-ground and noise pixels while the rest pixels with higher greylevels represent the fruit. The noise removal process is doneby resetting the grey level value of all pixels which have lowergrey level values than the threshold value T to zero as indi-cated in Fig. 6. The T value is determined by searching thevalley next to the distinct mode of the smoothed histogramusing the slope information. Typical values of T ranged from40 to 50 depending on the noise levels of a blank X-ray image(or the background noise).

2.6. Adaptive thresholding algorithm

The major purpose of adaptive thresholding is to give eachpixel a suitable threshold value that is dependent on the dis-

Fig. 6 – Histogram of a sample X-ray image of a citrus fruit.

Page 7: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200 195

Fig. 7 – Steps of the adaptive thresholding algorithm: (a) starting position of the M × M operational region, (b) shifting theoperational region, (c) the coarse threshold grid, and (d) two-dimensional interpolation of the threshold values.

tribution of grey levels of the neighbourhood pixels. To achievethis, we create a map of threshold values which has the samesize with the original image during adaptive thresholding pro-cess. The map stores the threshold values corresponding toeach pixel in the original image and is used to create a binaryimage for later processing. To calculate the threshold valuesof the map, we adapted the approach developed by Chowand Kaneko (1972) for outlining boundaries of the heart ven-tricle from X-ray image. The X-ray image is initially dividedinto many M × M (M = 32 in most cases) operational regions asshown in Fig. 7a. A threshold value is then determined fromthe histogram of this M × M sub-image using an automaticthresholding algorithm. The algorithm is an unsupervisedthresholding method by iteratively choosing the thresholdvalue Ts with the following equation (Gonzales and Woods,2002):

Ts = |�1 − �2|2

(1)

where �1 is the average grey level of all pixels with grey levelgreater than Ts and �2 is the average grey level of all pixels withgrey level smaller than Ts. The value Ts is iteratively calcu-lated at each classification round until the value has convergedto a fixed threshold value. Using this algorithm, the iterationusually takes three to four rounds to converge. Each M × M sub-image has M/2 pixels overlap, horizontally and vertically, withthe neighbor sub-images. The Ts values are calculated fromleft-top to right-bottom of the image for all M × M sub-imagesto form a coarse threshold value grid. The detailed steps areas follows:

1. Calculate the histogram of the M × M operational regionand select an initial estimate for Ts. Iteratively compute anew threshold value using Eq. (1) until the threshold value

converges. Save the value in the corresponding position ofthe center of the operational region to the coarse thresholdvalue grid.

2. Shift the operational region M/2 pixels to the right, asshown in Fig. 7b, and repeat the process of step 1. Repeat theprocess horizontally and vertically for all the M × M opera-tional regions. At the end of the process, a coarse thresholdvalue grid with (2N/M − 1) × (2N/M − 1) threshold values isobtained for an N × N image, as shown in Fig. 7c.

3. The threshold values for the pixels p(x, y) within anM/2 × M/2 interpolation grid are determined by two-dimensional interpolation using the following equation(Seul et al., 2000):

T(x, y) =∑i=4

i=1Ii/R2i∑i=4

i=11/R2i

(2)

where I1. . .4 are threshold values of the four nearest refer-ence points to p(x,y), and R1. . .4 are the distances from p(x,y) to I1. . .4, respectively, as shown in Fig. 7d. The interpo-lated threshold value is calculated based on the distancesof p(x, y) to its four nearest neighbor grid points. A com-plete threshold value map is finally formed by determiningthe threshold values for all pixels p(x, y) in all interpolationgrids. Compared with conventional bilinear interpolationmethod, this algorithm is more efficient in terms of com-putational effort.

4. When the complete threshold value map is computed, theimage thresholding is done by the following rule:

f ′(x, y) ={

255, f (x, y) ≥ T(x, y)

0, f (x, y) < T(x, y)(3)

where the f′(x, y) is the new pixel value of the binary image.

Page 8: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

196 c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200

Fig. 8 – (a) Original X-ray image of an infested peach and (b) the threshold value map of (a).

Fig. 8 shows an example using the proposed adaptivethresholding algorithm. The image shown in Fig. 8a is anoriginal X-ray image of a peach after background removal.Applying the above adaptive thresholding algorithm, a thresh-old value map is generated, as shown in Fig. 8b. It is obviousthat the threshold value map is variable and dependent onthe local grey level distribution of the original X-ray image.Fig. 9 illustrates a typical example of the sequential steps ofthe complete image segmentation process of a citrus X-rayimage. Fig. 9c is the binary image of Fig. 9b after applying theadaptive thresholding.

2.7. Hole filling and image subtraction

A binary image is obtained following the adaptive threshold-ing step. The binary image contains the cavities or tunnelscreated by the infested pests. These small spots need to be iso-lated and classified into noise or suspected infestation sites.

A hole-filling step utilizing the NI-IMAQ morphological oper-ation (fill hole library function) is then applied to the binaryimage to fill these spots and create a temporary image. Thetemporary image is then subtracted by the original binaryimage to isolate the small spots as shown in Fig. 9d. In effect,this process also removes the outer contour of the fruit inFig. 9c and only small spots within the fruit remain in theimage.

2.8. Morphological filtering

To identify possible infestation sites among small spots seg-mented from the binary image, a morphological filteringapproach is employed, which can eliminate or maintain thespots on the image according to their area size by the proce-dure of erosion and dilation. The erosion procedure shrinksthe spots, so that a spot will be eliminated if it is smallerthan a certain size. The dilation procedure is then performed

Fig. 9 – Sequential image processing results of a citrus X-ray image: (a) original image, (b) removal of background, (c)adaptive thresholding, (d) locating possible spots by using hole filling and image subtraction, (e) morphological filtering toremove small spots, and (f) overlaying the result onto the original X-ray image.

Page 9: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200 197

to expand the spots remaining after the erosion process totheir original size. As in many image processing libraries, themorphological filtering function is a library function of theNI-IMAQ image processing library. The morphological filter-ing function performs operations on spots in binary images,and the filtering retains particles resistant to a specified itera-tion of erosion by a 3 × 3 structuring element. We utilized thismorphological filtering function to screen noise or undesirablespots using the iteration number as an operational parameter.A typical result of small spot removal is shown in Fig. 9e. Theremaining spots are isolated and overlaid onto the originalX-ray image, as shown in Fig. 9f. The optimum number of iter-ation is dependent on different kinds of fruits and extent ofinfestation. Below we discuss the effect of iteration numberon the identification of suspected infestation sites.

3. Results and discussion

The adaptive segmentation algorithm was implemented onthe prototype X-ray scanner for fruit quarantine. The softwarewas initially tested extensively for X-ray images of variouskinds of fruits. For images of 512 × 512 pixels, the averageprocessing time was 270 ms using a desktop computer with2.4 GHz Pentium IV CPU under the Microsoft XP Windowsenvironment. This processing speed is sufficient for nearlyreal-time processing to mark the suspected infestation sitesin the X-ray image during fruit scanning in a quarantine oper-ation. In practice, the scanning operation requires that thebands of scanned lines be continuously processed one afteranother. Therefore, images of 80 × 960 pixels were acquired,processed, and updated on the monitor sequentially to allowfor real-time inspection as the fruit was moved along the con-veyor belt. With the current algorithm, the scanning system

was capable of executing the inspection operation at a con-veyor speed of 1.2 m/min. The suspected sites of infestationin the fruit were immediately segmented and overlaid on theX-ray image during scanning to alert the quarantine inspector.

3.1. Parameters for adaptive segmentation algorithm

The number of iterations for morphological filtering of spots inbinary image is the key working parameter for segmentationof infestation sites in X-ray images of fruits. This parameteris not universal for different kinds of fruits nor is it univer-sal for fruits with different extents of infestation. The numberof iteration is basically affected by the size and shape of theinfestation sites. Therefore, adjustment of this parameter fordifferent conditions of quarantine inspection is usually neces-sary. Once the parameter is determined for a specific scanningoperation such as a particular kind of fruit, the parameter issaved in the record file for later retrieval and parameter settingwhen the same kind of fruit is scanned afterward.

In general, the morphological filtering process can removesignal noise or small grains such as seeds from X-ray imagesof fruit. As shown in Fig. 10a, the X-ray image of a guava con-tains several infestation sites, and the result of segmentationafter adaptive thresholding without morphological filtering isshown in Fig. 10b. By removing small spots using morpholog-ical filtering with three iterations, small spots of noise andgranular seeds were successfully removed leaving the seg-mented infestation site as shown in Fig. 10c. However, inanother case of peach as shown in Fig. 10d, the soft tissuearound the pit has similar grey level and size as the infesta-tion site on the top of the fruit. The morphological filteringsegmented both spots but was not successful in differentiat-ing the infestation site and the normal tissue (Fig. 10f). In mostcases, adjusting the iteration number of the morphological

Fig. 10 – Effect of morphological filtering: (a) X-ray image of a guava, (b) segmented spots after adaptive thresholding of (a),(c) morphological filtering of (b) with three iterations, (d) X-ray image of a peach, (e) segmented spots after adaptivethresholding of (d), and (f) morphological filtering of (e) with three iterations.

Page 10: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

198 c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200

Fig. 11 – Effect of sub-image size on adaptive thresholding. (a) Binary image using 32 × 32 sub-image size, (b) binary imageusing 12 × 12 sub-image size, (c) result of (a) after morphological filtering, and (d) result of (b) after morphological filtering.

filtering can successfully segregate infestation site from thenoise or granular texture in the X-ray image of fruits. Whenthe size and grey level of the segmented spots are similar, thecurrent segmentation algorithm has its limitations and thusother geometric features of segmented spots such as shape orlength needs to be considered, if necessary.

Another important parameter that may affect the resultof the adaptive segmentation procedure is the size of theM × M operational sub-images. For the current configura-tion of the X-ray scanning system, we most frequently usedthe 32 × 32 operational sub-images for adaptive threshold-ing. Changing the size of the operational sub-image maylead to different results in some cases. The binary imagesof guava shown in Fig. 11a and b are the results of adap-tive thresholding using different sub-image size of 32 × 32and 12 × 12, respectively. It is clear that the sub-image sizeaffected the size distribution of the segmented spots. Thisresult subsequently affected the detection of the infestationsites when the morphological filtering is applied. In Fig. 11c, ashadow region corresponding to the core of the guava fruitexists in the middle part of the X-ray image. This region,with similar size to the infestation site, was misclassifiedas an infestation site using 32 × 32 operational sub-images.Using 12 × 12 operational sub-images in adaptive threshold-ing, finer spots were obtained and the misclassified region inFig. 11c was screened by the morphological filter as shown inFig. 11d.

3.2. Sub-image size and interpolation grid size

Another concern in the selection of optimum operationparameters for the adaptive segmentation procedure is the

computation time and the stability of the algorithm. Two keyparameters, namely, the operational sub-image size and theinterpolation grid size may affect the performance of the adap-tive segmentation algorithm. To test their effects, the X-rayimage of a guava in Fig. 10a was processed using the sub-imagesizes of 32 × 32, 24 × 24, 18 × 18, and 12 × 12 in combinationwith the interpolation grid sizes from 1 × 1 to 32 × 32. Thecomputation time and threshold value map of each conditionwere recorded for analyses. Fig. 12 shows the effect operationalsub-image size and interpolation grid size on the computa-tion time. The computation time increases with the increaseof sub-image size. On the other hand, increasing the interpo-lation grid size reduces the computation time. However, thereis no significant difference in the computation time when the

Fig. 12 – Comparison of computation time of adaptivesegmentation procedure using different operationalsub-image sizes and interpolation grid sizes.

Page 11: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200 199

Fig. 13 – Comparison of average threshold value differenceof adaptive segmentation procedure using differentoperational sub-image sizes and interpolation grid sizes.

interpolation grid size is greater than 8 × 8 pixels, even whenthe sub-image size is different.

Fig. 13 shows the comparisons of average threshold valuedifference of adaptive segmentation procedure using dif-ferent operational sub-image sizes and interpolation gridsizes. The threshold value maps created by different com-binations of sub-image sizes and interpolation sizes werecompared with the reference threshold value map createdby using 32 × 32 operational sub-image and without interpo-lation (1 × 1 interpolation grid size). The average thresholdvalue difference was calculated by taking the average of theabsolute difference of the threshold values of each corre-sponding pixels of the two threshold value map. Althoughthe average difference slightly increases with the increaseof the interpolation grid size, the difference is not signifi-cant. The maximum average difference of threshold valuemaps for all cases is less than five grey levels, which indicatesthat the threshold value map is relatively stable regard-less of the variations in sub-image size or interpolation gridsize.

3.3. Accuracy of infestation detection

To further test the feasibility of the developed algorithm,experiments were carried out to assess the accuracy of infes-tation detection. Guava and peach fruits were implanted withfruit fly eggs and the infestation sites by the hatched fruit flylarvae were manually assayed and recorded. The X-ray imagesof these infested fruits were also acquired and processed withthe adaptive segmentation procedure. Totally, 86 infestationsites in the flesh part of 25 guava fruits and 135 infestationsites of 35 peach fruits were manually identified. The areas ofinfestation sites in fruits ranged from 3.54 mm2 to 70.91 mm2,which correspond to the areas of 80 pixels to 1600 pixels in theX-ray images when the magnification ratio of X-ray system is1.9×.

Table 1 summarizes the experimental results of the detec-tion accuracies of the infestation detection experiments forguava and peach fruits. The detection accuracy was appar-ently affected by the selection of sub-image and it decreasesas the sub-image size increases. Using 18 × 18 sub-imagesize, 93% and 96% of infestation sites were correctly detected

Table 1 – Detection accuracies of the infestationdetection experiments for guava and peach fruits

Sub-image size Detected sites Missed sites Falsealarm

Guavaa

12 × 12 95% (82)b 5% (4) 66% (52)18 × 18 93% (81) 7% (5) 1% (1)24 × 24 62% (53) 38% (33) 3% (2)32 × 32 31% (33) 69% (53) 3% (2)

Peachc

12 × 12 98% (133) 2% (2) 77% (95)18 × 18 96% (130) 4% (5) 11% (12)24 × 24 85% (114) 15% (21) 4% (4)32 × 32 60% (81) 40% (54) 0% (0)

a Number of fruits tested = 25 and total number of infestationsites = 86.

b Number in the parenthesis is the number of detected infestationsites.

c Number of fruits tested = 35 and total number of infestationsites = 135.

for guava and peach, respectively. The false alarm rateswere 1% and 11% correspondingly. The detection accuracyslightly increased to 95% (guava) and 98% (peach), by reduc-ing the sub-image size to 12 × 12 in the adaptive segmentationprocedure. The slight increase of detection accuracy is accom-panied with the trade-off of more computation time andsignificant increase of false alarm rate to 66% (guava) and77% (peach).

4. Conclusions

With the adaptive segmentation procedure developed in thisresearch, we can effectively cope with the problem of greylevel gradient in the X-ray images due to shape or uneventhickness of fruit for most of tested cases. However, the infes-tation sites could not be segmented using the traditionalstandard thresholding algorithm. Consequently, variations infruit characteristics and extent of infestation may be dealtwith by adjusting the iteration number of morphological fil-tering or the sub-image size for adaptive thresholding. Thealgorithm is fast in computation time and was implementedin the X-ray scanner for real-time quarantine inspection ata scanning rate of 1.2 m/min. Suspected sites of infestationinside fruit can be accurately marked on the acquired X-rayimage to aid the quarantine officer during inspection. Fordifferent kinds of fruits, initial tests and choices of opera-tion parameters need to be determined, including number ofiterations for morphological filtering, operational sub-imagesize, and interpolation grid size. Once the parameters areconfigured, they are saved and used in subsequent quaran-tine inspection. The effect of operational parameters was alsoexamined by comparing the computation time and thresh-old value map using different combinations of parameters.Experimental results revealed that the effect of sub-imagesize and interpolation grid size has little effect on the com-putational time when the interpolation grid size is greaterthan 8 × 8 pixels. The adaptive thresholding algorithm isstable judging from the insignificant difference of thresh-

Page 12: Author's personal copy - nchu.edu.t€¦ · Author's personal copy computers and electronics in agriculture 60 (2008)190 200 191 Although X-ray scanners are commonly used in airports

Author's personal copy

200 c o m p u t e r s a n d e l e c t r o n i c s i n a g r i c u l t u r e 6 0 ( 2 0 0 8 ) 190–200

old value maps created using various sub-image size andinterpolation grid size. The algorithm resolves the frequentproblem of segmenting object from X-ray image using globalthresholding approach. Without substantial modification, thealgorithm can be applied to X-ray inspection of variousagricultural products having uneven thickness and variabledensities.

Acknowledgement

The authors would like to thank the Council of Agricultureof the Executive Yuan, ROC for financially supporting thisresearch under Grant no. 93AS-6.1.5-BQ-B1.

r e f e r e n c e s

Chavagnat, A., 1985. Industrial X-ray radiography: control of seedquality and other applications in agronomy. Comptes Rendusdes Seances de l’Academie d’Agriculture de France 71,457–463.

Chen, X., Jing, H., Tao, Y., Carr, L., Wheaton, F., 2003. Real-timedetection of physical hazards in deboned poultry usinghigh-resolution X-ray imaging. ASAE Paper Number 033084ASAE. St. Joseph, MI.

Chen, Z., Tao, Y., Chen, X., 2000. Multiresolution local contrastenhancement of X-ray images for poultry meat inspection.Appl. Opt. 40 (8), 1195–1200.

Chow, C.K., Kaneko, T., 1972. Automatic boundary detection ofthe left ventricle from cineangiograms. Comp. Biomed. Res. 5,388–410.

Fesus, I., 1972. Detection and estimation of internal pestinfestation in seeds by the application of X-ray techniques.Bull. Org. Eur. Mediterr. Pour Protect. Plantes 3, 65–76.

Gonzales, R.C., Woods, R.E., 2002. Digital Image Processing, 2nded. Prentice Hall, Upper Saddle River, NJ, pp. 598–600.

Haff, R.P., Slaughter, D.C., 2004. Real-time X-ray inspection ofwheat for infestation by the granary weevil, SitophilusGranarius (L.). Trans. ASAE 47 (2), 531–537.

Karunakaran, C., Jayas, D.S., White, N.D.G., 2003. Soft X-rayinspection of wheat kernels infested by Sitophilus oryzae.Trans. ASAE 46 (3), 739–745.

Karunakaran, C., Jayas, D.S., White, N.D.G., 2004. Massdetermination of wheat kernels from X-ray images, ASAEPaper Number 043120 ASAE. St. Joseph, MI.

Kim, S., Schatzki, T.F., 2000. Apple watercore sorting system usingX-ray imagery. I. Algorithm development. Trans. ASAE 43 (6),1695–1702.

Komitopoulou, K., Christophides, G.K., Kalosaka, K., Chrysanthis,G., Theodoraki, M.A., Savakis, C., Zacharopoulou, A., Mintzas,A.C., 2004. Medfly promoters relevant to the sterile insecttechnique. Insect Biochem. Mol. Biol. 34, 149–157.

Lin, T.T., Jiang, J.A., Ouyang, C.S., Chang, H.Y., Yang, M.M., Yang,E.C., 2005. Integration of an automatic X-ray scanning systemfor fruit quarantine. In: Proceedings of Automation 2005, theEighth International Conference on Automation TechnologyConference, Taichung, Taiwan, CIAE.

Poland, T.M., Haack, R.A., Petrice, T.R., 1998. Chicago joins NewYork in battle with the Asian longhorned beetle. Newslett.Michigan Entomol. Soc. 43, 15–17.

Seul, M., O’Gorman, L., Sammon, M.J., 2000. Practical Algorithmsfor Image Analysis. Cambridge University Press, Cambridge,pp. 43–46.

Shahin, M.A., Tollner, E.W., Gitaitis, R.D., Sumner, D.R., Maw, B.W.,2002a. Apple classification based on surface bruises usingimage processing and neural networks. Trans. ASAE 45 (5),1619–1627.

Shahin, M.A., Tollner, E.W., Gitaitis, R.D., Sumner, D.R., Maw, B.W.,2002b. Classification of sweet onions based on internal defectsusing image processing and neural network techniques.Trans. ASAE 45 (5), 1613–1618.

Singh, K.G., 1975. Use of X-ray analysis in plant quarantine forassessment of seed quality. Malays. Agric. J. 50, 1–11.

Tao, Y., Ibarra, J.G., 1999. Thickness-compensated X-ray imagingdetection of bone fragments in deboned poultry—modelanalysis. Trans. ASAE 43 (2), 453–459.

Tao, Y., Chen, Z., Jing, H., Walker, J., 2001. Internal inspection ofdeboned poultry using X-ray imaging and adaptivethresholding. Trans. ASAE 44 (4), 1005–1009.

Wadhi, S.R., 1983. X-ray radiography in plant quarantine. J. Nucl.Agric. Biol. 12, 87–89.

Yang, E.C., Yang, M.M., Liao, L.H., Wu, W.Y., Chen, T.W., Chen,T.M., Lin, T.T., Jiang, J.A., 2006. Non-destructive quarantinetechnique—potential application of using X-ray images todetect early infestations caused by Oriental fruit fly (Bactroeradorsalis) (Dipteral: Tephritidae) in fruit. Formosan Entomol. 26,171–186.