Laser Point Cloud Segmentation in MATLAB

Currently, as a result of the massive continuous advancements in laser measurement technology, possibilities of map production are broadened, the loss of time and the waste of material sources are highly prevented, and the accuracy and precision of the obtained results are significantly improved. In the view of engineering concept. However, big data which are from laser point clouds have been especially used in the significant procedures of surveying studies. Programming methods are dependent in each studies. In the necessity of the applications, the coding procedure has more efficient, the data of work has increased, and time has been consumed. The coding methods have necessarily been optimized for working together especially in the big data studies. In this section, an automated survey (building facade surveying) is produced from scanning data by means of coding in MatLAB.


Introduction
Nowadays, laser scanning and modeling technology have been extensively used in city documentation and cultural heritage studies besides the technique of imaging for global representation in the internet survey and navigation applications. In the view of engineering concept. However, big data which are from laser point clouds have been especially used in the significant procedures of surveying studies. Programming methods are dependent in each studies. In the necessity of the applications, the coding procedure has more efficient, the data of work has increased, and time has been consumed. The coding process of big data process must be modeled in the hardware systems requires receiving consideration. This process has been related to hardware construction by electronic and computer engineering vision. This process has mathematical model and algorithm, which has been concerned surveying and computer programming engineering vision. In this chapter, Matlab coding models including functional and stochastic properties have been suggested and discussed for operational process within laser scanning data segmentation in surveying studies.

Data structure
Laser scanners scan the object in horizontal and vertical directions under a certain angle as a series of points and this allows the object to be displayed as a point cloud. In order to determine each of the laser points, measurement of scannercentric polar coordinates are made [1]. The measured points are slanted distance to point P, the angle between X-axis and horizontal plane α, and the angle of inclination of the horizontal plane measuring line φ. As illustrated in Figure 1, the initial point of terrestrial laser scanners are considered to be the positioned points. These measurements are based entirely on their local coordinate systems.
The resulting point cloud data is processed in formats related to the coordinate and the angle. The processing is carried out as follows: DXF for CAD models, ASCII for surface modeling, VRML format for visualization, and txt or pts. Software which varies with different laser scanner instrumentation can be used to obtain the point cloud data.
Laser scanners initially obtain the X,Y,Z Cartesian coordinates inside a second coordinate system which is located at the center of the station point and then they scan the surface of the object. In addition to the three-dimensional coordinates, the resulting data includes the density of the returning signal in terms of RGB (Red, Green, Blue) depending on the structure of the surface in question and the distance of measurement. Modeling of the scanned object and environment gets easier with recorded RGB density values. The dense data obtained by scanning is called a point cloud. Table 1 displays the formation of txt data linked to the point cloud data.
There is a software in target-oriented modules to obtain raw data, to convert data to a workable format, and to perform the texturing process (if necessary) etc.   Figure 2 shows the point cloud data that is represented with RGB density values. A Leica HDS -3000 terrestrial laser scanner is used to scan the point cloud data.

Programming flow procedure
During the documentation of the coordinate information of laser scanner point cloud data, there is no regular data order and classification [2]. For segmentation, points with known three-dimensional coordinates must be selected from all point cloud data. The algorithm is formalized with mathematical surface or point clustering techniques. Planar surfaces or points including depth parameters can be extracted by using various methods [3][4][5][6][7][8][9]. In addition, the surface points of the assigned surfaces are filtered. Once the building's planar surfaces are obtained, various methods can be used to extract property boundaries.
Programming flow procedure could be designed in this method in Matlab programming in Figure 3.
Deciding segmentation method is a dynamic process in Matlab programming flow. There are three different segmentation methods have been used in this step.
Geometric segmentation is based on geometric information of point cloud data. Radiometric segmentation is based on radiometric information of point cloud data. Hybrid segmentation is based on all information of point cloud data. The  mathematical model of these segmentation methods could be based on not only conventional methods but also expert systems (Fuzzy systems, SVM, etc.) as shown in

