1 Introduction 1.1 Thinning Algorithm Thinning algorithm is a Morphological operation that is used to remove selected foreground pixels from binary images. It preserves the topology (extent and connectivity) of the original region while throwing away most of the original foreground pixels. Figure 1.1 shows the result of a thinning operation on a simple binary image. Original Image Thinned Image Figure 1.1 Thinning is somewhat like erosion or opening. It can be used for several applications, but is particularly useful for skeletonization and Medial Axis Transform. In this mode it is commonly used to tidy up the output of edge detectors by reducing all lines to single pixel thickness [6]. Like other morphological operators, thinning operators take two pieces of data as input. One is the input image, which maybe either binary or greyscale. The other is the structuring element, which determines the precise details of the effect of the operator on the image [5]. 1.2 Mathematical Morphology Mathematical Morphology is the analysis of signals in terms of shape. This simply means that morphology works by changing the shape of objects contained within the signal. Mathematical morphology was developed in the 1970’s by G.Matheron and J.Serra [4]. Morphology has several advantages over other techniques especially when applied to image processing as outlined below: Preserves edge information Works by using shape-based processing Can be designed to be idempotent Machine Vision Thinning Algorithms Page 1 of 14 Computationally efficient Morphology uses ‘Set Theory’ as the foundation for many functions. The simplest functions to implement are ‘Dilation’ and ‘Erosion’. Dilation in 1D is defined as: where A and B are sets in Z. This definition is also known as ‘Minkowski Addition’. This equation simply means that B is moved over A and the intersection of B reflected and translated with A is found. Usually A will be the signal or image being operated on and B will be the ‘Structuring Element’. The opposite of dilation is known as erosion. This is defined as: This definition is also known as ‘Minkowski Subtraction’. The equation simply says erosion of A by B is the set of points x such that B translated by x is contained in A. Morphology has been used in a wide range of applications. A few of the possible applications are listed below: 1.3 Image enhancement Image restoration (i.e. removing scratches from digital film) Edge detection Texture analysis Noise reduction Structuring Element The structuring element consists of a pattern specified as the coordinates of a number of discrete points relative to some origin. Normally Cartesian coordinates are used and so a convenient way of representing the element is as a small image on a rectangular grid. Figure 1.2 shows a number of different structuring elements of various sizes. In each case the origin is marked by a ring around that point. The origin does not have to be in the center of the structuring element, but often it is. As suggested by the figure, structuring elements that fit into a 3×3 grid with its origin at the center are the most commonly seen type. Machine Vision Thinning Algorithms Page 2 of 14 Figure 1.2 Each point in the structuring element may have a value. In the simplest structuring elements used with binary images for operations such as erosion, the elements only have one value, conveniently represented as a one. More complicated elements, such as those used with thinning or greyscale morphological operations may have other pixel values. In the structure element 1’s are represented as the foreground pixels and 0’s are represented as the background pixels. The Blanks are indicated as “don’t care”. When a morphological operation is carried out, the origin of the structuring element is typically translated to each pixel position in the image in turn, and then the points within the translated structuring element are compared with the underlying image pixel values. The details of this comparison and the effect of the outcome depend on which morphological operator is being used. Machine Vision Thinning Algorithms Page 3 of 14 2 Thinning Methods 2.1 General Thinning algorithms can be divided into two broad classes namely iterative and non-iterative. Although non-iterative algorithms can be faster than iterative algorithms they do not always produce accurate results. 2.2 Iterative Thinning The Template-Based Mark-and-Delete Thinning Algorithms are very popular because of their reliability and effectiveness. This type of thinning processes uses templates, where a match of the template in the image, deletes the center pixel. They are iterative algorithms, which erodes the outer layers of pixel until no more layers can be removed [3]. Almost all iterative thinning algorithms use Mark-and-Delete templates including Stentiford Thinning Method. Both Stentiford and Zhang-Suen methods use Connectivity numbers to mark and delete pixels. 2.2.1 Connectivity Number The Connectivity number is a measure of how many objects are connected with a particular pixel. The following is the equation to calculate Connectivity number. Where: Nk is the colour of the eight neighbours of the pixel analyzed. N0 is the center pixel. N1 is the colour value of the pixel to the right of the central pixel and the rest are numbered in counter clockwise order around the center. S = {1, 3, 5, 7} Figure 2.1 The following are the connectivity numbers for Figure 2.1: a) Connectivity number = 0. b) Connectivity number = 1. c) Connectivity number = 2. Machine Vision Thinning Algorithms Page 4 of 14 d) Connectivity number = 3. e) Connectivity number = 4. 2.2.2 Stentiford Thinning Algorithm It uses a set of four 3 x 3 templates to scan the image. Figure 2.2 shows these four templates. Figure 2.2 The Stentiford Algorithm can be stated as following: 1. Find a pixel location (i, j) where the pixels in the image match those in template T1. With this template all pixels along the top of the image are removed moving from left to right and from top to bottom. 2. If the central pixel is not an endpoint, and has connectivity number = 1, then mark this pixel for deletion. Endpoint pixel: A pixel is considered an endpoint if it is connected to just one other pixel. That is, if a black pixel has only one black neighbour out of the eight possible neighbours. 3. Repeat steps 1 and 2 for all pixel locations matching T1. 4. Repeat steps 1-3 for the rest of the templates: T2, T3, and T4. T2 will match pixels on the left side of the object, moving from bottom to top and from left to right. T3 will select pixels along the bottom of the image and move from right to left and from bottom to top. T4 locates pixels on the right side of the object, moving from top to bottom and right to left. 5. Set to white the pixels marked for deletion. Machine Vision Thinning Algorithms Page 5 of 14 Figure 2.3 shows some examples of the thinning process using the Stentiford Algorithm. Figure 2.3 2.2.3 Zhang-Suen Thinning Algorithm This skeletonization algorithm is a parallel method that means the new value obtained only depend on the previous iteration value. It is fast and simple to be implemented. This algorithm is made by two sub-iterations. In the fist one, a pixel I (i , j) is deleted if the following conditions are satisfied [3]: 1. Its connectivity number is one. 2. It has at least two black neighbours and not more than six. 3. At least one of I(i,j+1), I(i-1,j), and I(i,j-1) are white. 4. At least one of I(i-1,j), I(i+1,j), and I(i,j-1) are white. In the second sub-iteration the conditions in steps 3 and 4 change. 1. Its connectivity number is one. 2. It has at least two black neighbours and not more than six. 3. At least one of I(i-1,j), I(i,j+1), and I(i+1,j) are white. 4. At least one of I(i,j+1), I(i+1,j), and I(i,j-1) are white. At the end, pixels satisfying these conditions will be deleted. If at the end of either sub-iteration there are no pixels to be deleted, then the algorithm stops. Figure 2.4 shows some examples of the thinning process using the ZhangSuen Algorithm Machine Vision Thinning Algorithms Page 6 of 14 Figure 2.4 2.3 Non-Iterative Thinning There is a fast non-iterative thinning algorithm proposed by Neusius-Olszewski [2]. It has time complexity of O (n2). 2.3.1 Neusius-Olszewski Algorithm Approach It is possible to state for some black nodes whether they belong to the skeleton or not by examining the kind of their four edges. For example, when there are four incoming edges to a node, the node certainly belongs to the skeleton; it represents a local maximum in this case, and therefore lies in the middle of the object. Unfortunately the nodes found by this method do not building a sound skeleton; the connectivity is not preserved. This is called a pre-skeleton. Further step is necessary construct the skeleton [6]. This algorithm can be summarized as follows: (1) Label all nodes with their minimal distance to an edge of the object. (2) Detects all nodes of the pre-skeleton. (3) Find the remaining skeleton nodes to preserve connectivity. Machine Vision Thinning Algorithms Page 7 of 14 3 Applications of Thinning Algorithm Thinning can be used for several applications such as hand-written character recognition, but it is particularly useful for skeletonization, which has been successfully applied in the following three medical applications [7]: Assessment of laryngotracheal stenosis, Assessment of infrarenal aortic aneurysm, and Unravelling the colon. Each of the emerged three applications requires the cross-sectional profiles of the investigated tubular organs. The proposed process is sketched as follows: Image acquisition by Spiral Computed Tomography (S-CT), (semiautomatic snake-based) segmentation (i.e., determining a binary object from the grey-level picture, Morphological filtering of the segmented object, Curve thinning (by using one of our 3D thinning algorithm), Raster-to-vector conversion, Pruning the vector structure (i.e., removing the unwanted branches), Smoothing the resulted central path, and Calculation of the cross-sectional profile orthogonal to the central path. The above applications were proposed by Dr Kálmán Palágyi who is an associate professor of University of Szegek, Hungary. The following sections describe each application in detail including tests carried out on patients. 3.1 Assessment of Laryngotracheal Stenosis Many conditions can lead to laryngotracheal stenosis (LTS), most frequent endotracheal intubation, followed by external trauma, or prior airway surgery. Clinical management of these stenosis requires exact information about the number, grade, and the length of the stenosis. There is a method developed for assessment of LTS. The cross-sectional profiles (based on the central path) of the upper respiratory tract (URT) were calculated for 30 patients with proven LST on fiberoptic endoscopy (FE). Locations of LTS were determined on axial S-CT slices and compared to findings of fiberoptic endoscopy (FE) by Cohen's kappa statistics. Regarding the site of LTS an excellent correlation was found between FE and S-CT (z=7.44, p<0.005). Site of LTS, length and degree could be depicted on the URT cross-sectional charts in all patients. Machine Vision Thinning Algorithms Page 8 of 14 Figure 3.1 The segmented URT, its central path, and its cross--sectional profile at the three landmarks (vocal cords, caudal border of the cricoid cartilage, and cranial border of the sternum) and at the narrowest position (top); the line chart (bottom). 3.2 Assessment of Infrarenal Aortic Aneurysm The cross-sectional profile in patients suffering from infra-renal aortic aneurysms (AAA) was used. AAA are abnormal dilatations of the main arterial abdominal vessel due to atherosclerosis. AAA can be found in 2% of people older than 60 years. If the diameter is more than 5 cm then the person is at high risk for AAA rupture, which leads to death in 70-90%. For therapy two main options exist: surgery or endoluminal repair with stentgrafts. For optimal patient management the "true diameter" in 3D as well as the distance to the origin of the renal arteries (proximal aneurysma neck) as well as the extension to the iliac arteries (distal aneurysma neck) have to be known. Figure 3.2 Machine Vision Thinning Algorithms Page 9 of 14 The segmented part of the infrarenal aorta and its central path. Along the central path the cross-sectional profile was computed. The following parameters could be derived from this approach: the maximum diameter in 3D as well as the length of the proximal and distal neck of the aneurysma. Since size of the aneurysma is regarded to be a prognosticated factor, the volume of the segmented aneurysma was determined too. At follow-up investigations the same parameters were derived. In order to investigate the correctness of the applied 3D thinning algorithms, some mathematical phantoms were created. Figure 3.3 Two phantoms and their central paths. 3.3 Unravelling the Colon Unravelling the colon is a new method to visualize the entire inner surface of the colon without the need for navigation. This is a minimally invasive technique that can be used for colorectal polyps and cancer detection. Dr. Palágyi has proposed an algorithm for unravelling the colon which is to digitally straighten and then flatten using reconstructed spiral/helical computer tomograph (CT) images. Comparing to virtual colonoscopy where polyps may be hidden from view behind the folds, the unravelled colon is more suitable for polyp detection, because the entire inner surface is displayed at one view. Figure 3.4 The segmented volume of a part of the artificial phantom with two polyps (top) and the same part of the phantom after unravelling (bottom). Machine Vision Thinning Algorithms Page 10 of 14 Figure 3.5 The segmented volume of a part of the cadavric phantom with polyps (top) and the unravelled colon (bottom). Machine Vision Thinning Algorithms Page 11 of 14 4 Discussion and Conclusion The Stentiford method tends to produce lines that follow curves very well, resulting in vectors that most accurately reflect the original image. The Zhang Suen method tends to be better at extracting straight lines from a raster, so may result in more desirable vectors from an original image which comprises mainly straight lines [8]. Finally, since sometimes, when thinning is complete, there are still pixels that could be deleted (principal among these are pixels that form a staircase). It is possible to use Holt’s staircase removal algorithm, which allows half of the pixels in a staircase to be removed without affecting the shape of connectedness of the overall object by applying a template-matching technique. The following (figure 4.1) shows the thinned image resulting from the application of a hybrid implementation based on the merging of the above algorithms in the following order: Stentiford’s pre-processing scheme feeding images into Zhang-Suen’s basic algorithm, with Holt’s staircase removal algorithm as a post-processor [2]. Figure 4.1 Machine Vision Thinning Algorithms Page 12 of 14 Although there are many thinning algorithms proposed over the years they produce some sort of side effects such as necking (figure 4.2(a)), tails (figure 4.2(b)) and hairs (figure 4.2(c)). There is yet to be a thinning algorithm that does not produce any side effect. There are lot of institutes that are undertaking research on thinning, and it is hoped that there will be a perfect thinning algorithm in the near future. Figure 4.2 Machine Vision Thinning Algorithms Page 13 of 14 5 References [1] A Noniterative Thinning Algorithm [online]. Available: http://portal.acm.org/ft_gateway.cfm?id=174604&type=pdf&coll=portal&d l=ACM&CFID=11111111&CFTOKEN=2222222 [2] Computer-assisted analysis of in-vitro vasculogenesis and angiogenesis processes [online]. Available: http://wscg.zcu.cz/wscg2004/Papers_2004_Full/M37.pdf [3] Image Processing Techniques For Machine Vision [online]. Available: http://www.eng.fiu.edu/me/robotics/elib/am_st_fiu_ppr_2000.pdf [4] Mathematical Morphology [online]. Available: http://dmsun4.bath.ac.uk/research/morphology/morphology.htm [5] Morphology Thinning [online]. Available: homepages.inf.ed.ac.uk/rbf/HIPR2/thin.htm [6] Morphology Thinning [online]. Available: http://www.cee.hw.ac.uk/hipr/html/thin.html [7] Skeletonization [online]. Available: http://www.inf.u-szeged.hu/~palagyi/skel/skel.html#Applications [8] Vectorisation Thinning [online]. Available: http://homepage.ntlworld.com/heatons/softsoft/wintopo/help/html/vectoris e.htm Machine Vision Thinning Algorithms Page 14 of 14