1. Introduction
The line feature is an important part of an image’s geometric information and plays a crucial role in photogrammetry and remote sensing [
1], three-dimensional (3D) urban modeling [
2,
3], computer vision and robot navigation positioning [
4,
5], and so on. Simultaneously, the importance of line elements is emphasized in cartography and the even more user-oriented discipline, spatial cognition [
6,
7]. The line feature has the following advantages as a more advanced feature than the point feature: (1) It has rich structural information for expressing edge information of 3D objects, such as structured buildings; (2) the extraction of the line feature is less affected by image noise, occlusion, geometric distortion, and grayscale distortion; (3) it has higher matching accuracy; (4) it is not necessary to completely determine the position of its two endpoints; and (5) in case of missing texture or uniformity, the line feature is easier to extract than the point feature. Particularly, a line feature is the kind of rich structural information which can intuitively express edge contours of the structured scene. This has achieved good practical application results in scientific and engineering decision-making applications. Crowley [
8] and Zhang et al. [
9] used line features to realize map creation and navigation positioning. Garulli et al. [
10] utilized lines to express environmental features, enabling simultaneous localization and mapping (SLAM) of mobile robots for sensing unknown environments. Trinh et al. [
11] extracted line segments from the surface of structured buildings to achieve a shape analysis of the target. Yu et al. [
12] detected the location of cracks in pipes by judging whether the line feature was continuous. Elqursh et al. [
13] proposed a bundle-adjustment method combined with line segments to achieve relative orientation of stereo-images and the estimated position and pose information of the camera. Gerke [
14] and Schmude [
15] used line segments as the constraint information for a camera’s relative orientation. Santos et al. [
16] combined the line feature extraction algorithm to implement unmanned aerial vehicle (UAV) image-based power line inspections. Partovi [
17] extracted straight lines from a building feature and used them for the regularized processing of buildings. Wang et al. [
18] used reconstructed 3D line segments as auxiliary information to improve the quality of the real orthophoto that reduced the sawtooth pull problem at the edge of a building. Therefore, it is valuable to extract good line features in many fields.
Line segment extraction algorithms can be classified into three categories: (1) Algorithms that transform domain-based methods [
19]; (2) algorithms based on gradient phase feature [
20]; and (3) segmentation edge approaches [
21]. The first type of algorithm is less influenced by image noise, but the calculation cost is higher, with lower extraction accuracy. The second type of algorithm has a low memory-occupancy rate with better extraction efficiency in complex scenes, but it is sensitive to grayscale distortion. When the grouping error is large, line segments are prone to the phenomenon of obvious segmentation fracture. The third type of method can detect local features of the image and it is easy to obtain the geometric attribute information of the line segment. Its extraction speed is fast, yet these algorithms depend on the quality of built-in edge tracking algorithms.
The theoretical basis of line segment extraction is relatively mature. The Hough transform technique [
22] extracts line segments accurately in a single texture background scene, but it is prone to large error-extracted line segments in complex texture scenes. Xu et al. [
23] proposed a multi-scale Hough transform with a pre-stored weight matrix to detect straight lines with higher precision and less constraints by studying the limitation of accuracy, efficiency, and image size for detecting line segments of Hough transform. Canny [
24] proposed the line segment extraction algorithm with edge detection based on the Canny operator. However, the algorithm requires a large number of decision-making parameters, which has serious false positive (false detection) and false negative (missing detection) problems. A robust line segment extraction algorithm progressive probabilistic Hough transform (PPHT) proposed by Matas et al. [
25] combines the random edge point selection algorithm to improve the feature extraction speed. However, its error-detection mechanism easily raises false negatives and misses the necessary short line segments. More recently, a local line segment extraction algorithm, line segment detector (LSD), proposed by Gioi et al. [
26], was found to be capable of extracting sub-pixel-level precision line segments in linear time, but the effect of line segments intersection, partial occlusion, image blur, image noise, and grayscale distortion caused severe segmentation fracture problems. Akinlar et al. [
27,
28] proposed a new edge detection operator, Edge Drawing, and a faster line segment extraction algorithm, Edge Drawing Lines (EDLines), but the segmentation fracture effect of the extracted line segments was not improved. The false negative of this method is inevitable and it is easy to miss critical line segments.
The existing research mainly focuses on the accuracy and efficiency of the line feature extraction without considering the length of extracted line segments. Short line segments are less accurate than long line segments, which causes more processing errors (error matching and error reconstruction). Currently, there are few methods to solve this line segmentation fracture problem. To alleviate this common problem, this paper proposes a multi-constrained line segment extraction optimization algorithm based on multi-scale image space, namely MSLines, including MSLSD and MSEDLines (MS is an abbreviation of Multi-Scale), which reduces the influence of grayscale distortion on feature extraction using the idea of fuzzy processing.
Figure 1 shows the overall methodology presented in this paper, which is divided into three main modules. The first module consists of constructing the line segment extraction model. A multi-scale image pyramid was constructed based on the Gaussian down-sampling and line segments of each image layer were extracted by the traditional line segment detection algorithm. All line segments were projected onto the original image and stored in line vector spaces. The second module was the optimization of the purification strategy. A set of line segment optimization and purification methods were designed with geometric constraints; line segments were merged or deleted according to the distance and angle relationships between line segments. The third module was second optimization. The virtual straight line was constructed and the secondary merge optimization of the line segment was realized based on the grayscale constraint relationship of the normalized cross correlation (NCC) measurement. Compared with several mainstream line segment extraction algorithms, i.e., LSD and EDLines, the proposed method could alleviate the segmental fracture effect of line segments and eliminate line segments’ redundant problem.
The remainder of this study is organized as follows.
Section 2 describes the principle of multi-scale image space line segment extraction method. This section also introduces a new line segment optimization and purification method based on geometric constraints. Also, a second optimization method of grayscale constraint is presented. In
Section 3, three sets of real data, i.e., indoor, outdoor, and aerial images are tested to analyze superiority of our proposed line segment extraction method compared with the mainstream method.
Section 4 discusses the selection of parameters in the model construction for various resolution images and analyses the accuracy of the proposed method.
Section 5 presents conclusions and possible further studies.
2. Methods
2.1. Model Construction
2.1.1. Line Segment Detection Method
At present, Von Gioi’s LSD line segment extraction algorithm is one of the most widely used methods. The principle of several mainstream line segment extraction algorithms is similar to LSD.
Figure 2 shows the workflow of the LSD algorithm.
In the line detection process, the input image was first down-sampled to 80% of the original image by the Gaussian down-sampling method to weaken the sawtooth effect of image, as well as to maintain a balance between the sawtooth effect and image blur. Next, a 2 × 2 gradient template was given to calculate the gradient direction (level-line angle (LLA)) and amplitude (intensity) of all pixels after image down-sampling. Depending on the pixel gradient amplitude, 1024 containers were opened and all image pixels were pseudo sorted from high to low order. Simultaneously, a state list was established and the initial state of all pixels was set to UNUSED. The state of pixel labels whose gradient amplitude was smaller than the threshold “ρ” was changed to USED, to represent an area where the image is flat or the gradient changes slowly; this means it did not participate in the line support region (LSR) and rectangle construction. Then, an UNUSED pixel from the sorted list was selected as a seed point. The region growing algorithm was used to generate LSR with the seed point. The seed point and LLA were continuously updated until the current point could not meet the threshold requirement. The final regional direction angle θreg was achieved. The rectangle and the number of false alarms (NFA) was calculated according to θreg and finally, line segments were determined after traversing all UNUSED seed points.
A point can only belong to certain line segment with a traditional LSD algorithm where extracted line segments cannot intersect with each other. If two line segments intersect, they break and split into four short line segments. Additionally, the algorithm is susceptible to pixel grayscale gradient mutation during the regional growth period, so that the difference between the current point LLA and the regional direction angle exceeds the growth threshold, resulting in segmentation fracture of the line segments. The EDLines algorithm uses the Edge Drawing operator for feature extraction. The speed of this method is fast, but the line segmentation fracture problem is not improved. Therefore, traditional line segment extraction algorithms should be further optimized to solve the segmentation fracture effect.
2.1.2. Multi-Scale Image Space Line Segment Extraction Method
In order to overcome the segmentation fracture problem of line segment extraction, the proposed method combines the idea of fuzzy processing by down-sampling the original image to produce a pyramid-like model of multi-scale image space.
To perform this method, the specific procedure was as follows: (1) According to the actual image resolution and processing requirements, the standard deviation factor (scale space factor) of Gaussian filter kernel function
σ was set and the maximum down-sampling number
tmax was set; (2) Gaussian kernel convolution on image
I to achieve Gaussian blur of the image was performed; (3) image-based down-sample on image-scale space factor
σ (
σ is generally set to 0.5) was carried out; (4) to detect line segment, the traditional method was used for this layered image and the line segments were stored in the corresponding line vector spaces; (5) steps (2 –4) were repeated until the maximum number of down-sampling was reached. Specifically, the Gaussian-blurred image
is first generated with Equation (1).
where
is the Gaussian kernel function,
is the image
, and
is the convolution operation on the image pixel
.
Based on scale space factor σ, the original image was down-sampled to obtain a low-resolution image J. The above operation was repeated to continue down-sampling of image J until the maximum down-sampling number tmax was reached. Finally, an N-layer image model was created (N = tmax + 1), forming a pyramid-like multi-scale image space model.
To detect line segments, traditional line segment detection method was used for each image layer in scale space and line segment vector spaces corresponding to the number of images were opened. Line segments extracted in each scale image were stored in a line segment vector
, where
k represents the
k-scale image of line segment vector space and the maximum value of
k is
N. Moreover, line segment endpoints’ coordinates and length information were stored in line segment class
, where
k represents
kth line segment vector space and
i represents
ith line in the image. Line segment extraction and storage process is shown in
Figure 3.
Figure 3 shows that the traditional line segment detector extracts line segments for each scale image and stores segments in vector space. If detector extracts
m1 and
m2 line segments in the first and second layers of the image, respectively, then the line segment method extracts
mN line segments in the Nth layer of the image. The expression of multi-scale image space line feature vector can be represented with Equation (2).
2.1.3. Line Segment Projection
Line segments extracted from different scale images were all projected to the original image and stored in a new opened memory vector space. Particularly, line segments extracted from the original image were directly stored in a new vector. For a line segment extracted after down-sampling of image, the
needed to be projected with Equation (3) in case of known scaling factor σ and the number of the image down-sampled times
t (
). Finally, a vector set
SumLineVec of all line segments extracted by traditional method in the multi-scale image space was achieved with Equation (4). The vector dimension of
SumLineVec is
m1 +
m2 + ⋯ +
mN.
where,
2.2. Optimization and Purification Based on Geometric Constraints
After line segments extracted by the multi-scale image space were projected to the original image, severe redundancy. Overlapping. and clutter problems of line segments occur. Many line segments are meaningless, so the entire set of line segments needs to be optimized and purified. As a result, the down-sampled image with low resolution can only extract a few segments, which brings extraction error. In this subsection, a line segment optimization and purification strategy is proposed, which optimizes line segment extraction results through line segment geometric constraint relationships. The optimized line segments have longer length and higher integrity, while alleviating the redundancy problem.
Before optimization and purification, it is necessary to describe and determine constraint relationships between line segments. As shown in
Figure 4, the geometric constraint relationships between line segments are defined as follows:
Based on the geometric constraint relationships in
Figure 4, we define horizontal, vertical, and angle thresholds to determine whether line segments need to be optimized and purified. We define
and
, respectively, as reference and determined line segments that needed to be judged. The distance between midpoints of two segments is
and the average distance between the endpoints of two segments is
. The angle between two lines is
θ.
2.2.1. Distance Geometric Constraint
The distance geometric constraint relationships can be divided into horizontal and vertical distance relationships. Considering the horizontal distance relationship (
Figure 4a), the distance
D1 between the midpoints of two line segments is used to judge whether they are related and whether
needs to be retained or deleted. If
,
and
are independent.
is retained and stored as one of the reference line segments in the next judgment process. If
,
is related to
and
continues to be judged by the vertical distance constraint relationship. Considering vertical distance constraint (
Figure 4b), if
(where
is the vertical threshold),
is strongly correlated with
and we then merge
and
. If
,
is a redundant or invalid segment and needs to be deleted. If
,
and
are independent and
is retained and stored as one of the reference line segments in the next judgment. Here we set
ξd = 1(
pixel), because the resolution of the human eye is 1 pixel, and the error of more than 1 pixel is discernible.
In this paper, as a part, we also propose an optimization method for merging short line segments based on endpoint projection transformation. The reason for selecting optimization method is that the least squares fitting method has larger extraction errors for extracted line segments from low-resolution images than from original images by using the multi-scale image space model. The least squares fitting is an error-averaging method to minimize the sum of squared errors. If the least squares fitting strategy was used here to merge line segments, it would bring more merging errors. The line segment merging method based on endpoint projection transformation is shown in
Figure 5.
The origin
O of an image coordinate system is located in the upper left corner of image.
was a reference line segment extracted from the original image and the two endpoints were
and
.
was an error-containing line segment in the multi-scale image space and its two endpoints were
and
, whereas
were homogeneous coordinates corresponding to these endpoints. We projected error-containing line segments onto the reference line segment, as well as obtained projected coordinate values
and
at both endpoints of the error-containing line segment. Equation (6) gives the endpoint projection formula:
where
A,
B, and
C are the reference line equation
parameters, which can be taken by known two endpoints image coordinates. Thereby, the projected coordinate value
of endpoints for the error-containing line segment can be achieved. Due to difference between positive and negative slopes of the reference line segment, the method of line segment merging has two possibilities regarding endpoint transformations. We can finally get endpoints
and
of the merged line segment using Equation (7).
2.2.2. Angle Geometric Constraint
When
and
intersect each other at the extension line (
Figure 4c), there is no overlap between
and
due to that line segments are not infinitely long lines. Moreover,
and
don’t need to be judged by the angle geometric constraint relationship, but only the vertical distance geometric relationship is used for judgment. When
intersects with
at the non-extended line (
Figure 4d), the angle constraint relationship is also judged for the deletion of the pseudo-line after completing the distance constraint judgment. If
(where
is the angle threshold,
ξθ = 5°), we think that
is a false line and delete it. Otherwise, we retain
. The expression of angle
is given in Equation (8).
2.3. Optimization Based on Grayscale Constraint
After completing the geometric constraint relationship judgment, we can get optimized line segments. Grayscale constraint was performed on the first optimized line segment to realize the second optimization (
Figure 6).
Furthermore, it must be mentioned that direction information of all line segments is traverse after geometric optimization. When any two line segments, and , have the same direction (the angle between the two lines θ < 1°) and the distance between them is less than 20 pixels, which is suitable for the current typical megapixel/medium-resolution image in the experiment section of paper, these two line segments are temporarily merged into one virtual line segment.
In addition to this, grayscale points on the central positions of AB (midpoint of
), BC, and CD segments (midpoint of
) on virtual line segments are used as center grayscale to open a 3 × 3 matching window with NCC similarity judgment. NCC is often used to compare the similarity of two images and realize the matching features. Here, we propose an extended NCC that compares the similarities of the three windows (small patches) opened on one image. If
(where
is grayscale threshold among three matching windows,
ψ = 0.8), the line segment has high grayscale-level similarity that means a virtual line segment is an optimized line segment. In this case, we combine
and
to get a real line segment. If
, the virtual line segment is not a real merging line segment. In this case,
and
are retained and the virtual line segment is released. The specific expression of
NCC is given in Equation (9).
where
Gp and
Gq represent grayscale windows at positiond
p and
q on virtual line segment, respectively, and
N represents the size of the grayscale window, which is 3 here.
2.4. Overall Procedure of Optimization
When the kth line segment in the SumLineVec line feature set was processed (k < dim), the previous k-1 line segments were used as reference lines for judgment. In this article, vertical distance constraint, angle constraint, and grayscale constraint thresholds were set respectively by the empirical method decision above.
According to the constraint relationships between line segments as described above, the specific procedure of line segment optimization and purification was as follows:
(1) The line feature vector space and were opened for storing line segments that were optimized by geometric and grayscale constraints. The initial state was and .
(2) Line segments extracted from the original image in SumLineVec were taken as reference lines and directly taken into the optimized set .
(3) Line segments extracted from other scale image space in SumLineVec were judged as determined lines with reference lines in the optimized set based on the geometric distance and angle constraint relationships. If the determined line satisfied the optimization and purification situation, would be updated. Otherwise, the determined line would be deleted.
(4) When all lines in SumLineVec were processed, an optimized set of line segments was obtained.
(5) For any two lines in , virtual line segments were constructed by directional characteristics, where the grayscale constraint relationship was used for judgement. If two lines satisfied the grayscale constraint optimization situation, was optimized. Otherwise, those lines that do not need to be optimized were directly stored to .
(6) The optimization set was purified by geometric constraint as a purification criterion. When geometric distance between line segments satisfies the culling condition, it was considered that there was a redundant line segment and we deleted the error. Also, when the angle distance between lines satisfied the culling condition, it was considered that there was a pseudo-line, which we deleted. Finally, we achieved the resulted line segment feature set .
3. Experiments and Analysis
Experiments were carried out using three data sets, each with three images, i.e., indoor, outdoor, and aerial images, to verify the effectiveness of the proposed method, as shown in
Figure 7. Our method was implemented in C++ and OpenCV. It was executed on a personal computer with Intel (R) Core (TM) i7-7500U 2.70 GHz CPU and 8.0 GB RAM.
As for the nine selected megapixel resolution data sets, we set the maximum down-sampling number
tmax = 2 and scale space factor σ = 0.5 based on the parameter setting of discussion section. Therefore, a three-layered multi-scale image space model was formed. For the three sets of nine images, each image consists of three images with different resolutions arranged from high to low. Moreover, the merits of the proposed line segment extraction method (referred to as MSLSD and MSEDLines for better description) are mainly discussed from the aspect of number of extracted line segments, extraction time, accuracy rate, total length, average length, and visualization effect of the line segment extraction. Here, the accuracy rate is the ratio of the number of correctly extracted line segments to the total number of line feature extraction [
29]. Generally, a longer average length of a line segment indicates a higher integrity of the extracted line, whereas a shorter extraction time means the method is better. However, this paper firstly uses the traditional method to extract line segments for multiple image scales and, as a result, extraction time is generally longer than the original method. The proposed method needs a short optimization time, but the overall extraction speed is not greatly affected. This study mainly solves the segmentation fracture problem of line segments and redundant or invalid feature problems. Therefore, it mainly focuses on the average and total lengths of line segments and the visualization effect of extracted line segments on the image. The proposed method is compared with LSD and EDLines methods from the above perspectives in this section.
For these test data, the line segment extraction results in
Figure 8,
Figure 9,
Figure 10,
Figure 11,
Figure 12,
Figure 13,
Figure 14,
Figure 15 and
Figure 16 are, respectively, shown for conventional LSD, EDLines, and our proposed method, MSLSD, MSEDLines. Moreover, a quantitative index of traditional and proposed methods for line segment extraction in three sets of nine images is presented in
Table 1.
It can be seen from the visualization results in
Figure 8,
Figure 9,
Figure 10,
Figure 11,
Figure 12,
Figure 13,
Figure 14,
Figure 15 and
Figure 16 that the proposed methods MSLSD and MSEDLines alleviated the segmentation fracture effect of line segments. Also, it can be seen from the local area marked by the yellow frames in the nine figures that the line extraction results of conventional LSD and EDLines method were affected by image factors such as grayscale distortion, causing a relatively severe fracture phenomenon. MSLSD and MSEDLines had the effect of optimization and could merge multiple broken short line segments into one complete long segment. Additionally, we can clearly see from
Figure 9,
Figure 10, and
Figure 13 that the proposed methods, MSLSD and MSEDLines, played a role in removing redundancy, eliminating the redundant lines while retaining the key geometric contour lines. From the comparison of
Figure 10a,b, it was found that the proposed method MSEDLines could remove some pseudo-lines extracted by algorithm mistakes.
Table 1 shows the quantitative results of line extraction with nine sets of experimental data of indoor, outdoor, and aerial images. Regardless of indoor or outdoor environments or aerial scenes, MSLSD and MSEDLines extract longer lines than the corresponding traditional methods, LSD and EDLines. The longer the average length of line segments, the higher the integrity of extracted line segments on the images. For Indoor 1, the line segment average length of MSEDLines and MSLSD was 85.3 pixels and 85.2 pixels respectively, which is much higher than that of EDLines (63.1 pixels) and LSD (51.3 pixels). Since our methods had the effect of removing line segment redundancy, the number of extracted line segments was less than that of conventional methods. MSEDLines and MSLSD extracted 215 and 238 line segments respectively from Indoor 1, while EDLines and LSD extracted 327 and 445 line segments, respectively. However, the reduction in the number of line segments does not result in the sharp drop in the total length of line segments. Because proposed methods in this paper preserve and optimize the key geometric contour information on the image while removing the redundant line segments, they ensure that the total length does not change much. The extraction time of the four methods of MSEDLines, MSLSD, EDLines, and LSD is not much different, which indicates that the optimization steps in this paper’s algorithm did not take much time. The quantification results of line segment extraction of the other eight sets of data have the same trend as Indoor 1.
Generally, line segments extracted by MSLSD and MSEDLines were more complete than that extracted by traditional methods and they also alleviated the line segmentation fracture problem. Many broken line segments were optimized to be combined into a complete line feature, which completely expressed the geometric profile information of the target. Meanwhile, the proposed method eliminated redundant clutter in the line feature detection process. Quantitative results showed that the average length of optimized line segments extracted by the proposed method was greatly improved compared with that extracted by traditional methods. Also, it was found that the accuracy of traditional methods and proposed methods was very high, except for images including the presence of trees and reflections, for example, such as Indoor 1 and Outdoor 2, and the accuracy of the proposed method was generally higher than that of the classical method. The line feature extraction time of all four methods in the paper was similar. The proposed method does not affect the extraction efficiency.
5. Conclusions
In this article, our proposed line detection method, MSLines, including MSLSD and MSEDLines, solves the line segmentation fracture problem. This novel method has the following advantages and characteristics: (1) Using advantages of down-sampling fuzzy processing, the influence of grayscale distortion on line segment extraction is reduced and the segmentation fracture effect of the traditional line feature extraction algorithm is alleviated. The continuity of line segments is improved. (2) Multi-scale image space line features are combined to construct an optimization and purification strategy with multiple constraints. The average length of extracted line segments is longer with higher integrity. Longer and accurate line segments provide a good research basis for line-based camera calibration, image matching, and 3D reconstruction. (3) Ineffective lines with partial redundancy and pseudo-lines are removed, as well as key line segments, such as geometric contours of the main object are optimized, which makes edge structures of the image be described more intuitively and clearly. (4) Only one parameter needs to be controlled manually, which makes the novel method more automated and parameter-less.
We experimentally verified the validity and superiority of our proposed method. Compared with LSD and EDLines, our proposed method has a longer average length and higher line segment integrity, which alleviates the line segmentation fracture effect to some extent. Particularly, our approach can extract more complete and comprehensive details for structured buildings. The presented improvements also can provide better structural features for SLAM navigation and other line-based applications. However, the proposed method does not completely solve the segmentation fracture effect of line segment extraction. Later, we can consider the fusion of LiDAR (Light Detection And Ranging) point cloud data based on our proposed method to further optimize and eliminate the segmentation fracture effect of line segment extraction. It can also be considered from the classical LSD algorithm perspective to improve problems where the internal gradient direction angle of the algorithm is abruptly affected by the grayscale mutation of individual pixels, which leads to the interruption of region growing and insufficient density of the same points.