Rectangle Positioning Algorithm Simulation Based on Edge Detection and Hough Transform

This paper proposes a new algorithm to extract the rectangle in images. It’s goal is to meet the requirement of the truck’s compartment positioning and assure that some work are done inside the truck’s compartment. Firstly, the Canny operator is used to calculate the edge of the image, because it is sensitive to the image texture features. Secondly, the Canny edge is transformed with the Hough transform algorithm. The peak points in the Hough parameter space indicate the straight lines which may be the elements of the compartment. The sides of the rectangle are the straight lines which meet the conditions of the actual size of the compartment. Finally, the four vertices of the rectangle are solved in accordance with the geometric constraint of rectangle. The simulation experiment shows that the algorithm is effective.


INTRODUCTION
Edge detection technology is increasingly been applied in various fields along with the development of computer vision and digital image processing, and its role is becoming more and more important.Coal is the important raw material in coal-fired power plants or steel mills.It plays a decisive role to in the quality of products.For small or medium-sized enterprises, the coal is carried into the factory mainly by trucks.While collecting the coal samples for further testing, the sampling process has been changed from manual sampling to mechanical sampling.But these sampling devices are unable to avoid the interference of man-made factors, because the sampling locations are decided by the operation personnel [1].On this situation, an intelligent sampling control system is necessary to cut down the influence of the human factor, to improve the reliability of sampling system, and thus realize the goal of automatic sampling.
For the moment, the technologies suitable for compartment positioning mainly include infrared signals localization and ultrasonic positioning that is based on sensor, as well as digital image processing technology which extracts image edge information.The positioning technology based on the sensor is vulnerable to environmental factors (such as the coal dust or the moving objects), but the positioning technology based on image edge detection technology can overcome these problems.
References [2][3][4][5][6] have discussed image identification issues for straight line and rectangle.Although the compartments of the trucks are rectangle, but the location of the truck (in the detection area of the driveway) is not fixed *Address correspondence to this author at the North China Electric Power University, Beijing, 102206, China; Tel: 0086-10-61772177; Fax: 0086-10-61772177; E-mail: pingxielaoshi@163.com while waiting for sampling, and the size of the compartments vary from a truck to another.Consequently, the key for intelligent automatic sampling is how to obtain the locations of the compartments.Hence, those methods must be improved to apply to the truck's positioning.
For the truck's compartment positioning, [7] proposed a locating method based on background subtraction and image projection method; [8] presented an edge detection algorithm on fuzzy sets according to the requests of determining orientation of coal compartment.It is applicable to the edge detection of bigger objective area (compartment) of multilevels image.In this paper, according to the image detection characteristics of the truck's compartment filled with coal, a camera is set up to get the location of the truck image in real time, then the Canny operator for the image edge detection is used to calculate the edge of the truck image.The Canny edge image contains the front part of the truck.In order to assure that the sampling locations are inside the compartment, the rectangle area that indicates the truck compartment should be identified by the Hough transform.

Detection Object Analysis
As shown in Fig. (1), in order to get the location of the truck in real time, a camera is set up on the top middle of the sampling area.The truck image information is acquired from the dynamic video after the truck has stopped in the sampling area, then the rectangle area which indicates the truck's compartment could be identified by the digital image edge detection technology and Hough transform.
Roberts operator, Sobel operator, Prewitt operator, Log operator, Laplacian operator and Canny operator are familiar edge detection operators.Many scholars have made the analysis and comparison of among their respective advantages and disadvantages.The edge of the compartment has obvious characteristic due to the black coal, so the outline of the truck can be easily obtained with an edge detection algorithm.The Canny operator is used in this paper because it is sensitive to the image texture features.The length and width data of the truck can be retrieved directly from the truck's RFID tags identification system, and the sampling area is a one-way road.Consequently, the direction of the truck is fixed.We just need to identify the tail location of the truck, and then the whole poison of the truck compartment can be calculated with the rectangle geometry constraints.

Canny Edge Detection
Canny edge detection operator based on optimization algorithm was put forward by John F. Canny in 1986.The edge of an image is some areas where brightness changes significantly.The gray level in these areas is generally regarded as a step.That is in the gray scale of a small area, occurs dramatic changes.The Canny edge detection has three criteria [9].

