Flaw Simulation in Product Radiographs

X-ray inspection machines have been widely used in modern industry to explore the interior of products, and to control product quality. With the advancement of automatic product inspection, we need lots of flaw radiographs to validate the system’s sensitivity and to help tune the automatic inspection parameters. Flaw simulation in product radiographs has been receiving an increasing attention for over two decades.


Introduction
X-ray inspection machines have been widely used in modern industry to explore the interior of products, and to control product quality.With the advancement of automatic product inspection, we need lots of flaw radiographs to validate the system's sensitivity and to help tune the automatic inspection parameters.Flaw simulation in product radiographs has been receiving an increasing attention for over two decades.
Before implementing the program to inspect the work pieces, a large number of sample images are needed to tune the algorithm, examine its performance, and ensure its accuracy.Product radiographs with defects from the production line are the best, however, they are often not available in sufficient quantities or variety.Simulation of casting defects is an alternative approach to deal with this problem.
Recently, the CAD model method, the Monte Carlo method and the generative image method have become the three main approaches for flaw simulation.
1.The CAD model method enables simulations to be produced for complex three dimensional (3D) casting objects.Ray-tracing, together with calculation of the X-ray attenuation, is the basis of this model to produce 3D casting defect simulations.2. Monte Carlo simulation is a method for iteratively evaluating a deterministic model using sets of random numbers as inputs.The creation of a proper physical model is the most critical task for the simulation.3. Generative image model for flaw simulation of the product radiographs has been developed from the idea of the superimposition technique, and is based on defect analysis.
In this chapter, we will discuss flaw simulation in product radiographs.The chapter is organized as follows.Section 2 introduces the CAD models for simulation, the three main parts of CAD models will be discussed including the X-ray source, the geometric and material properties of the objects, and the imaging process.Section 3 presents the applications of the Monte Carlo method for X-ray image simulation, a brief introduction of the Monte Carlo method and how to combine it in the simulation application are discussed.Section 4 concludes with the generative image model for flaw simulation in radiographs, the generative models and simulation results are outlined, the authors themselves have produced significant results in this field.Section 5 concludes and offers suggestions for further research.Finally, a reference list is provided for further reading.
be projected back though the modelled object to the X-ray beam source.Since it is very difficult to make the X-ray source from the x-ray tube into a single point light source, this can be seen from Fig. 1.The "source", which refers to the area of the emitter aperture should be very small, to minimise the blurring of the edges of the work piece in a radiograph or on the film, the enlarged circle in Fig. 1.
Fig. 1.The X-ray imaging system with the problems of the source and object edges in the radiograph The X-ray attenuation law is the basis of the simulation process (Haken &Wolf, 1996): where is the incident radiation intensity, is the transmitted intensity, x is the thickness of the object, and is the energy attenuation associated with the material.The gray value of the simulated image can be computed as follows: www.intechopen.com

Flaw Simulation in Product Radiographs
103 where is the incident radiation intensity with energy E, ∆Ω is the solid angle that corresponds to the pixel observed from the source point, represents the attenuation of material i at energy E, and is the total path length through material i. Fig. 2 is an example of a work-piece radiograph simulated from a CAD model and attenuation data.Fig. 2. A three-dimensional (3D) model of a workpiece and its generated radiograph Some flaws, such as cavities, can be simulated as nil X-ray absorption and others, such as incrusted material, with a different attenuation coefficient .We rewrite the equation (1) as following: Where d is the thickness of the flaw.If the flaw is a cavity with zero absorption, = (Mackenzie & Totten, 2006).Fig. 3 shows the small cavities in a workpiece on the left and on the right the simulated X-ray image compared with its real radiograph in the middle.In this technique, the entire object, including its defects, will be built up by independent CAD software.It offers excellent flexibility for setting objects and flaws, but it is not convenient and user friendly.The object itself may be complicated.It is time consuming to build up such a complicated model, moreover, in which every point should be calculated according to the attenuation law to form a simulated radiograph.What we need is to show flaws where they may appear on a real product.It is possibly easier to build up the flaw model only and superimpose the simulated flaws onto a real X-ray radiograph.

CAD models for flaw only
There is a serious disadvantage in the first approach.Building up an entire CAD model of the object and computing each pixel of the simulated image make the enormous computation.The second approach can be regarded as an improvement of the first one.In this technique, a 3D modelled flaw is projected and superimposed onto a real X-ray image.
The gray value displayed from the captured CCD image can be expressed as a linear function of the transmitted radiation: where x is the thickness of the object.If there is a cavity with thickness d, according to equation ( 3), the equation will be changed into: According to equation ( 4), can be substituted by − : In an X-ray image, the brightest point I max is obtained when the thickness is zero and the darkest point I min is obtained when the thickness is a maximum.
With equation ( 6) and ( 7), B can be estimated as following: In this technique, a 3D flaw model, the material absorption coefficient , and a real X-ray image are needed.Then, parameter B is estimated according to equation ( 9).The 3D flaw model with thickness d is projected and superimposed onto the real X-ray image using equation (6).The new gray value of a pixel, including the projected 3D flaw, comes from equation ( 6).All we need are the absorption coefficient and the flaw thickness (Mery, 2001).
The original gray value provides us part of the information needed.The work required in this approach is much less than in the first approach.But in this approach, we don't consider the solid angle ∆ of the X-ray beam that is projected onto the pixel, which generates an error.