Point segmentation
Algorithm of this study which aims at filtering laser point cloud data of parallel surfaces in indoor areas by the help of filtering function is shown in Figure 5 [10].
Selecting one of the parallel indoor surfaces as the reference plane by an operator is the first step of filtering function algorithm.
Distinct surfaces define the point cloud data which is illustrated in Figure 6. Planar surfaces like walls generally define the indoor areas. Figure 6 displays point cloud data and various surface structures in a three dimensional coordinate system.
Mathematical function that represents plane surface is given in Eq. (1).
Eq. (1) shows that surface function consists of 4 parameters: A, B, C, D. The selected reference plane surface can be expressed mathematically by calculating these four parameters. An operator must read and manually enter the selected point coordinates of reference plane. The parameters of selected reference plane surface are determined by this way. A plane can be mathematically defined with reference to four parameters. So, we can only define the parameters of reference plane with four points. An operator selects more than four points in the same reference plane and determines the parameters of reference plane in adjustment process. Operator manually enters the threshold value secondly. Threshold value can be defined as the minimum difference of depth during the filter operation. All the operations are performed automatically by a Matlab-based software, other than the two stages of the algorithm.
Calculating the parameters of the selected reference plane is the second step of geometric segmentation algorithm. Once the operator manually chooses multiple (five or more) points as part of the first step of algorithm, the Matlab-based interface automatically determines four parameters which represent the reference plane in the adjustment computation. Thus, the adjusted reference plane is created in this step.  Point cloud data structure in 3D coordinate system.