SNR Criterion
The goal for SNR (Signal Noise Ratio) is to check out all pixels that are part of the edge and remove all pixels that do not belong to the edge.SNR can be expressed as (1): In (1), f(x) is the filter impulse response in the boundary [-∞,∞], is on behalf of the edge, and is the root mean square for Gauss noise.

L Criterion
L (Localization accuracy) criterion shows that the edge pixels checked out must coincide with the actual edge as closely as possible.L can be expressed as (2): In ( 2), is the first-order derivative of G(x), and f (x) is the first-order derivative of f (x).

Single Edge Response Criteria
A single edge has only one response, and the false edge response should be restrained as much as possible.It can be expressed as D (the average Distance of the false edge) (3): For the three criteria, SNR reflects the detection rate of an edge detection operator based on the real edge.The higher the SNR, the more likely the detection result contains the real edges and cuts off the false edges.L reflects the mathematical expectation between the detection result and the inverse of the actual edge.The Lower the L, the higher the localization accuracy.D represents the average distance of the false edges by the convolution between the random noise and the detection function.The higher the D, the lower possibility the false edges are.
In this paper, Canny operator assumes that average distance D is a constant, and considers the optimal product of SNR and L which is calculated in limited times as Canny detection function, and then it is expressed as the firstorder derivative of Gauss function.If the Gauss function was G(x) = e !" 2 x 2 /2 , the Canny operator is as follows: Canny operator has a higher fidelity on the edge of original image, and also has better edge location accuracy.Hence the Canny operator is adopted.

Rectangle Detection Principle of Hough Transform
Hough transform is a kind of regional boundary shape description method.It is usually used to detect the straight line, circle or ellipse.This method has higher reliability, and can output the ideal result even under the condition of noise, deformation or some loss of image.
The basic idea to detect straight lines by Hough transform is the duality principle of points and lines.In other words, the points and sine curves are dual.On the one hand, any point in a straight line can correspond to those sine curves in the Hough transform space which intersect at the same point; on the other hand, the sine curves in the Hough transform space which intersect at the same point also can correspond to a straight line.So the Hough transform changes the problems of detecting straight lines in the image space into detecting points in the Hough transform space.A straight line in the image space usually is expressed as an equation that has a constant slope of k, such as y = kx + b.In this way, the size of the accumulator array could be very large when the slope of k is infinity, and then the storage space required becomes larger.In order to solve this problem, the straight lines are expressed as polar equation: != x cos" + ysin"     4), the rectangle is changed after Hough transform.There are 4 peak points: They are respectively corresponding to the four sides of the rectangle: The distance between the same pair of peak points is equal to the length of the rectangle's side, which means

Algorithm Idea
As long as the tail part of the compartment is identified, in other words, a pair of vertices and three sides of the rectangle are found out, the rectangle area of the whole compartment excluding the front part can be calculated.The reason is that the length and width of the compartment has been given and the truck enters the sampling area only in one way.Accordingly, we just need to process half of the truck image.The algorithm is as follows: Step 1: Obtain edge information of the truck after dealing with the truck image with Canny edge detection operator.
Step 2: Cut out half of the Canny edge image to perform rectangle feature extraction with the windowed Hough transform technique.
Step 3: Extract all straight lines in the window which would belong to the tail edge of the truck in Hough transform space.
Step 4: Eliminate those straight lines which do not meet specific conditions.That means the straight lines which are not part of the truck would be removed.
Step 5: Find out a pair of vertices (that is, two intersection points of three straight lines) which indicates the tail of the truck's rectangle region.
Step 6: Use the rectangle geometric constraints to calculate the other two vertices.
Since the four vertices of the rectangle have been identified, the compartment area also can be confirmed.In the following subsections, some of these steps will be described in detail.