Coordinate system
The CAD model and the X-ray source use virtual 3D world coordinates, but the image uses 2D digital image coordinates.We need to transform between these two systems.3D coordinates can be denoted as: We assume that the digital image has the horizontal and vertical scale factors and .The focus distance is f.To maintain the projected system, the projected plane must be placed within the focus distance f.If the digital image has size (x max , y max ) pixels, the projected plane must have the physical size of , ⁄ ⁄ millimetres.It means that the projected plane samples every ⁄ millimetres horizontally and ⁄ millimetres vertically during the simulation process.A pixel m=(x, y) in the simulated image can be converted into in the 3D coordinate system while , is the origin of the projected plane.To simulate the flaw there are 4 steps needed.First, capture a real X-ray image, and take the parameters f, K u and K v , (x max , y max ) ; Second, build a 3D flaw model as a 3D mesh; Third, position the 3D flaw in the virtual coordinate system and simulate the X-ray capture process, obtaining a depth map matrix W(x,y) which stores the length travelled within the component of each ray that penetrated the 3D flaw.Finally, compute the new gray value with the depth matrix using equation (6).A single ray is emitted from every pixel of the 2D image to the X-ray source.The distance travelled by the ray inside the flaw will be calculated and stored in the depth matrix (Hahn & Mery, 2003).

Discussion of CAD model simulation
First, each intersection alternates the state of the ray from outside to inside.The final depth is the sum of all internal traces and the attenuation calculation of the X ray will be difficult for irregular product shape.
Second, the computation is enormous.Every pixel of the simulated image needs to emit a ray to penetrate the 3D model to the source.For simplification, we assume that the X-ray comes out from a point source.But actually, the X-ray source is not an ideal point source and it has a scatter effect.Another cause that extends the computation is the shape of the projected plane.The projected plane is by definition a plane with the central pixel closer to the X-ray source than the corner pixels.The intensity of the X-rays is stronger in the middle.We know a perfect detector would be a spherical one which is far more complicated in coordinate computation.
Third, the CAD model is not user friendly.A three-dimensional CAD model is needed as seen from Fig. 2, but building up such a CAD model is a time consuming job.Although the second approach doesn't need an entire object model, the 3D flaw model is needed.However there are no prepared parameters for flaws normally.Considering the stochastic shape of the most defects, generating 3D CAD flaw model, which have to be created before all other calculation and projection, is a key technique, because using a fixed CAD model lacks randomization of flaw models.
Finally, there is a lack of description language and criteria for man-made 3D flaws.It's hard to tell whether man-made flaws are like or unlike real flaws.

Monte Carlo methods
A brief introduction of Monte Carlo methods is presented to better understand the concept and the four steps that Monte Carlo methods usually follow.An example of estimating π is summarised and the applications are discussed.

Introduction
The Monte Carlo method was developed in the 1940s by John von Neumann, Stanislaw Ulam and Nicholas Metropolis, while they were working on nuclear weapon projects (Manhattan Project) in the Los Alamos National Laboratory.It was named in homage to the Monte Carlo Casino, a famous casino, where Ulam's uncle would often gamble away his money (Metropolis, 1987).
Monte Carlo methods are a class of computational algorithms that rely on repeated random sampling to compute their results.Monte Carlo methods are often used in simulating physical and mathematical systems.These methods are most suited to calculation by a computer and tend to be used when it is infeasible to compute an exact result with a deterministic algorithm.
Monte Carlo methods are especially useful for simulating systems with many coupled degrees of freedom, such as fluids, disordered materials, strongly coupled solids, and cellular structures.They are used to model phenomena with significant uncertainty in inputs, such as the calculation of risk in business.They are widely used in mathematics, for example to evaluate multidimensional definite integrals with complicated boundary conditions.When Monte Carlo simulations have been applied in space exploration and oil exploration, their predictions of failures, cost overruns and schedule overruns are routinely better than human intuition or alternative "soft" methods.

www.intechopen.com
Flaw Simulation in Product Radiographs 107