5
Laser Point Cloud Segmentation in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95249 The third step of the algorithm is to calculate the distances of the parameters specified in the adjustment computation and all points in the laser point cloud to the reference plane. Figure 7 illustrates a point's distance to a plane. The distances of all points of the laser point cloud to the adjusted reference plane is calculated with Eq. (2). Eq. (2) shows the filtering function for the segmentation.
where; h: Distance of a laser point to the reference plane, A, B, C, D: Parameters of the adjusted reference plane, x 1 , y 1 , z 1 : Each laser point's three dimensional coordinates. These stated distances are added in vector form to segmentation matrix S as a column. For each point in segmentation filtering, point distances for the reference plane are calculated separately. The definition of Matlab operation environment is done in the format of segmentation matrix. This is basically called the "segmentation matrix". However, column algorithm are used to make the calculations and final column vector provides classification of points on the surfaces. The first column of segmentation matrix which is shown in Figure 8 is the X value, and the second column is the Y value of points. The third column represents the Z value in terrestrial laser scanning point cloud data. The fourth column shows the point distance into the reference plane. The fifth column displays the statistical  differences in terms of distances. The sixth column illustrates the exponential values of the differences, and the seventh column shows the surface of the related points.
Algorithm's fourth step is called the step of segmentation (classification). This step is utilized for statistical vectorial change which is created for the study. In this step, the detection of the number of surfaces in a vector is essential and this is determined by the amount of statistical deviation. The values of standard deviation determine the statistical analysis. Standard deviation's comparison value is called the threshold value. Thus, the minimum difference of depth in question determines the amount of the statistical deviation. So, if less minimum difference of depths are obtained for the points, it means that they are on the same surface. In statistical analysis (5th Column) the total number of various surfaces is detected, and all distances are calculated as an exponential function (6th Column) which are shifted into a positive value. That is, the raw data is obtained to carry out the classification step. The exponential part of the obtained value is taken because there are some conditions. These conditions include a negative plane point distance and a stable point on the other side of the plane. So, the surface with a smaller absolute value gets the points between two surfaces. With reference to this value, each point in the laser are assigned to a surface and to the matrix of the surface (7th Column).
In the final step of the segmentation algorithm, four boundary surface points are defined by laser scanning points assigned to the surface matrix. For this purpose, minimum and maximum x, y plane coordinate values of the points in the surface matrix are used. The edges in each segment of the original segmented laser point cloud data are determined with reference to minX-minY, minX-maxY, maxY-minX, maxX-maxY values. So, the boundary points of both surface and x and y plane coordinates are evaluated. However, the original values are not considered as the height value of points with plane coordinates defined in the algorithm. If we created a surface with a Z value acquired from the laser scanning data of the four points of the surface, not every surface would be parallel to each other. Thus, if we assign a height value to the four edge points, the segmentation result is assigned as the average height value of the Z (height) value for all points assigned to that surface. Therefore, the Z value of the four segmented points for each surface is the average Z value. This is the same value for each of the four points. This can be seen in Figure 9 [10].
At the end of the segmentation process, each surface with thousands of points is converted to planes that contain only four points and the average height of all points in a segment are taken. In order to test the filtering algorithm, laser point cloud of a class are scanned with Leica HDS 3000 in GYTE (presented in Figure 10). The scanning frequency in this study is 5 mm.
When obtaining the data which are specified in txt format from CYCLONE (Leica) software, affine conversion is carried out in order to give the data depth Z for point cloud data. So, operator will be able to determine the reference surface easier. An original data set, which is composed of four different surfaces and 21,932 points, is selected. There are significant depth differences which ranges from 1 cm to 20 cm in terms of the surfaces of doors, borders, walls and columns.
When the indoor space in Figure 11 is examined, it is seen that surface 1 is the reference plane which enables the testing of the filtering function from four plane  surfaces that are parallel to each other. Figure 7 shows that surface 1 is the backmost and surface 4 is the foremost of the surfaces. Operator chooses five points on the reference surface in Cyclone screen in order to calculate equation parameters of the plane. Threshold value (minimum difference of depth) of test data is 1 cm. By using the Matlab-based software, the classification of 21,932 three dimensional laser point clouds are made with four separate surfaces. This classification can be seen in Figure 12. Figure 13 shows the graph which presents the exponential values. There are 3906 points in the first segment which is based on 21,932 original laser scanning data with four distinct classes. In the second segment, there are 6588. In the third segment, there are 1951 points, and in the fourth 9487 points (5 points belong to surface1). Figure 14 presents the surfaces for each of the laser point cloud data. These are classified under four classes. Figure 14 shows that the distance threshold value between the second and third plane surfaces is nearly 1 cm. The filter performs the segmentation of these two distinct surfaces without any errors. While assigning all the points on the laser point cloud into a plane surface, it is important to record them to their respective surface matrix. The points within the matrix of each surface enable us to find the X, Y plane coordinate values of four edge points of the plane surface. In this plane surface, only one Z value is designated to all four points.   The crucial consideration here is to understand that surface selection does not cause any limitation and the operator decides this surface and defines it as the reference plane. Operator can select any surface as the reference plane in the suggested algorithm. The closest or the farthest plane surface or any surface within these surfaces can be determined as the reference surface by the operator. So, exponential values are used during the process of creating the segmentation matrix (matrix S). Distances between points and reference plane can be either negative or positive but since the exponential values are used, this does not change the results of segmentation or classification. Thus, negative or positive distances to the reference plane do not result in any segmentation error (this only shows the side that they belong to on any plane and does not interfere with the result). So, if the reference plane is the foremost surface (surface 4) and five points are selected on that surface, first segment includes 3906 points, second segment 6542 points, third segment 1997 points, and fourth segment 9487 points (note that the source of 5 points is surface 4) [10]. Matlab coding flowchart for this application is given in Figure 15.
Matlab Code of Flowchart in Figure 15 has been given in Appendix A.

