- Research Article
- Open Access
- Published:

# Appling a Novel Cost Function to Hopfield Neural Network for Defects Boundaries Detection of Wood Image

*EURASIP Journal on Advances in Signal Processing*
**volume 2010**, Article number: 427878 (2010)

## Abstract

A modified Hopfield neural network with a novel cost function was presented for detecting wood defects boundary in the image. Different from traditional methods, the boundary detection problem in this paper was formulated as an optimization process that sought the boundary points to minimize a cost function. An initial boundary was estimated by Canny algorithm first. The pixel gray value was described as a neuron state of Hopfield neural network. The state updated till the cost function touches the minimum value. The designed cost function ensured that few neurons were activated except the neurons corresponding to actual boundary points and ensured that the activated neurons are positioned in the points which had greatest change in gray value. The tools of Matlab were used to implement the experiment. The results show that the noises of the image are effectively removed, and our method obtains more noiseless and vivid boundary than those of the traditional methods.

## 1. Introduction

X-ray wood nondestructive testing is an effective method for accessing to internal information of wood. Comparing with other conventional wood nondestructive testing, such as appearance judgment, acoustic emission testing, ultrasonic testing, microwave testing, and stress wave testing, this method can acquire distinct wood internal structure images by an X-ray imaging system. Through the wood images, the positions of wood defects can be easily identified; the scales of the defects can be roughly estimated. Furthermore, we can make use of computer technology to automatically extract wood defects information from the images for automatically identifying defects characteristics such as areas, types, and severity, which can help making the optimal sawing solution. However, extracting accurate defects information depends on the accurate boundary detection. There are many edge detection algorithms. Most previous edge detection algorithms used first-order derivative operators such as the Sobel edge operator [1, 2], the Roberts edge operator, and the Prewitt edge operator [3]. If a pixel point is on the boundary, its neighborhood will be a zone of transition. The Laplacian operator [4] is a second-order derivative operator and is used to detect boundary at locations of the zero crossing. The Canny operator [5, 6], another gradient operator, is used to determine a class of optimal filter for different types of boundaries. All these operators detect boundary points by gray gradient change of the image pixels in the neighborhood; the disadvantage of these methods are sensitive to noise.

Comparing with traditional edge detection methods, Hopfield neural network, which regarded an edge detection process as an optimization process, has been applied in the field of the low-level image processing of boundary detection in the recent years. Chao and Dhawan [7] used a Hopfield neural network to perform edge detection on a gray-level image. The results were found to be comparable to a Sobel operator on gray-level noisy images. Chang [8] applied Contextual-based Hopfield neural network to medical image edge detection and designed the specific energy function for the medical images. The results showed that the method can obtain better edge points than the conventional methods. Active contour model (Snake) [9] was used in image processing these years [10–13]. Zhu and Yan [10] attempted to combine Hopfield neural network with active contour model for brain image boundary detection. That method showed the results comparable to those of standard "snakes-" based algorithms, but it requires less computing time.

In this paper, we presented a novel approach to automatically detect wood defects boundaries using a modified Hopfield neural network with a specific cost function designed for wood defects image. The boundary detection problem in this paper was regarded as an optimization process that sought the boundary points to minimize a cost function. Hopfield neural network was used as computational networks for solving optimization problems. Because of its highly interconnected structure of neurons, the network was not only very effective in computational complexity, but also very fault tolerant. In consideration of the accuracy of the detection, an initial boundary must be estimated before using the Hopfield neural network. Every pixel in the image with an initial boundary was represented by a neuron which was connected to all other neurons but not to itself. The image was considered as a dynamic system which was completely depicted by a cost function. The states of the neurons updated according to the cost function till the convergence. Then, the result image was given by the states of the neurons. The tools of Matlab were applied to implement the experiment in this paper. The results showed that our method can obtain more continued and more accurate boundary points than the traditional methods of boundary detection.

The remainder of this paper is organized as follows. In Section 2, a basic imaging principle of X-ray and a wood nondestructive detection imaging system are described. A Hopfield neural network theory and its application in solving optimization problems are illustrated in Section 3. Section 4 discusses how to implement the boundary detection algorithm using a Hopfield network. This section is divided into four phases. We first discuss how to initiate defects boundaries, then how to map the boundary detection problem into a Hopfield neural network, and then a novel cost function for wood defects boundaries detection is described. Finally, we illustrate the summary of the algorithm. In Section 5, experimental results and a discussion are given. We illustrate a conclusion and a perspective in Section 6.