Steps
Monte Carlo methods vary in different situations, but tend to follow these particular and simple steps: 1. Define a domain of possible inputs.2. Generate inputs randomly from a probability distribution over the domain.
3. Perform a deterministic computation on the inputs.4. Aggregate the results.
For example, consider a circle inscribed in a unit square.Given that the circle and the square have a ratio of areas that is π/4, the value of π can be approximated using a Monte Carlo method (Kalos &Whitlock, 2008): 1. Draw a square on the ground, and then inscribe a circle within it.2. Uniformly scatter some objects of uniform size (grains of rice or sand) over the square.
3. Count the number of objects inside the circle and the total number of objects.4. The ratio of the two counts is an estimate of the ratio of the two areas, which is π/4.Multiply the result by 4 to estimate π.
In this procedure the domain of inputs is the square that circumscribes our circle.We generate random inputs by scattering grains over the square then perform a computation on each input (test whether it falls within the circle).Finally, we aggregate the results to obtain our final result, the approximation of π.
To get an accurate approximation for π this procedure should have two other common properties of Monte Carlo methods.First, the inputs should truly be random.If grains are purposefully dropped into only the centre of the circle, they will not be uniformly distributed, and so our approximation will be poor.Second, there should be a large number of inputs.The approximation will generally be poor if only a few grains are randomly dropped into the whole square.On average, the approximation improves as more grains are dropped.

Applications
Monte Carlo methods are especially useful for simulating phenomena with significant uncertainty in inputs and systems with a large number of coupled degrees of freedom.Areas of application include: physical sciences, engineering, computational biology, applied statistics, games, design and visuals, finance and business, telecommunications, etc.

Monte Carlo and computer simulation
Computer simulation had developed rapidly just after the invention of the computer and the first large-scale deployment is to model the process of nuclear detonation.In this simulation, the scientists used a Monte Carlo algorithm.

Monte Carlo and computer simulation
A computer simulation is a computer program that attempts to simulate an abstract model of a particular system.Computer simulations have become a useful part of mathematical modelling of many natural systems in physics (computational physics), astrophysics, chemistry and biology, human systems in economics, psychology, social science, and engineering.Simulations can be used to explore and gain new insights into new technology, and to estimate the performance of systems too complex for analytical solutions.
Computer simulation developed hand-in-hand with the rapid growth of the computer, following its first large-scale deployment during the Manhattan Project in World War II to model the process of nuclear detonation.It was a simulation of 12 hard spheres using a Monte Carlo algorithm.Computer simulation is often used as an adjunct to, or substitute for, modelling systems for which simple closed form analytic solutions are not possible.
There are many types of computer simulations; the common feature they all share is the attempt to generate a sample of representative scenarios for a model in which a complete enumeration of all possible states of the model would be prohibitive or impossible.

Monte Carlo simulation software
Many software systems and computer platforms can perform Monte Carlo simulation tasks, Matlab and C++ are the most well-known.Some specially-designed software systems for Monte Carlo simulation are very popular with researchers.Two of them will be introduced below.

EGSnrc
The EGSnrc system (EGSnrc, URL) is a package for the Monte Carlo simulation of coupled electron-photon transport.Its current energy range of applicability is considered to be 1 keV to 10 GeV.The EGS acronym stands for Electron Gamma Shower, and EGSnrc is an extended and improved version of the EGS4 package originally developed at Stanford Linear Accelerator Center (SLAC).In particular, it incorporates significant improvements in the implementation of the condensed history technique for the simulation of charged particle transport and better low energy cross sections.

GoldSim
GoldSim is the premier Monte Carlo simulation software solution for dynamically modelling complex systems in business, engineering and science (GoldSim, URL).GoldSim supports decision and risk analysis by simulating future performance while quantitatively representing the uncertainty and risks inherent in all complex systems.Organizations worldwide use GoldSim simulation software to evaluate and compare alternative designs, plans and policies in order to minimize risks and make better decisions in an uncertain world.

X-ray images simulation by Monte Carlo methods
As the X-ray imaging system must be modelled by Monte Carlo simulation, the physical principles of an X-ray imaging system will be introduced firstly.Two publications with the corresponding models and the simulation results are discussed.

Principles of the X-ray imaging system
Typical X-ray imaging systems consist of a point X-ray source and an image recording device (detector).The object to be imaged is placed between the X-ray source and the detector.The images are produced by local reduction in the intensity of the primary X-rays produced by the X-ray source reaching the detector through the internal structure of an object in their path.These local intensity reductions correspond to the distribution of absorption (attenuation) in the object under study.The special amount of attenuation by the object depends, in turn, on its thickness, its chemical composition, and the X-ray energy.
Besides the source and detector, other auxiliary devices exist in a real imaging system.The schematic diagram is illustrated in Fig. 6.
Fig. 6.The schematic depiction of an X-ray imaging system.They try to get the X-ray images from this simulation model directly.Two main steps can be summarised as below: 1. Modelling The energy spectrum, polarization and profile of the incident beam can be defined so that Xray imaging systems can be modelled.Photoelectric absorption, fluorescent emission, elastic and inelastic scattering are included in the model.The detailed model and the complicated mathematical descriptions can be found in the literature (Bottigli et al., 2004).

