Straight Line Detection Using Hough Transform In Gray Images

In image processing, one of the main difficulties encountered in line detection is due to the various appearances of lines to be detected. This research presents a recognition method for line using Hough Transform (HT) .Applying erosion continuously to reach one pixel width of the generated skeleton for the image. Presented results are illustrating the utility of a new approach to know the content of an image, then store it using it's parameters and reconstruct it without the need to open it. Introduction: In computer vision, edge and line detection is a process which attempts to capture the significant properties of object in the image, since lines correspond to local extreme of the Grey level image and are of great use in the identification of image features, such as roads and rivers in remote sensing images and character recognition for example. However, the recognition of line has been studied by many researchers. It is still one of the difficult pattern recognition problems . Most schemes for the detection of line are limited to thinning algorithms. The majority of these algorithms are designed for binary images and a few for Grey level images. Kubais S.AL-Fahady Khalil I. AL-Saif & Sundus k. AL-Awbaidi 12 For manipulating line drawings with a computer, a Hough transform (HT) can be used to extract the lines in digital form from the pictures. The HT is a well accepted object detection method. It requires an explicitly chosen class of objects for detection (e.g., lines) and a parameterization of this class which describes all possible "idea" instances of the object . The HT has emerged in recent decades as a powerful method for many image processing and pattern recognition applications. However, a major drawback of its implementation in large images is its relatively low speed , also there is a big problem with end points of the lines for those methods, which used Hough transform. Other information for HT algorithm can be found in. Vector is a compact form of data, describing the geometry of a bar (straight-line segment with nonzero width) and other line shapes using a small number of attribute values. A raster image, in contrast, conveys less semantics and requires much more space to store a large amount of pixels for the purpose of describing the same graphic object. The role of vectorization is to convert graphic objects in a raster image to vector form. It can be used as a preprocessing for OCR . In general, a coding scheme for line structures must satisfy objectives: 1It must faithfully preserve the information of interest. 2It must permit compact storage and be convenient for display ; and 3It must facilitate any required processing. Recognition Procedure: The procedure adopted in this research consists of 5 modules: Digitization, preprocessing, thinning, Features extraction, and feature storing. 1-Digitization The first phase in the line recognition process is digitization. Documents to be processed are first scanned and digitized. A 300-dpi scanner is used for this. The image input to the picture processing system is a photonegative of a line drawing. The continuous image (photonegative) is converted by an image sampling and quantization process to equally spaced samples arranged in the form of an array where each element of the array is a number between 1 and 256, representing the intensity value at the corresponding picture point. Straight Line Detection... 13 2Preprocessing First, the noise in the input image is removed by binarization. Next, the obtained binary image F(X,Y) (figure 1(a)) is normalized so that the size of rectangle circumscribing the pattern is 100*100 pixels. Consequently, the normalized image F (X,Y) is obtained (figure. 1(b)). This operation is described as follows : F′ (X,Y)=F( (Width*X) / 100 + DX , (Height * Y ) /100 + DY ) ,-----(1) Where, Width and Height are that of the pattern, respectively. Then DX and DY are the horizontal and vertical distances between the left top corners of the image and the rectangle, respectively. Figure 1: Preprocessing and feature extraction. 3Thinning Thinning is irreversible operations that seek to reduce a connected region of pixels of a given property set to a smaller size. It reduces a region to minimal cross-sectional . The thinning operation removes foreground pixels such that an object without holes erodes to a minimally connected stroke that is equidistant from its nearest outer boundaries. If the object has holes, the object erodes to minimally connected ring located half-way between each hole and its nearest outer boundary. The thinning algorithm adopted in this paper can be found in . Figure (2) illustrates an original scanned image and the resulting skeleton after applying thinning algorithm. Kubais S.AL-Fahady Khalil I. AL-Saif & Sundus k. AL-Awbaidi 14 Figure 2: (a) The original image. (b) The thinning image 4Feature Extraction Object extraction techniques depend on the quality of the data noisy or inaccurate data demand more robust algorithms and more carefully turned parameters. The feature extraction steps involve the line description. Straight and curved line segments form the basic structure of many pictures. In such images a mathematical relationship of detected points on an object boundary provides a symbolic description of the image. The approach to the establishments of mathematical relationship is line-to-point transformation. The approach to line description used in this paper is as follows: 4-1 Line-to-Point Transformations In this paper the Hough transform is used to detect a straight line in a binary image. It is a technique which can be used to isolate features of particular shape within an image. Because it requires that desired features be specified in some parametric form, the classical Hough transform is most commonly used for the detection of regular curves such as lines, circles, ellipses, etc.. We can analytically describe a line segment in a number of forms. However, a convenient equation for describing a set of lines uses parametric or normal notion: P = X cos (θ) + Y sin (θ) -------------------------(2) Where P is the normal distance of the line form the origin and θ represents the slop angle of the line with respect to the X-axis, it is clearly illustrated in figure (3 ) . The HT of the line is simply a point at coordinate (P,θ) in the polar domain . After ending this stage we obtained a two dimensional H (P,θ) in a parametric space. Straight Line Detection... 15 Figure 3: parametric space 4-2 Determine Lines in Image In these stage end points for a straight line has been determined in image using the following algorithm: 1For any element in H(P,θ) satisfying H(P,θ) > TL (TL : represents a straight line detection in the image, i.e. the location of strong peaks in the HT matrix H(P,θ)), calculate its line equation by using two points P1(C,0), P2(0,B) as follows: (see figure (4)) Slop = tan (θ) A = P / cos (90-θ) B = P / cos(θ) _______ Rot = √A + B (A*X) + (B*Y) – (B*A) = 0 --------------------(3) Figure 4: illustrated the two end points of a line. Kubais S.AL-Fahady Khalil I. AL-Saif & Sundus k. AL-Awbaidi 16 2For any element in the image (x, y) satisfying (x, y ) = "1", calculate the distance (D) between this point and line equation follows: | A * X + B * Y – A * B | D = —————————— --------------------(4) Rot -If (DT) or (DIS>TOL). -Save last point location as end point for line (X2,Y2). Note : any pixel or position in the image (x, y) has been checking it will be deleted. 3repeat steps 1,2 until last element in H(P, θ). After feature extraction stage we obtained end points table for all line in the binary image which is called (LIST table). It is clearly illustrated in table (1) . Straight Line Detection... 17 5-Storing Features In this phase we store the lines in a file, the storing algorithm adopted in this research can be summarized as follows: 1-Given LIST (is a double linked list that contains information (x1,y1,x2.y2 ) for each line in image ). 2create a new file. 3Define the parameters A,B,C. 4Initialize each parameter to zero. 5For each line in LIST: -Calculate the slop by dy/dx , (dy = y2-y1, dx=x2 – x1 ). If a line is horizontal then A =A+1, Else if a line is vertical then B =B+1 , Else C=C+1 6Store first number of columns ( no. of Pixels in row ) for image, then Total line (A+B+C) , next number of horizontal lines (A), vertical lines (B), slant line (C) . This information represented header file , see table (2). 7Store (x1,y1,x2,y2) for each line in a file with the following order: Kubais S.AL-Fahady Khalil I. AL-Saif & Sundus k. AL-Awbaidi 18 aHorizontal lines. bVertical lines. cSlant lines. This information represented data file, the structure used for this data is : Data structure : { int x1,y1,x2,y2 ; } Table (3) below illustrates the information after this stage. Experimental Result A set of images, include different form of lines with all expected slops, are used to test the recognition algorithm. Image of Figure (5) contains different samples of intersected lines. This image is processed using this research algorithm and the result is illustrated in table (4) and table (5). Table (3,5) show a very useful information about the lines really these information are the line description by the two end points [x1,y1,x2,y2], so the lines parameters can be seen clearly from the information stable . Figure 5: (a) the original image . (b) the thinning image Straight Line Detection... 19 Conclusions This paper, which uses Hough transform as a main tool, lines with different shapes [horizontal, vertical and slant] and different length are detected, and the lines parameters which are described by the two end points can give the line length and its slop which is used later to reconstruct the lines again. Hough transform work better on images have little noise, with this paper by using a preprocess on the images and thinning algorithms, the noisy images can be treated for line detection. Also the st