Object segmentation
In this application, it is aimed to obtain the corner coordinate values of window gaps with geometric segmentation, which are not present in the mobile laser scanning data in order to use these values for automated visualization of the building facade survey. The sharp corners of the window are both natural points and target points for the vertical conversion. For this reason, laser point cloud data is used for the detection of these points by geometric segmentation. Then, the window corner points obtained by this segmentation are compared numerically with the values in the original point cloud data data in order to perform the analysis and obtain the results of the study.
The point cloud data used in the study are obtained from a measurement which was made in the Balgat district of Ankara with a vehicle in the inventory of TOPCON Company, equipped for mobile mapping, with a speed ranging from 10 km/h to 20 km/h. Ladybug-5 camera is used to produce photogrammetric data. The measuring equipment is shown in Figure 16 [11].
The point cloud data of study study area which are collected mobil laser scanner has shown in the Figure 17.
In this application, the data, which were obtained from cyclone program, were saved into the Tamyatay.txt file. Then, in order to distinguish the building points from the ground points on which we performed the survey process, the points which were 35 cm high from the lowest point of the ground have been determined on our raw data and the classification process was started.
Ground criteria was determined by the following Eq. (3) [12]: Here, the ground height value zk (ground thickness), which is asked to be entered into the code, can be changed. In order to distinguish the points more easily in the study, 35 cm was taken as the most appropriate value. Before starting the classification process, the scanned point clouds were plotted in Matlab as below the Figure 18.
For performing the classification process, first, a value of 1 was assigned to the class column of all points. Then, Z value was assigned to points whose Z value was less than the ground criteria. The ground points matrix Matrix_Ground was created by selecting the values which were assigned with 0 and its graph was plotted. The road's center axis Axis y , Axis x was determined using the points having maximum and minimum X and Y values from the ground points. When determining the center axis of the road, the axis was used on the points which were taken as Z 1¼ Z and had a depth of Z 1 and above.
These processes were calculated with the following Eqs. (4) and (5): Axis y ¼ Ground y min þ Ground y max À Ground y min 2 (4) Other than the values which were assigned to the class column with the value of 0 (ground point), the points assigned with class value 1 (building points) were saved as Matrix_Building_seg matrix and its graph was plotted in the Figure 19.  The building points were separated from the ground height of 35 cm, but a new classification was made on the basis of the above-mentioned road center axis to determine whether the building was on the left or right side of the road axis. For this purpose, a value of 1 was assigned to points smaller than Axis x (depth of the road axis) and a value of 2 was assigned to points greater than Axis x . The points assigned with the value of 1 are shown in the Matrix_Building_Left matrix, and the points assigned with the value of 2 are shown in the Matrix_Building_Right matrix.
It is assumed that the building lays on the side with the high number of points. So, the number of points of the Matrix_Building_Left and Matrix_Building_Right matrices were calculated and the values of the Matrix_Building_Left matrix were written as Matrix_Building_Segment matrix where the building points were completely separated and then, the building points were plotted. Also, if there were no points exceeding the height limit Z 1 ð Þ on the right side of the road center axis, although this data was not included in our data, this classification step would have to be made in order to completely make a distinction of the building points in the Figure 19 also.
After determining the building points, building points were transferred into a reference surface to draw the building facade survey. A mathematical filtering function was applied in this stage.
The segmentation works on the basis of surface-dependent height differences within the maximums and minimums of the surface function that forms the mathematical model. Surface equation is expressed as Eq. (6) [13]: where n is the number of points. An exponential filtering method is used as the filtering function. Filtering function is determined as Eq. (7): Where ΔX Building and Δ Depth were calculated with the following Eqs. (8) and (9): Δ Depth ¼ X Building À X max (9) a, b, c, d represent plane equation parameters, ΔX Building is the depth of building points to the reference surface, Δ Depth is depth differences of building points to the reference surface, e ΔBina is result values of the function, e ΔDepth is exponential values of differences of depth, and Eksen y represents the y value of road center axis.
For the segmentation process, the building reference surface points were determined at first. Then, the limits of the reference surface were resolved by using the minimum and maximum points of Z (height) and Y (length) of the building points and a rectangular surface was created. Only the maximum value of X (depth) was used. This is due to the fact that the bottom window (Window 1) of the building, which we were to transfer to the surface is located more on the backside than the other three windows. Also, when the minimum value of X is taken, there is a possibility that the points behind the bottom window with the smaller depth values might interfere with the bottom window and building points. The specified reference surface points are written into a Building_Reference_Surface_Points.txt file in the Table 2. The Surface graphic has shown in the Figure 20.
After the reference surface points are determined, the reference plane parameters of the building are calculated using these points. The reference surface is drawing in Matlab has shown in the Figure 21, then the PRight matrix is created and plotted. It is written into a Building_Reference_Plane_Par.txt file.