Simulation
The Monte Carlo method is employed in the course of simulation.The core of the simulation is a fast routine for the calculation of the path lengths of the photon trajectory intersections with the grid voxels.The selected simulation result can be seen in Fig. 7 below.
In this experiment, only the absorption is considered, i.e. the photons from scattering or fluorescence emission are discarded.This type of simulations is useful for testing the correctness and the speed of the procedure for numerical integration of the absorption along an arbitrary path inside a grid.The CPU time for the simulation of one projection image was about 3 seconds using a PC based on a PENTIUM IV 1800MHz processor.

Scattered image simulation model
Different from the direct imaging model, the scattered image model focuses on simulating the scattered image.The final image can be obtained by subtracting the scattered image from the real image taken during the inspection.Frank Sukowski et al. provided a simple description of this model in (Sukowski & Uhlmann, 2011).
A lot of effects affect the image quality in radioscopy systems.By optimizing the throughput of the inspection system it is of essential interest to suppress all effects reducing the image quality.One effect e.g. is the scattered X-ray radiation from inside the specimen during inspection which hits the detector and reduces the contrast and sharpness of the projection.This effect leads to reduced possibility of detection of small defects.With the Monte Carlo simulation is it possible to simulate the scattering effects in the specimen and also the distribution of the scattered radiation on the detector.If we know the intensity distribution of the scattered radiation from the specimen on the detector, it can be subtracted from the real image taken during the inspection.With this operation it is possible to get images of the specimen with nearly zero intensity of scattered radiation resulting in better contrast and higher sharpness of the image.The author believes that simulation is the only way to get a realistic and not approximated intensity distribution of scattered radiation.In Fig. 8 the simulated projection of a step wedge and the simulated intensity distribution of the scattered radiation are shown.

Discussion about Monte Carlo simulation method
Monte Carlo simulation is a method for iteratively evaluating a deterministic model using sets of random numbers as inputs.This method is often used when the model is complex, nonlinear, or involves more than just a couple uncertain parameters.An X-ray based imaging system is a very complex system including lots of factors which can affect the final image.To simulate this kind of complex system with a Monte Carlo method, to build a proper model, is difficult and important.In this research area there is no readily available model that can be followed, even a tiny difference of hardware or device position can lead a very different model, and the objects under inspection can also affect this model.Another problem is the computing cost of simulation, which may be extremely high due to the model complexity.However, the Monte Carlo method is a very powerful tool to solve complex simulation problems, and its application in X-ray imaging systems is still being explored.

Generative image for flaw simulation in product radiographs
Defect superimposition is another technique that attempts to simulate casting defects.It differs from the CAD approach in the process of defect creation using 2D image technology, to superimpose the simulated casting defects onto real radioscopic images (Filbert et al., 1987).It needs neither complex 3D software packages nor a model of the casting specimen under test, furthermore, it offers a radioscopic image of a real product with a range of possible defects to test, validate and measure the accuracy of different radiograph analysis procedures, or for tutorial and training purposes.

Image generation technology
The image generation technology for flaw simulation of product radiographs is developed from the idea of the defect superimposition technique, and is based on defect analysis.The descriptions of defects or flaws defined by different standard organizations for specimens or products use a language and high level semantics which can be understood by engineers and workers in the field.Though many sample images are used as standards and are available for demonstration, they cannot include all because almost any defects in the products are distinguished greatly from others in their shapes, grey contrasts, salience of edges, size of areas, girth of counters etc.The defects are recognized from a product X-ray image normally depending on an understanding of the descriptions or definitions of the flaw but also rely on the calculation of their image parameters.We can generate flaw images according to the image semantic interpretation rather than depend heavily on the system parameters of the X-ray imaging or CAD models which provide the geometrical parameters of products.
The flaw generation process, as shown in Fig. 9, consists of five steps.The first step is defect image collecting.Though the definition for one kind of defect is uniform or unique, images have great variety, i.e. polymorphism in the defect formation.From a certain number of defect samples, the qualitative visual features are extracted and analysed.In the second step, which is a key step called "seed feature"or main high frequency feature creation process, the defect images are formed or grown from it.Simultaneously, the fuzzy image representations for each type of feature are expected to apply to the image generation after obtaining the qualitative features and statistical analysis, fuzzy membership is needed and is applied to these image features in the third step.The fourth step is generating low frequency features in the regions of the creative defect, to subject the defect appearances to their semantic definitions.The last step is image synthesizing or superimposing the created flaw image onto real product radiographies.

Fuzzy image representations
Qualitative visual features Fig. 9. Phases of flaw image generation for product radiographs