## 2. X-Ray Wood Nondestructive Detection Theory

X-ray detection method has been widely applied in the field of wood nondestructive detection in recent decades. As the major application way using X-ray, wood defects image was acquired first by an X-ray image system. Then, wood defects and other internal structure features were detected by subsequent evaluation methods.

### 2.1. Basic Imaging Principle of X-Ray

X-ray is a kind of electromagnetic wave which has shorter wavelength than visible lights. It can penetrate a certain thick opaque body. After penetrating the body, the intensity of X-ray is related to the property and thickness of the body and energy of the X-ray. For a monochromatic narrow beam X-ray (which has a single wavelength), when it penetrates a thin part of homogeneous substance which part has a thickness as , the decay intensity of the X-ray is proportional to incident ray intensity and thickness of the substance, as . Therefore, after the X-ray has intensity as , penetrating homogeneous substance has a thickness as , the intensity of the X-ray is

where, is the intensity of incident ray, is the intensity of transmitted ray, is the thickness of the substance, and is the attenuation coefficient. It is the basic attenuation principle of monochromatic narrow X-ray [14]. An attenuation diagram of X-ray imaging law is shown in Figure 1. In the practical testing, the X-ray from the source is a broad beam and continuous spectrum ray, which includes different energy photons, so the attenuation formula is complex. The attenuation coefficient of broad beam and continuous spectrum ray changes with increasing of thickness of the penetrated substance. When the thickness gets a threshold value, the attenuation coefficient gets nearly a fixed value. In this case, the continuous spectrum ray can be approximately regarded as monochromatic ray.

### 2.2. X-Ray Wood Nondestructive Detection Imaging System

The block diagram of X-ray wood nondestructive detection imaging system is shown in Figure 2. The system used in our experiment is capable of producing wood defects images. The log will be placed between the X-ray source and the image intensifier. The X-ray source gives off the X-ray which will be absorbed partly by the wood material when it penetrates the objects. Absorption quantity is related to the types and the density of log defects. The attenuation of X-ray in the logs reduces the energy, reflected in different degrees of activating the same image intensifier screen. The visual information of image intensifier is transmitted to a computer by a CCD camera. The digital signals transmitted by the A/D converter circuit from the simulation signals are deposited in the image storage system for the wood defects image detection.

## 3. Hopfield Neural Networks

### 3.1. Basic Theory of Hopfield Neural Networks

The Hopfield neural network is one of the most famous artificial neural network models. As a recurrent neural network, it is constructed from a single layer of neurons, every of which has feedback connections to all other neurons, but not to itself. Figure 3 shows a diagram of a Hopfield neural network structure with four neurons.

Every neuron in a Hopfield neural network has computational capabilities, which can process an input and give a relevant output. If the th neuron is described by two variables: its input and its output . The output is the state which is computed by a given activation function . The transformation is described as

In a discrete model, is a discrete variable with a value of zero or one.

The input of the th neuron is related to the weighted sum of other neurons and their corresponding weights which was described as an interconnection of strength. The interconnection of strength between the th neuron and the th neuron is represented by . For ensuring the network convergence, the interconnective strengths are constrained to be symmetrical, which means that . In addition, each neuron has a bias of fed to its input. The input, or the current state of the th neuron, is updated by a function described as

In a Hopfield neural network, a neuron can not only be used for an input neuron, but also an output neuron. Every Hopfield neural network has a so-called cost function (or an energy function), which is used for measuring stability of a Hopfield neural network. Signals were circularly transmitted in the whole network. The operation course can be regarded as a recovered and strengthened processing for an input signal. In the course, the network approach gradually to a stable state when the cost function is minimized. If a problem can be mapped to the task of minimizing a cost function, the Hopfield neural network will be implemented to obtain an optimal (or near optimal) solution.

### 3.2. Hopfield Neural Networks for Solving Optimization Problem

Hopfield neural networks have been used successfully in solving optimization problems such as the traveling salesman problem (TSP) [15–17]. In recent years, take advantage of their optimization computation capabilities, Hopfield neural networks were applied in image processing [18–20]. Mapping a practical problem to an energy function is a key step for Hopfield neural networks to solve optimization problems. The basic form of the energy function was described in the literature [21] as

The general steps for solving optimization problems are described as follows.

First of all, an objective function of a problem should be illustrated by the penalty function method. The designed optimization problem is

is the number of the restriction. The objective function is