Introduction:
In computer vision, edge and line detection is a process which attempts to capture the significant properties of object in the image, since lines correspond to local extreme of the Grey level image and are of great use in the identification of image features, such as roads and rivers in remote sensing images and character recognition for example [15] .However, the recognition of line has been studied by many researchers.It is still one of the difficult pattern recognition problems [1][8] [10] .Most schemes for the detection of line are limited to thinning algorithms.The majority of these algorithms are designed for binary images and a few for Grey level images [14] .
For manipulating line drawings with a computer, a Hough transform (HT) can be used to extract the lines in digital form from the pictures.The HT is a well accepted object detection method.It requires an explicitly chosen class of objects for detection (e.g., lines) and a parameterization of this class which describes all possible "idea" instances of the object [9] .The HT has emerged in recent decades as a powerful method for many image processing and pattern recognition applications.However, a major drawback of its implementation in large images is its relatively low speed [12]   , also there is a big problem with end points of the lines for those methods, which used Hough transform.Other information for HT algorithm can be found in [6] .
Vector is a compact form of data, describing the geometry of a bar (straight-line segment with nonzero width) and other line shapes using a small number of attribute values.A raster image, in contrast, conveys less semantics and requires much more space to store a large amount of pixels for the purpose of describing the same graphic object.The role of vectorization is to convert graphic objects in a raster image to vector form.It can be used as a preprocessing for OCR [5][11] .
In general, a coding scheme for line structures must satisfy objectives [4] : 1-It must faithfully preserve the information of interest.2-It must permit compact storage and be convenient for display ; and 3-It must facilitate any required processing.

Recognition Procedure: -
The procedure adopted in this research consists of 5 modules: Digitization, preprocessing, thinning, Features extraction, and feature storing.

1-Digitization
The first phase in the line recognition process is digitization.Documents to be processed are first scanned and digitized.A 300-dpi scanner is used for this.The image input to the picture processing system is a photonegative of a line drawing.The continuous image (photonegative) is converted by an image sampling and quantization process to equally spaced samples arranged in the form of an array where each element of the array is a number between 1 and 256, representing the intensity value at the corresponding picture point.