Defect image collecting
As X-ray radiation is passed through the material under test, and a detector senses the radiation intensity attenuated by the material, a defect in the material modifies the expected radiation received by the sensor.The contrast in the X-ray image between a flaw and a defect-free area of the specimen is distinctive.In an X-ray image we can see that the defects, such as voids, cracks, or bubbles, show up as bright areas compared to their background, i.e. the imaging of defect-free material.
Defects are defined according to their appearances, as many different kinds are described by the natural language along with some radiograph images, as we can see in Fig. 10.The images shown in Fig. 10 are chosen from the reference radiographs presented by The American Society for Testing and Materials (ASTM) E155 (Hoff, 1999).These are standard radiographs of castings produced to help the radiographer make appropriate assessments of the defects in casting components.
As discussed in detail in the NDT Resource Center (Iowa State University, 1996), the characteristics of casting defects, the discontinuities produced by gas porosity or blow holes, sand and dross inclusions, various kinds of shrinkages, are summarized in 'radiography-NDT course material' (Iowa State University, 1996) are quoted here: 1. "Gas porosity or blow holes are usually smooth-walled rounded cavities of a spherical, elongated or flattened shape caused by accumulated gas or air which is trapped by the metal.The gas or air will be trapped as the molten metal begins to solidify while the sprue is not high enough to provide the necessary heat transfer needed to force the gas or air out of the mold.2. Sand inclusions and dross are nonmetallic oxides, which appear on the radiograph as irregular, dark blotches.These come from chipped parts of the mold or core walls and/or from oxides which have not been skimmed off prior to the introduction of the metal into the mold gates.3. Shrinkage has various forms of discontinuity occurring in all cases as the molten metal shrinks as it solidifies in all parts of the final casting.Shrinkage in its various forms can be recognized by a number of characteristics on the radiographs.There are at least four types of shrinkage: (a) cavity; (b) dendritic; (c) filamentary; and (d) sponge types.Some documents designate these types only by number to avoid misunderstanding.Their characteristics are summarized in the following: (a) Cavity shrinkage appears as areas with distinct jagged boundaries.It may be produced when metal solidifies between two original streams of melt coming from opposite directions to join a common front.Cavity shrinkage usually occurs at a time when the melt has almost reached solidification temperature and there is no source of supplementary liquid to feed possible cavities.
(b) Dendritic shrinkage is a distribution of very fine lines or small elongated cavities that may vary in density and are usually unconnected.
(c) Filamentary shrinkage usually occurs as a continuous structure of connected lines or branches of variable length, width and density, or occasionally as a network.
(d) Sponge shrinkage shows itself as areas of lacy texture with diffuse outlines, generally toward the mid-thickness of heavier casting sections.Sponge shrinkage may be dendritic or filamentary.Filamentary sponge shrinkage appears more blurred as it is projected through the relatively thick coating between the discontinuities and the film surface." The X-ray image is usually captured with a frame-grabber and stored in a matrix.The size of the image matrix corresponds to the resolution of the image.The gray value between 0 and 255 associated with the image brightness denote from the one hundred percent black to white in an image.Tuned by the voltage and current for the X-ray tube, the gray intensity of a product and its defects will vary significantly, that means the contrast between the defect and its background will change, the examples shown in Fig. 11, in which the tube current is 1.5mA but the tube voltages are varied from 110KV to 105KV and 75KV in each from left to right.From the pictures in Fig. 11 we can see that not only the contrast of the defects against their backgrounds vary in every image but the brightness of the defects also changes.Although using high voltage, the defect in the left image is the darkest compared with the defects in the other two images with relatively low voltages, and the contrast around the defect in the left image associated with its background is very low.
It is necessary to collect the sample defect radiographs and classify them into different semantic categories and if possible, get their radiographs with different voltages.

Visual feature analysis and nonparametric sampling
Deduced from example-based technique for image generation, the nonparametric sampling and modelling that relies on the qualitative visual feature analysis contributes to set up nonparametric models for both main construction of defects, their texture synthesis and other low frequency information.The introduction of nonparametric sampling and defect image reconstruction leads to an intricate feature analysis problem.Here we mention two different classical nonparametric sampling and modelling approaches, one is a stochastic defect counter based on a hierarchical template model and the other is a skeletonizationbased model.

Counter based hierarchical template model
Most casting defects are located on the inner part of the work pieces, as seen in Fig. 12, where the two diagrams on the left are typical of actual radiographs with defects generated from the production line, the images sizes are 540 540  pixels, and the others are the diagrams of what is seen when the porosity defects are cut from the actual images and magnified to display with image sizes of 200 200  pixels.The intensities of casting defects in the radiographs are usually lighter than the parts around them.If the work pieces have different structures and shapes, the defects with the same size often appear as different grey values on different work pieces.This is a result of the different absorption of the X-rays by the metal due to the different thicknesses.The energies required for X-ray penetration of the thicker structures are significantly higher, and the grey values of the casting defects are strongly affected by the corresponding backgrounds.This is illustrated in Fig. 12, showing casting defects in casting products.Though it is not easy to classify them into type one or type two defects, all of them are single large and discontinuous.The aim of this paper is to generate simulated defects similar to these real ones.