is a sufficiently large constant. may have different dereferencing. By comparing each term in (5) with the corresponding terms in (6), we can determine the network parameters, the inter-connective strength , and the bias of each neuron. Secondly, the dynamic equation of the network is written out. For a continuous network, the dynamic equation can be calculated by

For a discrete network, the dynamic equation can be calculated by

After obtaining the dynamic equation, the original inputs can drive the network till it achieves a stable state. Then, the optimization result is worked out.

## 4. Hopfield Neural Networks for Wood Defects Boundary Detection

The boundary detection problem in this paper was regarded as an optimization process that sought the boundary points to minimize a cost function. Hopfield neural network was used as computational networks for solving optimization problems.

### 4.1. Initiate Boundary

An initial boundary must be estimated before using our Hopfield neural network boundary detection method. The Canny detector was selected to implement the initiation. The Canny detector is the most powerful edge detector provided by function edge. In the Canny algorithm, an image is smoothed using a Gaussian filter with a specified standard deviation, , to reduce noise. The local gradient, , and edge direction, , are computed at each point. An edge point is defined to be a point whose strength is locally maximum in the direction of the gradient. The algorithm then tracks along the top of these ridges and sets to zero all pixels that are not actually on the ridge top so as to give a thin line in the output. Finally, the algorithm performs edge linking by incorporating the weak pixels that are 8-connected to the strong pixels. Figure 4(b) shows the processed wood defects images by Canny algorithm. Figure 4(a) is an original wood image with a defect of crack. Figure 4(c) shows the image that Figure 4(a) merged Figure 4(b). Effective edge detection can be implemented using the Canny algorithm. We can get a good detection result, less noise, and single lines. However, the edge points do not exactly match the actual boundary of the crack, while the edge can be regarded as the initiate boundary of the Hopfield neural network boundary detection.

### 4.2. Boundary Detection with a Novel Cost Function

Once we have found the initial boundary of a defect in a wood image, we determine an approximate region where the actual boundary is most likely to be located. A slight adjustment can be made to seek the actual boundary which will be implemented by a Hopfield neural network.

To design such a neural network with an energy function for an entire image is impossible and impractical. However, we noticed that the influence is small between two distant elements. Thus, a small window is applied to the image. The neurons inside the window are fully connected to each other. The correlation between the central element and the element outside the window can be ignored without affecting the final result [22].

In this window, every pixel in the image is represented by a neuron. As shown in Figure 5, a two-dimensional (2D) binary Hopfield neural network is constructed. All the initiate boundary points estimated by the Canny operator are mapped to the 2-D network. The number of rows equals the number of rows of initial boundary image, while the number of columns equals the number of columns of initial boundary image. Each neuron is denoted as a point , where and . A binary output, 0 (for resting) or 1 (for activate), is assigned to each neuron representing the absence or presence of boundary elements.

According to (4), we can define the energy function of the 2-D Hopfield neural network as

where is the binary state of the neuron in row and column , is the interconnection weight between the neuron in row and column and the neuron in row and column . A neuron in the network receives weighted inputs from the neuron and a bias input from outside. The total input to neuron is computed as

The output of each neuron is computed as

and the activation function in the network is defined by

The states of the neurons corresponding to the initial boundary points are activated. As the network is running, the operating rule drives the network towards to the direction of minimizing the energy function, while the neurons representing the actual boundary points are activated gradually. Therefore, the energy function should be designed to meet that the energy of the network is minimum when the neurons corresponding to the actual boundary points are activated. An objection function meeting the above conditions are described as

where is the output of the neuron in row and column , is the initial value of the neuron in row and column . is the gray value of the original wood defects image. and are constant coefficients.

The first term of the energy function ensures that fewer neurons are activated except the neurons corresponding to the actual boundary points in each row. The second term ensures that the activated neurons are positioned in the points which have greatest change in gray value.

By expanding (13) and comparing each term with the corresponding terms in (9), we can determine the network parameters, the inter-connective weights , and the bias inputs as

where if and zero otherwise. Once the parameters and are obtained using (14), each neuron can evaluate and adjust its state according to (10) and (12).

Once the initial state of the neurons has been set, the Hopfield neural network begins to work continuously until the energy function of the network stops decreasing. Through the network evolutions, the optimal (or near optimal) boundary points are detected. The position of these activated neurons indicates the detected boundary locations.

### 4.3. Summary of the Algorithm

The algorithm of wood defects boundary detection using the Hopfield neural network can be summarized as follows.