2-Preprocessing
First, the noise in the input image is removed by binarization.Next, the obtained binary image F(X,Y) (figure 1(a)) is normalized so that the size of rectangle circumscribing the pattern is 100*100 pixels.Consequently, the normalized image F (X,Y) is obtained (figure.1(b)).This operation is described as follows [10]

3-Thinning
Thinning is irreversible operations that seek to reduce a connected region of pixels of a given property set to a smaller size.It reduces a region to minimal cross-sectional [13] .
The thinning operation removes foreground pixels such that an object without holes erodes to a minimally connected stroke that is equidistant from its nearest outer boundaries.If the object has holes, the object erodes to minimally connected ring located half-way between each hole and its nearest outer boundary [3] .
The thinning algorithm adopted in this paper can be found in [1] . Figure (2) illustrates an original scanned image and the resulting skeleton after applying thinning algorithm.The feature extraction steps involve the line description.Straight and curved line segments form the basic structure of many pictures.In such images a mathematical relationship of detected points on an object boundary provides a symbolic description of the image.The approach to the establishments of mathematical relationship is line-to-point transformation [13] .The approach to line description used in this paper is as follows:

4-1 Line-to-Point Transformations
In this paper the Hough transform is used to detect a straight line in a binary image.It is a technique which can be used to isolate features of particular shape within an image.Because it requires that desired features be specified in some parametric form, the classical Hough transform is most commonly used for the detection of regular curves such as lines, circles, ellipses, etc. [2][14] .
We can analytically describe a line segment in a number of forms.However, a convenient equation for describing a set of lines uses parametric or normal notion: P = X cos (θ) + Y sin (θ) - ------------------------(2) Where P is the normal distance of the line form the origin and θ represents the slop angle of the line with respect to the X-axis, it is clearly illustrated in figure (3 ) .
2-For any element in the image (x, y) satisfying (x, y ) = "1", calculate the distance (D) between this point and line equation follows: (where T:is a small number = 5 as a threshold value, TOL:is a small number represents the distance between end point of line and a new point that is accepted as a part of line. ) -Continue until (D>T) or (DIS>TOL).
-Save last point location as end point for line (X2,Y2).Note : any pixel or position in the image (x, y) has been checking it will be deleted.

3-repeat steps 1,2 until last element in H(P, θ).
After feature extraction stage we obtained end points table for all line in the binary image which is called (LIST table).It is clearly illustrated in table (1) .

5-Storing Features
In this phase we store the lines in a file, the storing algorithm adopted in this research can be summarized as follows: This information represented data file, the structure used for this data is : Data structure : { int x1,y1,x2,y2 ; } Table (3) below illustrates the information after this stage.

Experimental Result
A set of images, include different form of lines with all expected slops, are used to test the recognition algorithm.
Image of Figure ( 5) contains different samples of intersected lines.This image is processed using this research algorithm and the result is illustrated in table (4) and table (5).
Table (3,5) show a very useful information about the lines really these information are the line description by the two end points [x1,y1,x2,y2], so the lines parameters can be seen clearly from the information stable .

Conclusions
This paper, which uses Hough transform as a main tool, lines with different shapes [horizontal, vertical and slant] and different length are detected, and the lines parameters which are described by the two end points can give the line length and its slop which is used later to reconstruct the lines again.
Hough transform work better on images have little noise, with this paper by using a preprocess on the images and thinning algorithms, the noisy images can be treated for line detection.
Also the storage technique (the last stage of the recognition algorithm) provide the users with all image information.The size of the stored file is so small compared with the image size.
: F′ (X,Y)=F( (Width*X) / 100 + DX , (Height * Y ) /100 + DY ) ,-----(1)Where, Width and Height are that of the pattern, respectively.Then DX and DY are the horizontal and vertical distances between the left top corners of the image and the rectangle, respectively.

Figure 2 :
Figure 2: (a) The original image.(b) The thinning image

Figure 3 : parametric space 4 - 2
Figure 3: parametric space Rot -If (D<T) then Calculate distance (DIS) between end point for line and a new point, If (DIS< TOL ) then A new point belong to this line and same this point as begin point(X1,Y1),

1 - 6 -
Given LIST (is a double linked list that contains information (x1,y1,x2.y2) for each line in image ).2-create a new file.3-Define the parameters A,B,C.4-Initialize each parameter to zero.5-For each line in LIST: -Calculate the slop by dy/dx , (dy = y2-y1, dx=x2 -x1 ).-If a line is horizontal then A =A+1, Else if a line is vertical then B =B+1 , Else C=C+1 Store first number of columns ( no. of Pixels in row ) for image, then Total line (A+B+C) , next number of horizontal lines (A), vertical lines (B), slant line (C) .This information represented header file , see table (2).7-Store (x1,y1,x2,y2) for each line in a file with the following order: a-Horizontal lines.b-Vertical lines.c-Slant lines.

Figure 5 :
Figure 5: (a) the original image .(b) the thinning image