Fig. 12. The sample defects in real casting pieces
The cavities, as shown in Fig. 13 (a) and (b), are both single large casting defects, however, they are considered separately as blow hole and shrinkage defects, and they differ greatly in appearance and volumetric measurement from the porosity defect shown in Fig. 13 (c).Based on the principle of Active Qualitative Vision (Aloimonos, 1990), an initial shape needs to be designed to provide a starting point followed by the adjustment of the following image parameters during the simulation: grey level value, shape, size, orientation, shading effects, and contrast with background.The random shape template is designed as three embedded nesting stencil-plates, as illustrated in Fig. 14, in which the shapes of each template can be given randomly but their sizes are limited so that every smaller one of three shapes fits entirely inside the larger one for the appropriate grey value adjustment.The analysis and the measurement of the profiles of the largest cavity defects, from all of our casting defect images, leads to a size for the profile of the largest stencil-plate of 78x46 pixels (1cm=31.889pixels), which approximates to the size of the single defect profiles that appear normally in casting pieces.
From Fig. 14 and from the physics of the x-ray process it is easy to find that the middle of the cavities is normally brighter than their edges.For convenience the higher gray value is set to the middle of the entire shape; and also there is a general requirement for the template set that their areas vary, with the smaller being totally enclosed by the larger.
With the proposed defect creation algorithm, the stencil-plates are not limited in shape, and changes in their formation will not significantly influence the outcome of the generated defects.Furthermore, the templates used are binary images.The white parts in the templates are the shapes used in the defect simulation.Though these white parts are not the exact final shape of the simulated defects, they approximate to the final shape having some of the features of real casting defects with smooth, continuous, and irregular contours.

Fig. 14. The sample defects in real casting pieces
We use one of shapes in Fig. 14 to design the superposing operation to locate the simulated defect onto a specified region of the original X-ray image; this superposing operation can be used by all stencil-plate superposition, the details can be found in reference paper (Huang, et al., 2009).

Skeletonization based model
The skeleton of some dendritic flaws such as filamentary shrinkage and dendritic shrinkage in castings or cracks in any materials can be the main feature or so called 'seed feature' to let simulated flaws grow from it.Skeletonization is a process for reducing foreground regions in a binary image to a skeletal remnant that largely preserves the extent and connectivity of the original region while throwing away most of the original foreground pixels (Gonzalez, 2008).It can be a key step when extracting the nonparametric features from a sample defect.To see how this works, imagine that the foreground regions in the input binary image are made of some uniform slow-burning material.Light fires simultaneously at all points along the boundary of this region and watch the fire move into the interior.At points where the fire travelling from two different boundaries meets itself, the fire will extinguish itself and the points at which this happens form the so called "quench line".This line is the skeleton.Under this definition it is clear that thinning produces a sort of skeleton.
The dash line in set A denotes its skeleton S(A), as shown in Fig. 15,the notion of a skeleton.