Step () Set the initial state of the neurons based on the initial boundary points which is detected by the Canny edge detection algorithm.

Step () Calculate the input of each neuron, , using (10).

Step () Calculate the output of each neuron, , using (11).

Step () Check the state of neurons; if the state does not change comparing with the last state, stop; otherwise, go back to step ().

Step () The final states of neurons are the output result of the network, which represent the final boundary points.

## 5. Experimental Results and Discussion

The purpose of our boundary detection approach is to detect boundaries of wood defects in an image and separate it from normal wood structure. Once isolated, the detected defect can be further processed for recognition of defect type and other defect characteristic. To show that the proposed method have good capability of boundary detection, the proposed method is compared with the conventional methods such as Sobel edge operator, Roberts edge operator, Prewitt edge operator, Laplacian operator, and Canny operator.

Matlab is a high-level technical computing language. We can solve technical computing problems faster than with traditional programming languages such as C and C++. It has a toolbox of image processing which have some traditional image processing functions such as Sobel, Roberts, Prewitt, Laplacian, and Canny. We can conveniently implement the traditional image processing methods by some simple commands. M-files are macros of Matlab commands that are stored as ordinary text files. An M-file can be either a function with input and output variables or a list of commands. All macros of image processing commands in Matlab are stored in M-files. We can program the proposed commands using M-files to implement some works of image processing including the Hopfield neural network method.

A computer program coded by M-files of Matlab7.0 was used to implement the proposed method. The values of the parameters and were determined by the experiment. The value was set to 0.5, while the value of was set to 0.05. The initial boundary points were estimated using the Canny edge algorithm, and the result image was shown in Figure 4(b). The conventional methods were implemented by the image processing toolbox of Matlab7.0. The original wood images used for evaluating the method were acquired from the X-ray wood nondestructive detection imaging system. Figure 6 shows an original X-ray wood image with a crack on it. Figures 7, 8, 9, 10, and 11 show separately the boundary detection images using Sobel edge operator, Roberts edge operator, Prewitt edge operator, Laplacian operator, and Canny operator. Figures 12, 13, and 14 show separately the boundary detection images using our method with different thresholds of which are separately −0.006, −0.005, and −0.004.

Comparing with conventional boundary detection methods, this approach converted a boundary problem to an optimization process that seeks the boundary points to minimize a cost function. The gray value of image pixel was described as the neuron state of Hopfield neural network. The state updated till the cost function touches the minimum value. The final states of neurons were the result image of boundary detection. Taking advantage of the collective computational ability and energy convergence capability of the Hopfield network, the noises will be effectively removed. The experimental results showed that our method can obtain more noiseless and more vivid boundary points than the traditional methods of boundary detection.

## 6. Conclusion

An X-ray imaging technique was applied in wood nondestructive detection. Through wood images acquired by this technique, the wood defects information such as locations, scales, and types was visual. The detected defects can be further processed for recognition of defects types and other defects characteristics.

Hopfield neural network was applied in the boundary detection of wood images. We designed a novel cost function for a Hopfield neural network to detect a defect boundary as solving an optimization problem. After the boundary initiation using Canny edge algorithm, a slight adjustment can be made to seek the actual boundary which will be implemented by a Hopfield neural network with the cost function. Those points that decreased the network energy were detected as boundary points. Taking advantage of the collective computational ability and energy convergence capability of the Hopfield neural network, the experiment received a good result. As shown in the Figures 6–14, the method based on Hopfield neural network in detecting boundary of wood defects was effective; the noises were effectively removed. We can get a more noiseless and vivid wood defect boundary. Thus, a promising method of wood boundary detection based on Hopfield neural network with a novel cost function is provided. All the courses of image processing and building a Hopfield neural network in this paper were implemented using the tools of Matlab. The tools of Matlab are well done in the study of images.

## References

- 1.
Davis LS: A survey of edge detection techniques.

*Computer Graphics Image Processing*1975, 4: 248-270. 10.1016/0146-664X(75)90012-X - 2.
Lu D-S, Chen C-C: Edge detection improvement by ant colony optimization.

*Pattern Recognition Letters*2008, 29(4):416-425. 10.1016/j.patrec.2007.10.021 - 3.
Gonzalez RC, Woods RE, Eddins SL:

*Digital Image Processing Using MATLAB*. Publishing House of Electronics Industry, Beijing, China; 2004. - 4.
Gonzalez RC, Woods RE:

