This section explains how the TCEDA proposed in this paper uses the block texture change to extend the edge information of the image. When there is a grayscale change between the adjacent pixels, it will be included in the algorithm to determine whether to retain it as the edge of the image of the texture information. As to how to build the edge through the effective block texture feature, this paper distinguishes it in the following three parts: image pre-processing, the optimal edge thinning process, and edge texture construction processing. First, the image pre-processing converts the input color image into a grayscale image. In addition, to reduce the noise interference caused by the imaging technology and the operation of the optical device during the acquisition process, a Gaussian smoothing filter is used to weaken the variation of the grayscale value between the adjacent pixels in the image and the Sobel operator is used to calculate the gradient values of the image. Then, in order to filter the invalid texture variation features, the redundant pixels and weaker edges of the gradient change are regarded as noise. Therefore, a fixed threshold is set in the algorithm to filter noise to reduce its interference with the contour edges of the details in the image. Second, for the optimal edge thinning process, to avoid excessive unnecessary analysis of the image pre-processing results and reduce the complexity of the subsequent object edge construction, the algorithm uses the non-maximum suppression method to find pixels with larger regional gradient values. The point is used as a candidate edge point and the thinning texture template is then used to filter out redundant pixels to achieve the optimal thinning effect. Finally, in the edge texture construction processing part, since the texture change with a long extension has more meaningful edge features, the algorithm establishes the edge texture through the connection between the central block and the four adjacent blocks. The steps in the algorithm are described in detail in the subsections below.
2.2. Optimal Edge Thinning Process
The optimal edge thinning process includes the two steps of non-maximum suppression and the thinning texture template process to achieve optimal edge thinning. Since the edge segments obtained by the pre-processing steps have different thicknesses, to simplify the subsequent analysis and determine the texture change combination required for edge construction, the edge thinning processing is indispensable.
First, the non-maximum suppression method uses the gradient angle obtained by Equation (6) and divides it into four directions, according to the degree of approximation: 0° (i.e., horizontal), 45° (i.e., upper right and lower left), 90° (i.e., vertical), and 135° (i.e., upper left and lower right). Then, it compares the gradient amplitude of the two pixels adjacent to the center pixel according to the gradient direction of the center pixel. When the gradient amplitudes of the two adjacent points are smaller than that of the center pixel, the center pixel is included as a candidate edge point. Conversely, the center pixel is not included as a candidate edge point. Although the method of non-maximum suppression can achieve preliminary thinning processing, there are still many redundant pixels in the candidate edge image after non-maximum suppression.
To filter the redundant pixels processed by the maximum suppression method, a block texture distribution with a center pixel as a redundant pixel is proposed to develop a set of thinning texture templates and a thinning texture template is used to filter out redundant pixels to achieve optimal edge thinning. The redundant pixel filtering process uses a raster-scan method to perform a 3 × 3 pixels block texture comparison on the non-maximum suppressed candidate edge image. When the block texture matches the defined thinning texture template, the redundant pixel in the center of the block is deleted.
Figure 2 shows an example of the thinning process.
When the block texture of the 3 × 3 pixels covered by the center pixel x conforms to the proposed thinning texture template, it is judged as a redundant pixel and gets filtered out. Then, it gets right-shifted to make the judgment of the block texture change of the next point, until the processing of the entire candidate edge image is completed; thus, the image with optimal edge thinning can be obtained.
Next, a method of binarizing the edge texture changes in the block will be described to facilitate subsequent analysis and processing.
Figure 3 illustrates the binary coding method showing the change in block texture. When the pixel gradient amplitude value is not 0, the code is “1”, and otherwise, it is “0”. The coding order starts from the upper left corner of the block and goes in order from left to right and top to bottom.
There are up to four texture changes through angle rotation, i.e., 0°, 90°, 180°, and 270°, in the block. Therefore, after the process of binarization coding is completed, the block binarization coding of the four rotation angles is obtained by changing the bit arrangement order.
Figure 4 shows the coding order of the different angles in the block.
Figure 4a shows the block coding order of 0° and a coding order of 123456789.
Figure 4b shows the block coding order of
Figure 4a with a rotation of 90° to the left and a coding order of 369258147.
Figure 4c shows the block coding order of
Figure 4a with a rotation of 180° to the left and a coding order of 987654321.
Figure 4d shows the block coding of
Figure 4a with a rotation of 270° to the left and a coding order of 741852963.
The binarized block texture template of different angles can be obtained using the binarized block texture template of 0°.
Figure 5 shows the schematic of a block texture template that uses a permutation order of the binarized coding order to obtain different angles.
Figure 5a shows a texture change at 0° and a binarization code of 000011110.
Figure 5b shows a texture change with
Figure 5a rotated by 180° to the left and a binarization code of 011110000. Therefore, in the subsequent thinning texture template, only the 0° binarized block texture must be retained and the remaining three angle changed binarized block textures can be obtained by different coding orders.
The binarized coding of the thinning texture template developed at the table is shown in
Table 1. According to the number of pixels and the distribution, it can be summarized into 31 patterns and sorted according to the size of the binarized value. Among them, there are 28 types of templates with four angle changes, one type of template with two angle changes, and two types of templates with a single angle change. The four angle changes refer to the four different textures of the template containing 0°, 90°, 180°, and 270° of angle rotation; the two angle changes refer to the two different textures of the pixels in the template containing 0° and 90° angle rotation; and the single angle change means that the template contains a texture of 0°.
Next, a processing method for filtering out redundant pixels of the candidate edge images processed by the non-maximum suppression method according to the thinning texture template prepared will be described. First, the edge point of the candidate edge image is taken as the center pixel and a block of 3 × 3 pixels is taken out. When there is one pixel in the block, it is regarded as isolated noise filtering; when the block has two pixels, it is regarded as the end of the edge segment; and when there are three or more pixels in the block, the thinning texture template in
Table 1 and its angled rotation are compared to see whether the texture changes match according to the number of pixels in the block. When they match, the redundant pixels in the candidate edge image are filtered out sequentially in the raster-scan process to achieve the best edge thinning process.
Figure 6 shows the preliminary thinning candidate edge image obtained in
Figure 1c after the non-maximum suppression method. From the partial enlargement area, it can be observed that there are still redundant pixels around most of the edges, so it does not achieve the optimal edge thinning treatment.
Figure 7 shows the best edge thinning image obtained after the thinning texture template processing. Through the partial enlargement area, it can be clearly seen that the image edge is composed of only a single pixel, which can effectively filter pixels that have not performed the maximum suppression. There are still redundant pixels around the image edges to achieve optimal edge thinning. The total number of candidate edge points in
Figure 6 is 45,608, and the total number of optimal thinning edge points in
Figure 7 is 38,835. In
Figure 7, when compared to
Figure 6, the number of candidate edge points is reduced by 6773, which is about 15% lower than the number of edge points. The optimal edge thinning results obtained after processing will facilitate the analysis and processing of the subsequent edge texture construction.
2.3. Edge Texture Construction Processing
After the optimal edge thinning process step is completed, the edge image of the component is extended by the block edge texture template processing for the edge image of the optimal edge thinning. Since the extended texture change has more meaningful edge features, the edge texture construction processing is extended by expanding the edge texture template created between adjacent blocks, which defines a single edge segment as having at least six pixels. With the above extension length, the edge texture construction processing marks the edge points that satisfy the abovementioned conditional edge texture changes as valid points.
Figure 8 shows the block texture scan mask of the present process, which is composed of five adjacent 3 × 3 pixels blocks, based on the relation between the edge points of number
x1–
x5 in the central block
X, where the center pixel
x is located, and the adjacent blocks
P,
Q,
R, and
S, as well as the change in the texture length, to preserve the edge texture information.
The edge texture construction processing aims to use the block texture scan mask as the range to process the edge image with the optimal edge thinning process of the raster-scan method. In order to preserve the effective edge texture information in the image after the optimal edge thinning process, the process scans all edge points pixel-by-pixel and sequentially marks the edge points that meet the conditions. All edge points marked after scanning the entire image are the final edge detection results.
Figure 9 shows the flow of the proposed edge texture construction processing.
Each process of the edge texture construction processing is sequentially described in the flowchart of
Figure 9. First, the image with optimal edge thinning is used as the source image input, and then it is determined whether all edge points in the source image are processed completely. When all edge points have been processed, the process ends and the edge image with the edge texture mark is obtained. Conversely, when there is an unprocessed edge point, the raster-scan sequence is moved to the next edge point and the subsequent pixel is processed with the point as the center pixel.
Then, it is judged whether the nine points in the X block, where the center pixel is located, have edge points marked as valid points. When there are edge points marked as valid points, the process proceeds to the next process to perform block X edge point processing. The edge point of the valid point in x1–x5 is first deducted, and one records the position of all edge points in the X block and proceeds to the next process to determine whether there is an edge point in x1–x5. When there is no edge point, one goes to the marking processing step to process all edge points in the X block; when there are still edge points, the block texture extension analysis is performed in the next step of the flowchart. When no edge points of the nine points in the X block are marked as valid points, the number of edge points of the X block in which the center pixel is located is calculated: when the block contains at least three (inclusive) or more edge points, it goes to the block texture extension analysis; when there are less than three edge points in the block, the endpoint of the edge segment is regarded as unmarked, the initial step of the edge texture construction processing is returned to, and the next edge point is processed.
Next, the method of block texture extension analysis is described as a whole. The block texture extension analysis is based on the block scan mask range of
Figure 8. Through the
X block where the center pixel is located and its extended connection among the four adjacent blocks
P,
Q,
R, and
S, horizontal, vertical, and diagonal edge texture changes are formed. During the processing, the texture of the adjacent block is first determined. The position of the edge point of
x1–
x5 in the
X block is used to determine whether there are adjacent points in the adjacent block and the following three cases are distinguished.
In the first case, when there is no adjacent point in the adjacent block, the marking process is not performed and the block texture extension analysis is completed, and the next step of the flowchart is performed. In the second case, when adjacent blocks have adjacent points and any adjacent point is marked as valid, the x1–x5 edge points adjacent to the valid points must be deducted; meanwhile, the positions of all edge points in the X blocks are additionally recorded and it is judged whether there are edge points in x1–x5. When there is no edge point, the block texture extension analysis is completed, all edge points of the X block to be marked are recorded, and the next step of the flowchart is followed. When there are still edge points left, one checks whether there are adjacent points in the adjacent blocks: when there is no adjacent point, the first case is processed; when there are adjacent points, the third case is processed to perform the analysis.
In the third case, when the adjacent blocks have adjacent points, but the adjacent points are not marked as valid, the table lookup and comparison are performed according to the texture distribution of the adjacent blocks and all block texture templates that may meet the length of the effective edge line segment, as shown in
Table 2,
Table 3,
Table 4,
Table 5,
Table 6,
Table 7,
Table 8,
Table 9,
Table 10,
Table 11,
Table 12,
Table 13,
Table 14 and
Table 15. To speed up the table lookup process, the block texture template converts the binarized code in the block into a decimal number, which is sorted from small to large. The comparison process is based on the binary search method [
18]. If the comparison result is consistent, it means that the central and adjacent blocks have an edge texture change that satisfies the condition. Then, the block texture extension analysis is completed and the positions of all edge points in the
X block and the adjacent block to be marked are recorded. It then proceeds to the next step of the flowchart. On the other hand, if the comparison result does not match, the cross-block texture extension judgment is performed, where the position of the edge point of
x1–
x5 in the
X block is used as the starting point and one searches for edge points in the area adjacent to 8 that does not contain the
X block. When there are less than three points in the adjacent area and none of them are marked as valid, the
X block and the adjacent area are not marked. The block texture extension analysis is then completed and the next step of the flowchart is followed; when the adjacent area is extended to an area where three edge points (inclusive) are marked as valid, the block texture extension analysis is completed and all required positions in the
X block and adjacent areas are recorded, and the next step of the flowchart is followed; when the number of adjacent edge points reaches three, the block texture extension analysis is completed and all required positions in the
X block and adjacent areas are recorded, and the next step of the flowchart is followed.
The following is a detailed description of the third case for the abovementioned block texture extension analysis. When the X block has adjacent points and is not marked as a valid point, one checks the table to extend the texture change between the adjacent blocks. Additionally, the corresponding method is proposed for the number of x1–x5 edge points in the X block for one point, two points, and three points, respectively. Because there is no edge point above four points (inclusive) after a point in the center and the optimal edge thinning process, the edge point above four points (inclusive) will not appear. The related method description will now be presented.
When there is a one-point edge point, there are five types of distributions, such as
x1–
x5, where
x1 and
x2 are adjacent to the
P block;
x3 is adjacent to the
P,
Q, and
R blocks;
x4 is adjacent to the
R block; and
x5 is adjacent to the
R and
S blocks. Among these,
x1 is the
P block texture template corresponding to
Table 2;
x2 is the
P block texture template corresponding to
Table 3; and
x3 is adjacent to three blocks, which are
P,
Q, and
R. Therefore, when the adjacent
P block has adjacent point
p6 or
p7, it corresponds to the
P block texture template of
Table 4; when the adjacent
Q block
q7 has edge points, it corresponds to the
Q block texture template of
Table 5; and when the adjacent
R block
r1 or
r8 has edge points, it corresponds to the
R block texture template of
Table 6.
x4 is the
R block texture template corresponding to
Table 7 and
x5 is adjacent to
R and
S 2 blocks. When the adjacent
R block
r7 or
r8 has edge points, it corresponds to the
R block texture template of
Table 8; when the adjacent
S block
s1 has edge points, it corresponds to the
S block texture template of
Table 9. During the lookup process, when the texture distribution of all adjacent blocks matches the corresponding texture template, the block texture extension analysis is completed and all required positions in the
X block and adjacent areas are recorded, and the next step in the flowchart is followed. If this is not the case, it goes to the cross-block texture extension judgement.
When there are two edge points, they are divided into the left side of
x1,
x2, and
x3 and upper side of
x3,
x4, and
x5, according to the distribution position of
x1–
x5 in the
X block, and whether the two points are on the same side is judged by the position of the edge point. When the two edge points do not fall on the same side, the method is the same as the one edge point, and the adjacent block texture templates are sequentially checked and compared; when the two edge points are located on the same side, there are three cases on the left side, comprising
x1 and
x2,
x1 and
x3, and
x2 and
x3, and the corresponding
P block texture templates are shown in
Table 10,
Table 11 and
Table 12. When there is an edge point in
x3 and because it is adjacent to the
Q and
R blocks, when the
Q block
q7 has an edge point or the
r1 or
r8 in
R block has an edge point, one will sequentially lookup and compare the corresponding
Table 5 and
Table 6. There are three cases of
x3 and
x4,
x3 and
x5, and
x4 and
x5 on the upper side, and the corresponding
R block texture templates are shown in
Table 13,
Table 14 and
Table 15. When there is an edge point in
x3 and because it is adjacent to the
P and
Q blocks, when the
P block
p5 or
p6 has an edge point or the
Q block
q7 has an edge point, one will sequentially look up and compare the corresponding
Table 4 and
Table 5. When
x5 has edge points and because it is adjacent to the
S block, it must be compared with the corresponding
Table 9 when the
S block
s1 has edge points. In the process of checking the table, when the texture distribution of the adjacent block matches the corresponding texture template, the block texture extension analysis is completed and all required positions in the
X block and adjacent areas are recorded, and the next step in the flowchart is followed. If this is not the case, the cross-block texture extension judgement is performed.
When there are three edge points, there are two cases according to the distribution position of x1–x5 in the X block. In the first case, when x3 has edge points, there will be two edge points on both the left and upper sides. In the second case, when x3 has no edge point, there are two points on one side and one point on the other side. For the case where there are two points on one side, the block texture extension analysis is performed in the manner of the above two edge points, and in the case where there is only one point on one side, the block texture extension analysis is performed in the manner of the above one edge point. Next, when the adjacent block texture extension is judged in the table comparison process, the method of judging the cross-block texture extension is further required when the non-conforming block texture template is checked. The cross-block texture extension judges that the position of the edge point of x1–x5 in the X block is used as a judgment starting point, and searches for and extends the adjacent edge point by a range of eight adjacent points. When the adjacent edge points are less than three, and none of them are marked as a valid point, the X block and the adjacent edge points are not marked, and then, the block texture extension analysis is completed and the next step of the flowchart is performed. When the number of adjacent edge points is within three (inclusive) and there are edge points marked as valid, the block texture extension analysis is completed and all required positions in the X block and the adjacent areas are recorded, and the next step in the flowchart is followed. When the number of adjacent edge points reaches three, the block texture extension analysis is completed and all required positions in the X block and the adjacent areas are recorded, and the next step in the flowchart is followed.
Two examples are used to illustrate the analysis process of adjacent block texture extension judgment and cross-block texture extension judgment. First, in the adjacent block texture extension analysis, a more complex three-point edge in X block x1–x5 is used.
Figure 10 shows a schematic of the texture extension of adjacent blocks. First, one determines the number of edge points of
x1–
x5 in the
X block, and knows that in the
X block, there are three edge points, consisting of
x1,
x3, and
x5. Then, one can determine that
x1–
x5 is in the
X block according to the distribution position of the above three points in the block. Because there is an
x3 edge point, there are two edge points on both the left and upper sides, so one sequentially checks whether the adjacent blocks have adjacent points. When there are adjacent points, the adjacent block is further checked and compared.
To start the next step, one checks the edge point of the adjacent
P block
p7, and then compares the
P block texture template of
Table 11 with two points on the left side.
Table 11 shows that the
P block texture code is 000000111 and the decimal is 7, so one knows that the data in the first column is consistent. When the adjacent
Q block
q7 has edge points, based on the
Q block texture template corresponding to
Table 5 to check the table comparison, it can be known that the
Q block texture code is 010010001, the decimal is 145, and it is consistent with the third data in the fourth column in
Table 5. When the block texture of the adjacent block
R has no adjacent points, no table lookup is performed. When the adjacent
S block s1 has edge points, it corresponds to the
S block texture template in
Table 9. From the table lookup and comparison, it can be known that the
S block texture code is 000001110, the decimal is 14, and it is consistent with the second data of the first column in
Table 9. The block texture extension analysis is then completed and the next step of the flowchart is performed after recording all required positions of edge points in the
X and the adjacent
P,
Q, and
S blocks.
Figure 11 shows the cross-block texture extension diagram.
First, one determines the number of edge points of
x1-x5 in the
X block and finds that
x2 has one edge point. One then checks the edge points in the adjacent block and finds that there is an edge in the
P block
p6; the table comparison is performed with the
P block texture template corresponding to
Table 3. After checking the table, there is no matching data, and the cross-block texture extension judgment is performed. First, one searches for eight adjacent points with
x2 as the center to find
p6. Then, one searches for eight adjacent points centered on
p6, and finds
p4. Finally, one searches for eight adjacent points with
p4 as the center and finds
q8. When the search process encounters the edge point that has been marked as a valid point or when the extension of three pixels has not been marked as a valid point, the search is stopped; that is, the block texture extension analysis is completed. The positions of edge points in the
X block and the adjacent edge points
p6,
p4, and
q8 are recorded, and the next step of the flowchart is then performed.
After the block texture extension analysis is completed, the judgment is made as to whether to perform the marking process. The marking process is performed according to the position of the edge point recorded in the analysis process to be marked as a valid point. The adjacent block texture extension aims to mark the edge point positions in block
X and all adjacent blocks
P,
Q,
R, and
S. The cross-block texture extension aims to mark the edge point position in block X and extended edge points. During the marking process, the edge points that have been marked as valid are not duplicated. After all the edge points have been processed, the data marked as valid points are output; that is, the edge image after the edge texture construction process is completed.
Figure 12 shows a comparison of the edge images obtained by the optimal edge thinning process and the edge texture construction processing.
Figure 12a is the edge image after the optimal edge thinning process, including 38,835 points as the candidate edges.
Figure 12b is the edge image obtained from
Figure 12a after the edge texture construction processing is completed. After filtering through the effective edge texture condition, the total number of edges included is 32,582 points. Through the analysis of the total number of edge points, the edge texture construction processing is reduced by 6253 points compared to the optimal edge thinning process, reducing the edge points by about 16%. The edge image obtained by the above can reveal the retention of the texture through a long line segment, which can retain more meaningful edge texture information.
The proposed TCEDA achieves richer edge detection by retaining effective block edge texture changes.
Figure 13 shows the effect of this algorithm on edge detection. The local magnification area shown in
Figure 13a indicates that there are many obvious cracks on the wall. Although it is similar to the color of the wall, the construction of the effective edge texture can effectively detect the edge of the crack, as shown in
Figure 13b.