Fig. 15. Set A and its skeleton denoted by dashed lines
The skeleton of set A can be expressed in terms of erosions and openings as following: Where B is a structuring element, and A⨁kB indicates k successive erosions of A K times, and K is the last iterative step before A erodes to an empty set.In other words, The formulation states that S(A) can be obtained as the union of the skeleton subsets S k (A).Also, it can be shown that A can be reconstructed from these subsets by using the equation Where (() Another term medial axis transform (MAT) is often used interchangeably with skeletonization but they are not quite the same.The skeleton is simply a binary image showing the simple skeleton, while MAT is a graylevel image where each point on the skeleton has an intensity which represents its distance to a boundary in the original object, shown in the Fig. 16.The medial axis of an object is the set of all points having more than one closest point on the object's boundary.In mathematics the closure of the medial axis is known as the cut locus.
In 2D, the medial axis of a plane curve S is the locus of the centres of circles that are tangent to curve S in two or more points, where all such circles are contained in S. (It follows that the medial axis itself is contained in S.) The medial axis of a simple polygon is a tree whose leaves are the vertices of the polygon, and whose edges are either straight segments or arcs of parabolas.The medial axis together with the associated radius function of the maximally inscribed discs is called the medial axis transform , which is a complete shape descriptor, meaning that it can be used to reconstruct the shape of the original domain.
According to American Society for Testing and Materials (ASTM), Filamentary shrinkage usually occurs as a continuous structure of connected lines or branches of variable length, width and density, or occasionally as a network.From Fig. 17 we can see that, the most obvious feature is the continuous tree structure, wider in the trunk and thinner in the branches.In grayscale, the parts closer to the center of the structure are darker.The outside part is lighter and the branches are between the centre and the outside part.Because of its structure and features, the skeleton description is one of the best.In the application, several layers of skeletons are needed, as showing in Fig. 17, the simple and the complicate skeletons for the left dendritic shrinkage are as Fig. 17(c) and (d), which will be used to represent different parts of the defects, some like trunks and some branches.Apart from sample defects, skeletons can also be created randomly such as for cracks or filamentary shrinkages, and so on.Please refer Fig. 18.

Visual feature analysis and fuzzy representation
Since the qualitative visual features are fuzzy, so a fuzzy representation of them is appropriate.Set the image grayscale range [1, Ng], μ is defined as the membership function of the gray value in a specified image area, it makes the gray value mapped to [0, 1].On a view, like a factor image with piexls point to a single point of ambiguity in the original image, its corresponding values indicate the membership degree that the image point belongs to the object region.All the pixels in the image form a single dot fuzzy matrix expressed with μ (I).
The following eight fuzzy geometric features impact on the accuracy and speed of operation with more good compromise effects.The image size is M × N, the μ (I) is denoted by μ, the membership definitions of these fuzzy geometric features and the classification functions for the object structures are as follow: 1. Area: Area is the weighted sum of the pixels in an object image range.
2. Circumference: Circumference pixel horizontal distance and vertical distance weighted and is used to measure the undulations of the image area.
Height is the total number of the largest membership of the rows of the image, and width isthe total number of the largest membership of the columns of the image.The height and width can be used, respectively, to reflect the image of certain areas in the overall vertical and horizontal directionfeatures.

Length
Length is the total number of the largest membership of the rows of the image, width is the total number of the largest membership of the columns of the image.The use of the X-ray image can be described in certain regions in the vertical and horizontal distribution of the extreme characteristics of the membership.

= (25)
The characteristic quantity is the fuzzy area defined by the length and width of the moment shaped area ratio, length and width defined by the area of image certain areas of the largest possible area of fuzzy.

Generation of the low frequency information
No matter how the generative flaw image is rendered from a creative counter or from a simple skeleton, the counters or skeletons normally are the crucial characteristics of most inner defects of the materials and are used mainly to produce the similar perceivable structures with the original flaw.While some types of flaws are not obvious in their high frequency information, but present as apparent textural features such as shrinkages of needle cavity and small round cavity as well as sponge shrinkage showing in Fig. 19 (Hoff, 1999).Efros and Leung (1999) have proposed a nonparametric model to synthesize an output image from a given metric sample.Their approach works surprisingly well for a wide range of textures.Their algorithm consists of the following steps: 1.The output image is initialized with a random noise whose histogram is equalized with respect to the histogram of the input sample.
2. For each pixel in the output image, in scan-line order, the already-synthesized values in neighbourhood of current pixel z of specific size N(z) is considered and is compared with all possible neighbourhoods from the input sample.The value of the input pixel x with the most similar N(x) is then assigned to z.
Efros & Leung's algorithm is significantly useful for some kinds of defect simulation.After, initialize a synthesized texture with a 3x3 pixel "seed" from the source defect texture, for every unfilled pixel which borders some filled pixels, find a set of patches in the source image that most resemble the unfilled pixel's filled neighbors.Choose one of those patches at random and assign to the unfilled pixel a grey value from the center of the chosen patch, and do it repeatedly.The only crucial parameter is how large a neighbourhood you consider when searching for similar patches.As the "window size" increases, the resulting textures capture larger structures of the source image.The finer details of this approach can be found in the Efros' paper.The other problem which arises from radiograph simulation is to merge together the generated flaws with the workpiece or other parts of the background image.In a similar manner to the heat diffusion equation, the image diffusion technique is adopted, which is discussed below.

Imagediffusion technique
Embedding simulated flaws into the objects' radiographs, which is called augmented reality in the simulation research field, is not an avoidable step and is important both in simulation application and the technology of image superimposing.Take the X-ray penumbra into account, we know that the edges of the defects are blurred and sometimes fused with their background, furthermore, the grey values of the defect vary when the background changes, constrained by the law of X-ray attenuation and simultaneity, the grey values of the workpiece and its defect vary enormously in the large range of tube potential.
Similar to the effects of the heat diffusion equation, image diffusion is suitable for edge preserving blur and can be used widely in a flaw superimposing into a real radiograph, the apparent visual characteristics of blurred edges by diffusion can be seen from Fig. 20.To an initial image u(x,y,0) change to be image u(x,y,t) after a time t, the anisotropic diffusion first proposed by Perona and Malik (1990) is denoted as: where ∇u x, y, t is the gradient of the image and g x, y, t is diffusion coefficient, which can be isotropic or anisotropic and depends on different applications.Teboul et al.(1998) further discussed the conditions of the coefficient g x, y, t and three constraints are given as follows: 1.There are many research contributions to the diffusion coefficient function, such as Gauss Smoothing Diffusion (Catte, et al. 1992), Morphological Diffusion(Segall& Acton, 1997), Degeneration Diffusion Mode (You, et al. 1995)Statistical Diffusion Mode (Black, et al. 1998), Curvature Diffusion Mode (Alvarez, et al. 1992), but the anisotropic diffusion models are illposed, it is difficult to determine the convergence condition.In the flaw simulation, we still rely on the qualitative visual feature analysis of real radiographs.

Synthesizing and generating radiographs
The flaws generated in Fig. 21, follow a similar procedure though their 'seed features' differ from greatly from each other.After analysis of sample images and grouping them into different defect categories, extract their qualitative visual features; choosing the 'seed feature' and decide the flaw rendering approach such as the template method or the skeletonization method or texture synthesizing.Based on statistical analysis, calculate thefuzzy image representations for each type of feature, which are expected to be relevant for the image generation, fuzzy membership as needed is applied to these image features

Conclusion
X-ray defect simulation is associated with many uncertainties in terms of shape, inconsistancy of grey values and the blurring of simulated defect edges against the background.The approaches discussed in this section have shown how to simulate and create various kinds of defects including stochastic large discontinuity defects and regular shape defects such as circular and elliptical spots, which can be used to build a sample library for testing and tuning automatic inspection programs.The new defect superposition methods using nesting stencil-plates, texture generation as well as skeletonization have been shown to be able to simulate the normal range of casting defects.These new methods are not only capable of simulating the casting defects, but also able to be used to simulate irregular objects in different kinds of X-ray images.Apart from the crucial high frequency image features that were adopted to render the structures of the flaws, the anisotropic diffusion method has received more attention as nearly all the objects appearing in radiographs have shading effects, which could be visually represented by diffusion technology.
Compared with the CAD model and the Monte Carlo method, the advantages and characteristics of image generation method, that is the augmented reality simulation method, can be summarized as: (1) It has more randomness and flexibility and provides a better match for the shape variability of the defects: (2) The 'seed features' are not limited in shape or size, and changes in their form will not significantly influence the simulated defects.
(3) Many and varied defects can be created by the user and added to a real casting piece image.The program is easy to use and, by choosing and tuning the parameters, it can be used for the majority of casting pieces without any advanced measurements on the work piece.(4) The program works directly on the radiographs, and the location for the simulated defect can be chosen randomly by the user in any X-ray image.(5) Since no part of the programme is based on a CAD platform, there is no need of a CAD software package or any other database, the defect simulation function can be organized as a program module and integrated into the casting automatic inspection system to share the stored data.

Fig. 3 .
Fig. 3.The 3D image of a work-piece at left volume and its radiograph in the middle and the simulated image at right

Fig. 4 .
Fig. 4. Very simple simulated casting defects compared with the real ones
imaging simulation model U. Bottigli et al. developed a voxel-based Monte Carlo simulation model of X-ray imaging.
Fig. 7.The simulation result of the voxel-based Monte Carlo simulation model.(a) is the experimental image, and (b) is the simulated image.

Fig. 8 .
Fig. 8.The scattered image simulation.The left half is the simulated projection of a step wedge, and the right half is the simulated scattered image.

Fig. 10 .
Fig. 10.The sample patterns of the American Society for Testing and Materials (ASTM).(a) gas porosity or blow holes (b) shrinkage of needle cavity(c) shrinkage of round cavity (d) sponge shrinkage (e) sand inclusions or dross (f) filamentary shrinkage (g) dendritic shrinkage

Fig. 11 .
Fig. 11.The radiographs with different tube voltage for the same specimen, the tube voltage used from left to right are separately 110KV, 105KV and 75KV and all with tube current 1.5mA

Fig. 13 .
Fig. 13.Sample defects in real casting pieces By careful inspection of the visual features of about 2000 images of casting defects, we have found that stochastic shapes with closed defect contours are the most prominent features.Based on the principle of Active Qualitative Vision (Aloimonos, 1990), an initial shape needs to be designed to provide a starting point followed by the adjustment of the following image parameters during the simulation: grey level value, shape, size, orientation, shading effects, and contrast with background.The random shape template is designed as three embedded nesting stencil-plates, as illustrated in Fig.14, in which the shapes of each template can be

Fig. 16 .
Fig. 16.Skeletonization of a binary image, from left to right: the original binary image, normal skeletons, the skeleton image formed by the medial axis transformation

Fig. 17 .
Fig. 17.Skeletonization of a real dendritic shrinking for flaw simulation: (a) a radiograph of a workpiece, (b) zoomed dendritic shrinking, (c), (d) the skeleton images based on binarized images of different thresholds

Fig. 19 .
Fig. 19.Defect texture, from left to right: shrinkages of needle cavity and small round cavity as well as sponge shrinkage

Fig. 20 .
Fig. 20.The original panda image with the diffused ones on their right

Fig. 21 .
Fig. 21.Comparison simulated flaws with real defects on different products, at the third row the original is on the left and the simulated is on the right