*Digital Image Processing*. 2nd edition. Publishing House of Electronics Industry, Beijing, China; 2002. - 5.
Canny J: Computational approach to edge detection.

*IEEE Transactions on Pattern Analysis and Machine Intelligence*1986, 8(6):679-698. - 6.
Xu X, Yang Z, Wang Y: A method based on rank-ordered filter to detect edges in cellular image.

*Pattern Recognition Letters*2009, 30(6):634-640. 10.1016/j.patrec.2008.12.009 - 7.
Chao CH, Dhawan AP: Edge detection using Hopfield neural network.

*Proceedings of Conference on Applications of Artificial Neural Networks, 1994*2243: 242-251. - 8.
Chang C-Y: A contextual-based Hopfield neural network for medical image edge detection.

*Proceedings of the IEEE International Conference on Multimedia and Expo (ICME '04), June 2004*1011-1014. - 9.
Kass M, Witkin A, Terzopoulos D: Snakes: active contour models.

*International Journal of Computer Vision*1988, 1(4):321-331. 10.1007/BF00133570 - 10.
Zhu Y, Yan H: Computerized tumor boundary detection using a hopfield neural network.

*IEEE Transactions on Medical Imaging*1997, 16(1):55-67. 10.1109/42.552055 - 11.
Hamou AK, El-Sakka MR: Optical flow active contours with primitive shape priors for echocardiography.

*EURASIP Journal on Advances in Signal Processing*2010, 2010:-10. - 12.
Zheng Y, Li G, Sun X, Zhou X: A geometric active contour model without re-initialization for color images.

*Image and Vision Computing*2009, 27(9):1411-1417. 10.1016/j.imavis.2009.01.001 - 13.
Yang Y, Gao X: Remote sensing image registration via active contour model.

*AEU—International Journal of Electronics and Communications*2009, 63(4):227-234. 10.1016/j.aeue.2008.01.003 - 14.
Liu Z:

*Modern Ray Detection Technology*. China Standard Press, Beijing, China; 1999. - 15.
Rößler JF, Gerstacker WH: On the convergence of iterative receiver algorithms utilizing hard decisions.

*EURASIP Journal on Advances in Signal Processing*2009, 2009:-8. - 16.
Wen U-P, Lan K-M, Shih H-S: A review of Hopfield neural networks for solving mathematical programming problems.

*European Journal of Operational Research*2009, 198(3):675-687. 10.1016/j.ejor.2008.11.002 - 17.
Hopfield JJ, Tank DW: 'Neural' computation of decisions in optimization problems.

*Biological Cybernetics*1985, 52(3):141-152. - 18.
Pajares G, Guijarro M, Ribeiro A: A Hopfield Neural Network for combining classifiers applied to textured images.

*Neural Networks*2010, 23(1):144-153. 10.1016/j.neunet.2009.07.019 - 19.
Cierniak R: A 2D approach to tomographic image reconstruction using a Hopfield-type neural network.

*Artificial Intelligence in Medicine*2008, 43(2):113-125. 10.1016/j.artmed.2008.03.003 - 20.
Sammouda R, Sammouda M: Improving the performance of Hopfield neural network to segment pathological liver color images.

*International Congress Series*2003, 1256: 232-239. - 21.
Hopfield JJ: Neurons with graded response have collective computational properties like those of two-state neurons.

*Proceedings of the National Academy of Sciences of the United States of America*1984, 81: 3088-3092. 10.1073/pnas.81.10.3088 - 22.
Lu S, Wang Z, Shen J: Neuro-fuzzy synergism to the intelligent system for edge detection and enhancement.

*Pattern Recognition*2003, 36(10):2395-2409. 10.1016/S0031-3203(03)00083-9

## Author information

### Affiliations

### Corresponding author

## Rights and permissions

**Open Access** This article is distributed under the terms of the Creative Commons Attribution 2.0 International License (https://creativecommons.org/licenses/by/2.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

## About this article

### Cite this article

Qi, D., Zhang, P., Zhang, X. *et al.* Appling a Novel Cost Function to Hopfield Neural Network for Defects Boundaries Detection of Wood Image.
*EURASIP J. Adv. Signal Process.* **2010, **427878 (2010). https://doi.org/10.1155/2010/427878

Received:

Revised:

Accepted:

Published:

### Keywords

- Cost Function
- Boundary Detection
- Active Contour Model
- Solve Optimization Problem
- Hopfield Neural Network