Figure 20.
Building reference surface points.
The following Eqs. (10)(11)(12)(13) are used in the process of adjustment: It represents unit matrix, BY is the matrix of detected maximum and minimum surface points, N is the normal equation coefficient matrix, n is the plain terms vector, and X represents the matrix of unknown values (surface parameters) in the Table 3.
Using the calculated parameters and the result values of the function (e ΔBuilding ), Z and Y values of the building points are transferred to the reference plane. The X depth value (Surface Depth ) of the reference plane is calculated by averaging the maximum and minimum X values, and a Surface Filter matrix with the depth of the number of building points is created using the unit matrix. These processes are performed with the following Eqs. (14) and (15): To use the coordinate values obtained by mathematical filtering in the Geometric.m code, the new point cloud matrix was created and written to the  Geometric_Filter_Input.txt file for the references surface.The distance between points was determined as 25 cm, Geometric.m code was executed and 180 new points or openings were written and graphed by creating opening_output_txt file. As a result of this process, the window openings were filled vertically. This segmentation points have shown in the Figure 22.
Since the gaps were calculated in blocks with gap filtering in Matlab, a reclassification was performed to determine which window the dots belonged to. A function which is similar to the exponential filter function used in the transfer of building points to the reference plane was used. The windows which were drawn by using the coordinate values obtained from the result of point segmentation (distance between points is 14.5 cm) in red, surface segmentation in green, and conventional segmentation in magenta are shown in Figures 23 and 24.
To assign these points, the OP_Pen matrix with the number of lines (same as the building point numbers) and with a NaN value was created. Then, points within the 120 cm border were selected from the Matlab code matrix and printed on the OP_Pen matrix. In order to distinguish these assigned values from NaN values, the snip.m code was run once more. The points to be optimized for each window were differentiated and the files OP_PP1.txt, OP_PP2.txt, 0P_PP3.txt, OP_PP4.txt, which  had 2132, 646, 624, 383 points respectively, were created and the data points to be segmented were plotted in the Figure 24.
Matlab coding flowchart for this application is given in Figure 25. Figure 25 has been given in Appendix B.

Conclusion
With this chapter, we observe that point cloud data need fundamental process flow as the fundamental steps of geometric segmentation by Matlab programming. Obviously, Matlab programming which depend on various algorithm by data structures. Geometric segmentation methods should be based on these alghorithm by programmers in the point cloud data. The process examples and some tips are given by Matlab coding in this chapter, which is made for some kind of point cloud  segmentation flowcharts, and an approach to solve fundamental geometric segmentation is presented. Generaly, point cloud data coordinate system does not defined universal coordinate system. Thus, point cloud data listed disorderly by Cyclone 5.2 software are classified in a surface-based way, so it passes through a geometric segmentation before transformation to universal coordinate system.
In the potential, upcoming studies, radiometric and hiybrid segmentation methods might be used in Matlab coding. More accurate results might be obtained by using another method than geometric segmentation technique or by adding a third filter to geometric filtering or other segmentation methods whic are mentioned in this chapter. Matris_Oran(i,1) =(abs(a*(T(i,1)+ b*T(i,2)+ c*T(i,3)+ d)))/sqrt(a*a+b*b+c*c);  DOI: http://dx.doi.org/10.5772/intechopen.95249