Straight Line Extraction Algorithm
In order to find out the straight lines, the Canny edge image should be mapped into the Hough transform space by (5).The Hough transform is used for the whole image, so the range of !depends on the size of the image and is related to the diagonal length of the image, the range of which should be 0~180 °.The array C(ρ,θ) is used to cumulate the number of those pixels in the Canny image that meet the straight line equation.
The specific process for straight lines extraction is as follows: Step 1: For each edge pixels (x,y) in Canny image, each θ can be used to calculate a corresponding value ρ.The θ may take over any possible value in the range of 0~180°, each ρ and θ constitute the only one straight line in the Canny image.The values of array C(ρ,θ) are accumulated according to the value of ρ and θ, so we can get the numbers of pixels meeting the same parameters of ρ and θ.
Step 2: Find out the peak points in the array C(ρ,θ), because each peak point is corresponding to a straight line.Method for finding the peak point is to extract all points which meet the threshold condition C(ρ,θ) ≥ T c , and threshold T c is associated with the image size.

Vertex Extraction Algorithm
We have known that !!(! !, ! ! ) , ! !(! !, ! ! ) , , ! !(! !, ! ! ) are m peak points extracted from array C(ρ,θ), the goal of this step is to find out a pair of vertices (that is, two intersection points of three straight lines) which indicates the tail of the truck's rectangle region.
Firstly, we must find out a pair of parallel sides belonging it to the compartment by scanning each peak point.It means two peak points which meet the following condition (6) make a pair.
! i " !j < T ! and !i " !j " W < T w (6) In ( 6), T ! is the angle threshold, W is the actual width of the compartment, T w is the width deviation threshold.
Among those peak points which are not paired successfully, the third side of the compartment C k (ρ k ,θ k ) is the one which satisfies the following conditions (7).
In ( 7), T α is the angle threshold.
Now the three peak points we found out just represent the three sides of the tail compartment.
Finally, the rest of the job is to extract the two vertices of the tail compartment.
Assuming the three peak points we find out are !!(! !, ! ! ), !!(! !, ! ! ) and !!(! !, ! ! ), as shown in Fig. (4).As an example, we deal with C 1 and C 4 to illustrate how to get a vertex.The intersection point of the two straight lines is exactly the vertex.
The intersection point of the two straight lines can be calculated by ( 8) and ( 9), and the intersection point is corresponds to the vertex P 2 (x 2 ,y 2 ).
Similarly we can calculate the intersection point of C 2 and C 4 which corresponds to the vertex P 1 (x 1 ,y 1 ).Thus we obtained a pair of vertices and three sides of the compartment.

Solving Rectangle Vertices
The problem of solving rectangle vertices can be transformed into solving the location of the vertices P 3 (x 3 ,y 3 ) and P 4 (x 4 ,y 4 ) in Fig. (3), because we obtained the location of vertices P 1 (x 1 ,y 1 ), P 2 (x 2 ,y 2 ), three edges, and the length of a and b as shown in Fig. (3).

Extracting the Straight Lines
Firstly, the Canny edge image should be mapped into the Hough transform space by (5).The range of ! has been defined as 2 times of the diagonal length of image, the range of θ was supposed to be 0~180°, but we can narrow it down

( 5 )
According to (5), a straight line in the original image space is mapped to a point in the Hough transform space, as shown in Fig.(2).

Fig. ( 2
Fig. (2).A line in the image space is mapped to a point in the Hough transform space.Every point of the straight line in the image space is mapped to the same point in the Hough transform space because they have the same slope and intercept.As a result, the straight line in the image space becomes a rallying point in the Hough transform space after mapping.The length of the straight line segment determines the total value of the rallying point.In this way, the problem of detecting straight lines is replaced with finding peak points in Hough transform space.Consider the rectangle in Fig.(3).0 is the coordinate origin.! !(! !, ! !)! !!!, ! !, ! !!!, ! ! and !!(! !, ! !)are the four vertices of the rectangle.The length of sides are a and b.
are the four vertices of the rectangle.The length of sides are a and b.

Firstly
, the Canny operator is used to detect the edge of the original image.The original image is shown in Fig. (5), whereas the Canny edge image is shown in Fig. (6).The front part of the truck is included in the Canny edge.Secondly, cut out half of the Canny edge image to perform rectangle feature extraction with the windowed Hough transform algorithm.Fig. (7) is the image cut out to detect the tail part of the compartment.