Image Processing for Stress Cracks in Corn Kernels S. Gunasekaran, T. M. Cooper, A. G. Berlage, P. Krishnan ASSOC. MEMBER ASAE AFFILIATE ASAE MEMBER ASAE ASSOC. MEMBER ASAE ABSTRACT N image processing algorithm was developed for detecting stress cracks in corn kernels using a commercial vision system. White light in back-lighting mode with black-coated background having a small aperture for the light provided the best viewing conditions. The kernel images, when processed using the algorithm developed, produced white streaks corresponding to the stress cracks. Double stress cracks were the easiest to detect. Careful positioning of the kernel over the lighting aperture was necessary for satisfactory detection of single and multiple stress cracks. At present, corn kernels are examined for stress cracks by candling the kernels with a bright light source from below. This procedure is time consuming and fatiguing to the human eye. Gunasekaran and Paulsen (1986) investigated several nondestructive testing techniques for stress crack evaluation. Light reflectance measurement using a helium-neon laser light (632.8 nm) was found insufficient for stress crack detection because reflectance is a surface phenomenon (Gunasekaran et al., 1986). The laser optical method, however, was very successful in detecting external kernel defects. Ultrasonic imaging was also found to be unsuitable because of the need for slicing the kernel very thin to obtain a visual image using ultrasonic energy (Gunasekaran et al., 1986). However, optical imaging has been found to be suitable for stress INTRODUCTION crack evaluation (Gunasekaran, 1985; Gunasekaran and Physical and mechanical stresses developed in corn Paulsen, 1986). Optical imaging or image processing is a kernels as they are harvested, dried, stored, and handled relatively new technique that holds promise for induce various quality defects. Defects such as surface- automatic, on-line quality evaluation and control of splits, starch cracks and chip-offs, caused by mechanical wide-ranging materials (Gagliardi et al., 1984; Kahwati stresses, are external and are easily detectable. However, and Law, 1985). This method essentially duplicates the stress cracks, caused by a combination of thermal, condition as the eye sees an object. A typical image moisture and mechanical stresses, are internal and not processing system receives light from a source; converts readily identifiable. the light into an electrical signal proportional to the Stress cracks can be defined as very fine fissures in intensity of the light received; processes the analog kernel endosperm u n d e r n e a t h the p e r i c a r p . electrical signals into a digital form usable by a Gunasekaran et al. (1985) investigated the size computer; measures and analyzes various characteristics characteristics of stress cracks with the help of scanning of the digital data representing the image; and interprets electron microscope pictures. They concluded that a the image data to obtain useful information. The typical stress crack is about 53 fjim in width and half the resolution of the digital image depends on the number of kernel thickness in depth. The stress cracks were also pixels (picture elements) digitized for each scan line and found to propagate from the center of the kernel and on the number of scan lines used. Proper lighting may not extend to the surface underneath the pericarp. conditions are very important for processing speed and In general, kernels with stress cracks have lower efficiency (Berlage et al., 1984; Gagliardi et al., 1984; mechanical strength (Gunasekaran and Paulsen, 1985) Paulsen and McClure, 1985). and break more readily upon subsequent handling than Image processing applications in agricultural non stress-cracked kernels. Amount of broken corn engineering are rapidly expanding. Quality evaluation of along with foreign matter is a major corn grading factor. various biological materials such as apples (Graf et al., Cracked and broken corn yield lower percentages of 1981); brown rice (Matshuisa and Hosokowa, 1981); fish large grits in dry milling and starch in wet milling than (Shimatachi et al., 1982); seed contaminants (Berlage et undamaged corn. Large grits and starch are two of the al., 1984); and tomatoes (Sarkar and Wolfe, 1985) has valuable prime products of dry and wet milling, been achieved by image processing. Image processing respectively. Moreover, damaged corn is more readily has also been used as an aid to automatic fruit and attacked by microorganisms; and thus has a lower vegetable harvesting (Whittaker et al., 1984; Sites and storage life than undamaged corn. Delwiche, 1985). This article presents the application of image processing technique for detecting stress cracks in corn Article was submitted for publication in July, 1986; reviewed and kernels. approved for publication by the Electrical and Electronic Systems Div. A of ASAE in December, 1986. Published as Miscellaneous Paper No. 1154 of the Delaware Agricultural Experiment Station. The authors are: S. GUNASEKARAN, Assistant Professor, Agricultural Engineering Dept., University of Delaware, Newark; T. M. COOPER, Senior Research Associate, A. G. BERLAGE, Research Leader, USDA-ARS, Oregon State University, Corvallis; and P. KRISHNAN, Assistant Professor, Agricultural Engineering Dept., University of Delaware, Newark. 266 OBJECTIVES The objectives of this investigation were: 1. To determine optimal condition for viewing stress cracks in corn kernels using a computer vision system. 2. To develop an image processing algorithm to identify the presence of stress cracks in corn kernels. © 1987 American Society of Agricultural Engineers 0001-2351/87/3001-0266$02.00 TRANSACTIONS of the ASAE Printer Disk drives Host microcomputer % Vision system computer Processing module X Digitizer and display module Camera / monitor interface Video camera Black & white monitor Fig. 1—Block diagram of the vision system hardware. SYSTEM DESCRIPTION A commercial vision system, Intelledex V200*, was acquired and subsequently upgraded. It was developed with special hardware to interface with cameras and display monitors and with software to implement processing algorithms and drive a vision-to-robot interface. Fig. 1 shows a block diagram of the system hardware. A Hitachi KP-120 solid state video camera was used for image acquistion. A C-mount to bayonet adaptor allowed use of 35-mm SLR photographic lens system. The camera was mounted on a vertically adjustable stand for necessary magnification and resolution. The stand also provided support for lighting sources. In the vision system, the analog camera image is sent to the system computer. The computer consists of three modules: (a) c a m e r a / m o n i t o r interface, (b) digitizer/display module, and (c) processing module. The camera/monitor interface module passes information between the digitizer/display and the camera and monitor. It also controls the gain, timing, and selection of camera from which the image is produced. The digitizer/display module converts the analog camera signal to a digital form that the computer can process and store. Each of the 256 camera scan lines is digitized into a series of 256 discrete picture elements (pixels). Each pixel in this 256 x 256 array has a 6-bit value (range: 0-63) representing the average light intensity over its area. A value of zero is black while a value of 63 is white. The hardware digitizes an image in 0.0167 s. The module has 64 k x 6 bits of static random access memory (RAM) which is used for storing a single digitized image. This image buffer or display RAM holds a single frame for processing or display. * Mention of trade names in this publication is solely for the purpose of providing specific information and does not constitute endorsement by the University of Delaware and the USD A over others of a similar nature not mentioned. Vol. 30(l):January-February, 1987 f Fig. 2—Corn kernels with none, single, double and multiple stress cracks from left to right, respectively. The processing module contains an 8 MHz 8086 central processing unit (CPU), an 8087 numeric coprocessor, 132 kbytes of read only memory (ROM) for VISION BASIC, 256 kbytes of dynamic RAM, and 96 kbytes of CMOS battery-backed RAM. This module executes the vision commands which control the operation of the vision system. Vision generated data are used in decision-making algorithms which are fixed stepby-step procedures for accomplishing a given computational task. The host microcomputer serves as an intelligent terminal. Its main function is to execute the host program which gives the vision system computer access to the host microcomputer's disk drives, screen, and keyboard. A 23-cm (9-in.) black-and-white monitor displays the contents of the vision display RAM. This can be a stored image, or a processed image. PROCEDURE Sample Selection Corn kernels of four varieties namely, FRB73 x Mol7, FRB73 X Va22, Mol7 x HlOO, and (FR4A x FR4C) x Mol7 were used in this investigation. These corn genotypes are grown popularly in the Midwest. The kernels for the experiment were drawn at random from high-temperature dried samples and grouped as those with no, single, double, and multiple stress cracks (Fig. 2). About 25 kernels of each variety and of each stress crack category were viewed individually under the vision system to obtain the images. Illumination The need for proper lighting conditions for efficient image processing has been well established. In this investigation the kernels were illuminated using different lighting modes such as front-lighting, back-lighting, and side lighting. Front-lighting, (illuminating from above the kernels) and back-lighting (illuminating from below the kernel) were provided using the Schott, Model KL1500 fiber optic light source. This light source had a maximum of 150 W power rating and provided a maximum light intensity of about 10 Mix at the fiber optic light guide. A ring light guide mounted on the camera lens was used to obtain a shadow free diffuse lighting for front-lighting. For back-lighting, a flexible fiber optic bundle of 4.5 mm diameter was used. Light intensities at the kernel surface, when illuminated with white light, were measured to be 48.3 klx and 32.3 klx under front and back-lighting modes, respectively. A Wollensak Fastax WF327 type light meter was used for light intensity measurements. The wavelength of the light used for illumination was 267 Fig. 3—Kernel viewing section of the vision system. 1 - Monitor; 2 -Camera; 3 - Fiber optic light source; 4 - Light guide for back-lighting; 5 - Light guide for front-lighting; 6 - Black-coated background. varied using insert filters at the light source. While using white light, the wavelength received by the camera lens was controlled by mounting a suitable filter over the camera lens. A series of filters namely, violet (Wratten 34A, 370 nm); blue (Wratten 47 B, 450 nm); Green (Wratten 61, 515 nm); and red (Wratten 70, 610 nm), were used. For side-lighting a pair of incandescent lamps (18 W) mounted at 45° angle on either side of the kernel were used. The kernels were placed directly under the camera over different backgrounds of frosted glass plate, milky white glass plate, and black-coated wooden plate. These backgrounds were used with each of the above lighting modes to determine the best viewing conditions. The black-coated wooden plate used with back-lighting had a 2.4 mm diameter opening for the light to pass through. Fig. 3 shows a kernel being viewed with back-lighting over the black-coated wooden plate background. This figure also shows the ring light guide mounted on the camera lens for front-lighting. Image Processing Image acquisition and processing were perfromed using a variety of processing algorithms available with the vision system. The algorithm used for stress crack evaluation is similar to high-pass filtering. The pixels representing stress cracks had significantly different gray scale values than the pixels of the rest of the kernel surface. Therefore, gray scale levels of the pixels representing the stress cracks were extracted first by creating an image supressing the gray scale levels of the stress crack part and subtracting this newly created image from the original image. The high-pass filtering used in the image processing algorithm passes high frequencies in the gray scale value, i.e., it passes the pixels with large change in gray scale value (derivative) in relation to the neighboring pixels but not necessarily those pixels with high gray scale values. Following is the sequence and brief description of each of the step: VSNAP acquires the real-time digitized image of the object under the camera and writes it into the display RAM. VDIG is a mode command and does not perform any processing function. It switches the signal shown on the monitor to the current image in display RAM. This step is required only to see the actual processing of the image. 268 The VDIG display is static, and is not affected by the object under the camera. Therefore, once VSNAP and VDIG are performed the sample can be removed from viewing position. This enables acquiring several images at one time for later processing. VSIMAGE stores the digitized image in an image buffer. This original image is later used in the VSUBTRACT step to extract the stress cracks. VENHANCE performs an image enhancement operation on the contents of display RAM. Each pixel in the image is arithmetically averaged with its eight surrounding pixels and a new pixel value is obtained. The action is similar to low-pass filtering; and has the effect of smoothing the contrast of the pixels respresenting the stress cracks that have significantly high gray-scale value compared to their surrounding pixels. VSUBTRACT numerically subtracts the gray-scale value of each pixel of the current VENHANCEd image from the corresponding pixels of the original image stored in the image buffer (obtained by VSIMAGE). As mentioned above, this has the effect of passing those pixels with large rate of change or derivative of gray scale value. Change in gray scale value is usually large at places of discontinuity like a crack. VTHRESH operates based on the threshold gray-scale value used (the numeral following the command). All the pixels with gray-scale value less than the threshold are set to the binary value of zero (black); the rest are set to one (white). Thus, VTHRESH produces a purely black and white image. The images obtained using the above steps showed white streaks corresponding to the presence of stress cracks; but they also contained some spurious streaks which could be mistaken for stress cracks. To eliminate these spurious streaks the image-smoothing step, VENHANCE was repeated several times before VSUBTRACT operation. Additional VENHANCE operations eliminated the spurious streaks, but it also eroded the streaks representing stress cracks. After several trials, repeating VENHANCE three times was found to be optimal. In order to obtain a better stress crack recognition, a contrast enhancement algorithm (VMAP) was added to the program prior to VENHANCE operation. VMAP enables remapping of any or all pixel grayscale values to new values as specified. In the program used, all pixels with gray-scale values less than a chosen lower limit (XL) were set to zero. The pixels with grayscale values greater than (XL + 32) were set to 63. Those pixels with gray-scale values from XL to (XL + 31) were remapped as 2x(I-XL), where I is the gray-scale value of the current pixel. This operation has the effect of doubling the contrast of those pixels with gray-scale values from XL to (XL + 31). The lower limit XL was chosen to be 20 by examining the gray-scale histogram of the original image. The program with VMAP eliminated the spurious streaks and spots within the kernel boundary more effectively. However, this also caused the streaks representing the stress cracks to split and shorten. Therefore, an image-structuring algorithm VDILATE was added to the program. VCOMPRESS compresses the image in display RAM into bit plane zero. A bit plane is a contiguous 8 kbyte TRANSACTIONS of the ASAE block of RAM located in a saved image buffer. The vision system has bit planes 0 to 7 representing 64 k RAM. VCOMPRESS is necessary for the VDILATE operation. VDILATE algorithm dilates contents of bit plane zero by a linear structuring element. Dilation of an image by a structuring element can be defined as the union of the translations of all points in the image to all points in the structuring element. The software allows use of 8 structuring elements, each in a different direction. For stress crack detection, structuring elements in any two opposite directions were found most suitable. A BASIC program of the final version of the processing algorithm is given in the Appendix. RESULTS AND DISCUSSION Front-lighting generally produced lower contrast images than back-lighting. Therefore, even though the stress cracks were visible on the monitor with frontlighting, the information was lost in the processing steps. This is expected because front-lighting images are similar to light reflectance measurements; and reveal only the surface characteristics. Images obtained with side-lighting were similar to those obtained with frontlighting. Even though side-lighting is expected to reveal more of inner characterisitics than front-lighting because of the body reflectance (Gunasekaran et al., 1986), it was not sufficient to bring out the stress cracks. Backlighting, on the other hand, produced images with high contrast between stress cracks and the rest of the kernel surface. Thus, the images obtained with back-lighting, when processed, exhibited bright streaks representing the stress cracks. Back-lighting used in the experiments is similar to the candling procedure currently in use for stress crack detection. The frosted glass and milky white plates used as backgrounds for placing the kernel did not give good results because of huge light dispersion around the kernel. The black-coated wooden plate with a 2.4-mm opening helped to eliminate the light dispersion and provided a better contrast for stress cracks than other two backgrounds. Filters of varying wavelengths used both at the light source and at the camera lens diminished the light intensity reaching the lens and hence produced a lower contrast image than with white light. Therefore, it was determined that using white light (no filters) in the backlighting mode with black-coated plate having a small aperture as the background to be the optimal lighting and viewing condition. The original images of the kernels with single, double, multiple stress cracks and the corresponding processed images are shown in Fig. 4, 5, and 6, respectively. In the processed images the outer lines partially define the kernel periphery; and the stress cracks are represented by the lines inside the kernel boundary. The algorithm performed very satisfactorily in extracting the stress crack details in 90% of the kernels examined. The success rate was determined by comparing the visual evaluation of the kernels for stress cracks with the corresponding evaluation of the vision system using the same set of kernels. Of the three stress crack categories, double stress cracks were the easiest to detect. This is possible because most double stress cracks branch out on either side of the kernel surface, which become highly visible when light is directed at the center of the kernel. Vol. 30(l):January-February, 1987 Fig. 4—Original and processed images of a single stress-cracked corn kernel. In case of single and multiple stress-cracked kernels, the cracks were not clearly seen if the lighting was directly below. Therefore, it was necessary to position the kernel over the aperture slightly off-center to obtain the stress crack images. This problem was more serious with single stress cracks than with multiple stress cracks, because, in case of multiple stress cracks, those parts of the cracks that are around the center of the kernel (or around the lighting area) were visible. One way of solving this problem in an automatic system is by scanning the kernel surface by changing the kernel position two or three Fig. 5—Original and processed images of double stress-cracked corn kernel. 269 centering the kernels over the lighting aperture. 5. Single and multiple stress-cracked kernels required careful positioning over the lighting aperture in order to obtain complete stress crack details. 6. Further improvement in the processing algorithm and/or illumination condition is required to obtain information about very fine cracks and complete crack length. References Fig. 6—Original and processed images of a multiple stress-cracked corn kernel. times, to account for all of the stress cracks. In all three stress crack categroies the faint ends of the stress cracks were not obtained as lines. Also, some of the lines representing stress cracks were not continuous; some faint cracks were not detectable. This was due to the image-smoothing step in the algorithm, which tended to erode the less contrasting portions of the image (the ends of stress cracks). Therefore, further improvements in the processing algorithm and/or illumination conditions are necessary to extract complete stress crack details. In all the figures shown here, the kernel edges are represented by streaks similar to the stress cracks. They are shown to provide better visualization of the kernel boundary. However, these edges can be removed by providing a light seal around the kernel periphery. CONCLUSIONS 1. White light in the back-lighting mode with a black-coated background having a 2.4-mm diameter aperture for the light produced images showing high contrast between the stress cracks and the rest of the kernel surface. 2. An image processing algorithm was developed to produce the effect of high-pass filtering and thus extracting the pixels representing the stress cracks as streaks or lines. 3. The algorithm performed very satisfactorily in detecting stress cracks in 90% of the kernels examined. 4. Double stress cracks were the easiest to detect by 270 1. Berlage, A. G., T. M. Cooper, and R A. Carone. Seed recognition potential of machine vision systems. ASAE Paper No. 84-3059, ASAE, St. Joseph, MI 49085 2. Gagliardi, G. R., D. SulHvan, and N F. Smith. 1984. Computer-aided video inspection. Food Technology 42(4): 53-57, 59. 3., Graf, G. L., G. E. Rehkugler, W. F. Millier, and J. A. Throop. 1981. Automatic detection of surface flaws on apples using digital image processing. ASAE Paper No. 81-3537, ASAE, St. Jospeh, MI 49085. 4. Gunasekaran, S. 1985. A laser optical system for nondestructive detection of corn kernel defects. Unpublished Ph.D. Thesis, University of Illinois, Urbana. 5. Gunasekaran, S., S. S. Deshpande, M. R. Paulsen, and G. C. Shove. 1985. Size characterization of stress cracks in corn kernels. TRANSACTIONS of the ASAE 28(5):1668-1672. 6. Gunasekaran, S. and M. R. Paulsen. 1985. Breakage resistance of corn as a function of drying rates. TRANSACTIONS of the ASAE 28(6):2071-2076. 7. Gunasekaran, S. and M. R. Paulsen. 1986. Automatic, nondestructive detection of corn kernel defects. International advances in nondestructive testing. Vol 12, Gordon and Breach Science Publishers, NY. pp 95-116. 8. Gunasekaran, S., M. R. Paulsen, and G. C. Shove. 1986. A laser optical method for detecting corn kernel defects. TRANSACTIONS of the ASAE 29(l):294-298, 304. 9. Kahwati, G. and P. Law. 1985. Machine vision system assures product quality. Research and Development. October, pp 118-119. 10. Matshuisa, T. and A. Hosokawa. 1981. Possibilities of checking cracks of brown rice using illumination by oblique ray and image data processing system. J. of the Society of Aguricultual Machinery 42(4):515-520. 11. Paulsen, M. R. and W. F. McClure. 1985. Illumination for computer vision systems. ASAE Paper No. 85-3546, ASAE, St. Joseph, MI 49085. 12. Sarkar, N. and R. R. Wolfe. 1985. Feature extraction techniques for sorting tomatoes by computer vision. TRANSACTIONS of the ASAE 28(3):970-974, 979. 13. Shimatachi, Y., Y. Nomura, T. Ide, and O. Itoh. 1982. Application of pattern measurement technique to fish selection. Mitsubishi Electronic Technical Report 56(3): 44-48. 14. Sites, P. W. and M. J. Delwiche. 1985. Computer vision to locate fruit on a tree. ASAE Paper No. 85-3039, ASAE St. Joseph MI 49085. 15. V^hittaker, A. D., G. E. Miles, O. R. Mitchell and L. D. Gaultney. 1984. Fruit location in partially occluded image. ASAE Paper No. 84-5511, ASAE, St. Joseph, MI 49085. APPENDIX BASIC program to implement the image processing algorithm for detecting stress cracks in corn kernels in the Intelledex V200 vision system. 10 20 30 40 50 60 70 80 90 100 110 120 130 'Program to process a corn kernel image to detect stress cracks. 'Choose a lower limit for VMAP operation. A lower limit of 20 'is suggested based on kernel image histogram gray-scale levels. 'VMAP enhances contrast between the pixels representing the stress 'cracks and the rest of the pixels by doubling the gray-scale 'value of the pixels defined by a window. DIM IMAP (63) INPUT "Enter the lower limit", XL F O R I = O t o X L : IMAP(I) = 0: NEXTI FOR I = XL To (XL + 31): IMAP(I) = 2* (I-XL):NEXT I F O R I = ( X L + 32) To 6 3 : IMAP(I) = 6 3 : NEXT I VMAP IMAP TRANSACTIONS of the ASAE 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 'Store contrast enhanced image in image buffer zero. 'VENHANCE the image three times. VSIMAGE 0 FOR I = 1 To 3 : VENHANCE 1: Next I 'Subtract gray-scale value of each pixel of the VENHANCEd image 'from corresponding pixels of the image stored in buffer zero '(VSIMAGE) and add 20. A value of 20 was chosen arbitrarily to 'make the image appear good to the viewer. This, however, wHl 'not affect the end result. You can choose any value. VSUBTRACT 20, 0 Vol. 30(l):January-February, 1987 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 'Choose a threshold value of 22 (this value is relative to the 'number 20 used in the VSUBTRACT step). VTHRESH converts all 'pixels of gray-scale value less than the threshold value to pure 'black (0) and the rest of the pixels to pure white (63). 'Compress the VTHRESHed image in bit plane zero. VTHRESH 22 VCOMPRESS 0 'Restructure the cracks using two directly opposite linear 'structuring elements. Repeat VENHANCE three times. F O R P 3 To 4: V D I L A T E : N E X T I F O R I = 1 To 3: VENHANCE 1:NEXT I END 271