A method for roof damage identification and damage rate calculation of traditional village buildings
By training the roof instance segmentation model and using the SVM classifier, combined with the SLIC algorithm for super-pixel segmentation, the problem of identification and calculation of damage to traditional village building roofs has been solved, and the quantitative assessment and damage rate calculation of traditional village building roofs have been achieved, improving the efficiency Recognition accuracy and automation.
Patent Information
- Application Number
- CN202311238152.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2043-09-25
AI Technical Summary
Existing technology cannot effectively identify and calculate roof damage in traditional village buildings, especially for non-rectangular buildings and roof images. There is a lack of damage identification and calculation methods, and it is impossible to quantify the degree of roof damage.
By training the damaged roof instance segmentation model, using YOLOv8x-seg.pt pre-trained weight model, combined with the SLIC algorithm for super-pixel segmentation, and using the SVM classifier to identify the damaged areas, non-damaged areas, patios and courtyard areas of the roof, and calculate the damage rate.
It achieves quantitative assessment of roof damage of traditional village buildings, improves the accuracy and automation of damage identification, is suitable for different forms of traditional village buildings, and expands the regional scope of roof damage identification.
Smart Images

Figure CN117523405B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image segmentation, and in particular to a method for identifying damage of roofs of traditional village buildings and calculating a damage rate. Background Art
[0002] Traditional village historical buildings are an important historical and cultural heritage, but due to poor protection and utilization, the buildings are affected by insects, weathering, moisture and other factors, resulting in serious damage to the building components. Among traditional building components, roof tiles are lighter than masonry walls and wooden beams, and their characteristics of being exposed outdoors are more susceptible to natural erosion; at the same time, the top surface of the building is the most significant feature of the building observed in remote sensing images, and the calculation of its roof damage rate is of great significance to the assessment of the overall degree of damage to the building.
[0003] At present, the detection of the degree of damage to building roofs is mainly aimed at modern building areas. On the one hand, multi-temporal remote sensing images are used to detect the degree of change in the roof area of the area, which is mainly used in areas affected by disasters such as fires and earthquakes to collect statistics on the damage to buildings before and after the disaster; on the other hand, single-temporal remote sensing images are used to identify the damaged area of the building roof. However, there are still the following problems:
[0004] (1) No method for damage identification and damage rate calculation for traditional village buildings has been proposed. The existing technology mainly focuses on the damage identification type of modern buildings.
[0005] (2) No method is proposed to quantify the degree of roof damage into a numerical value. The existing technology can only detect the location of the damaged area of the building roof, but cannot calculate the degree of roof damage.
[0006] (3) No method for damage recognition and calculation of non-rectangular building roof images has been proposed. The current building roof recognition method is only for a single straight-edged rectangular roof, which is not universal for traditional villages with a variety of plane forms.
[0007] Therefore, it is urgent to propose a method for damage identification based on the image features of traditional village remote sensing images and taking the building roof morphology as the area of interest to achieve quantitative assessment of the degree of damage to the building roof. Summary of the invention
[0008] The purpose of the present invention is to solve the above-mentioned defects in the prior art and provide a method for identifying damaged roofs and calculating damage rates of traditional village buildings. The method predicts the segmentation results of damaged roofs and non-damaged roofs of the test samples to be segmented by training a damaged roof instance segmentation model; then superpixel segmentation is performed within the damaged roof mask range in the segmentation result, so that the damaged roof damage detection is clustered into superpixel blocks with semantic information in units of pixels; then the superpixel blocks are identified by the SVM classifier to distinguish the damaged areas, non-damaged areas, patios and courtyard areas of the building roofs with semantic information, and the building damage rate is determined by calculating the pixel ratio. This algorithm includes two-scale image segmentation methods, which segment damaged roofs and non-damaged roofs by example at the traditional village scale; and superpixel segmentation of damaged areas, non-damaged areas, patios and courtyard areas of damaged roofs at the building monomer scale. This method can establish a complete process for identifying damaged roofs and calculating damage rates in traditional villages from macro to micro scales, simplify the operation steps, and provide an effective way to improve the accuracy and automation of overall damage assessment of traditional villages.
[0009] The purpose of the present invention can be achieved by adopting the following technical solutions:
[0010] A method for identifying damage to the roof of a traditional village building and calculating the damage rate, the method comprising the following steps:
[0011] S1. Obtaining remote sensing images of traditional villages: Using satellite remote sensing images from Google Earth as the basic image source, download remote sensing images of traditional villages; divide the remote sensing images into training samples and test samples in proportion, wherein 90% are used as training samples and the remaining 10% are used as test samples;
[0012] S2. Create a training set to construct a damaged roof instance segmentation model: Use the training samples in the previous step to annotate remote sensing images containing traditional village buildings to form a training set T, wherein the training set T contains two types of target objects. The first type of target object is labeled as broken, corresponding to the damaged roof of traditional village buildings; the second type of target object is labeled as non-broken, corresponding to the non-damaged roof of traditional village buildings. Use the training set T to train on the basis of the yolov8x-seg.pt pre-trained weight model to obtain the damaged roof instance segmentation model Posun_BEST.pt;
[0013] S3, input the test sample to be segmented into the damaged roof instance segmentation model to obtain the instance segmentation result: input the picture in the test sample in step S1 into the damaged roof instance segmentation model Posun_BEST.pt for segmentation, and obtain the damaged roof and non-damaged roof instance segmentation results in each picture by calculation;
[0014] S4. Define the mask range of the damaged roof in the instance segmentation result for superpixel segmentation, and extract the superpixel sub-block image of a single damaged roof: Use the instance segmentation result of the previous step to extract the mask range Mask of the damaged roof in each image one by one, perform superpixel segmentation within the mask range through the SLIC algorithm, obtain the clustered superpixel blocks, extract the superpixel blocks as sub-block images, and constitute the test set d.
[0015] S5. Input the sub-block image into the trained SVM classifier: Use the sub-block image in the previous step and input it into the trained SVM classifier, wherein the SVM classifier includes three target recognition categories, the first category is the sub-block image of the non-damaged area, with a label of 0; the second category is the sub-block image of the damaged area, with a label of 1; the third category is the sub-block image of the patio and courtyard area, with a label of 2; use the SVM classifier for recognition, and obtain classification results of three types of sub-block images: damaged area, non-damaged area, patio and courtyard area.
[0016] S6. Damage rate calculation: Using the classification result of the previous step, calculate the value of the ratio of the pixel points of the damaged area sub-block image of a single damaged roof to the sum of the pixel points of the damaged area and non-damaged area sub-block images. This value is the calculation result of the damage rate of a single building roof.
[0017] Furthermore, in step S1, the remote sensing image of the traditional village is obtained from a public map service provider, and the image format should be jpg, which is suitable for the file format required by the annotation tool in the next step; in order to provide sufficient data for model training and retain a certain amount of data for evaluating the performance of the model on unseen samples, 90% of the remote sensing image is used as training samples and the remaining 10% is used as test samples.
[0018] Furthermore, the training samples are polygonally annotated by the Labelme image annotation tool to form a training set T, which includes two types of target objects. The first type of target object is marked as broken, corresponding to the traditional village building roof in a damaged state; the characteristics of the traditional village building roof in a damaged state in the remote sensing image include: irregular shape characteristics due to the lack of roofing materials; color difference and texture difference characteristics different from the surrounding intact roofs due to the lack of roofing materials; the second type of target object is non-broken, corresponding to the traditional village building roof in a non-damaged state; the characteristics of the traditional village building roof in a non-damaged state in the remote sensing image include: continuous, repeated, and uniform texture characteristics and color characteristics; complete shape, clear boundaries, no obvious cracks or bumps; consistency with surrounding buildings; in order to ensure that the key points of the polygon annotation can accurately outline the overall outline of each building, it is necessary to use an appropriate number of key points to be evenly distributed on the drawing during annotation to avoid placing the key points in positions where the objects are blocked or blurred.
[0019] Furthermore, the training and acquisition process of the damaged roof instance segmentation model Posun_BEST.pt in step S2 includes: downloading the YOLOv8 network data configuration file provided by Glenn Jocher and other developers from the official website of the code and software development platform GitHub, setting the initial parameters of the YOLOv8 network data configuration file and inputting the YOLOv8x-seg network instance segmentation model, using the pre-trained weights of yolov8x-seg.pt, and training the iteration number of 300 generations, and finally obtaining the damaged roof instance segmentation model Posun_BEST.pt. The YOLOv8x-seg network instance segmentation model involves identifying a single object in an image and separating the identified object from the background; the output result is a set of masks, as well as the category label and confidence score of each object, which can determine the position and exact shape of the identified object in the image. The damaged roof instance segmentation model Posun_BEST.pt optimized by the network instance segmentation model YOLOv8x-seg can determine the position of the damaged roof on the image and extract the mask outline of the damaged roof.
[0020] Furthermore, in step S3, the test sample is input into the damaged roof instance segmentation model Posun_BEST.pt for calculation, and the instance segmentation result of each remote sensing image is saved, wherein the result includes the target object type, the target object detection frame, and the target object mask contour: the target object type includes a non-damaged roof with a label of 0 and a damaged roof with a label of 1; the target object detection frame is used to roughly frame the instance in the image; the target object mask contour is a set of binary masks used to identify pixels related to the instance, a mask of 1 indicates that the pixel belongs to the instance, and a mask of 0 indicates that it does not belong to the instance. The coordinates of the key points of each target object mask contour on the image and the labels corresponding to the target object type are written into a txt document in sequence, and the txt document contains one or more target objects of the instance segmentation result of a remote sensing image.
[0021] Furthermore, in step S4, the target object type with label 1 is extracted from the txt document of step S3, and the coordinates of the key points of the mask contour corresponding to the target object type are returned to the remote sensing image to generate a damaged roof mask range image in png format. The damaged roof mask range image is used as the superpixel segmentation range of the next step. The damaged roof mask range image requires that the pixel values within the range are 0, while the pixel values outside the range are 0; since png images support transparent pixel channels and can represent transparent pixels in the image, the image format needs to be defined as png.
[0022] Furthermore, in step S4, superpixel segmentation is performed within the mask range by using the SLIC algorithm. This method is used to cluster pixels into superpixel blocks within an irregular region of interest, and has been verified in two to four dimensions. Load the original data configuration file maskSLIC, set the number of segmented superpixel blocks n_segments to 100, set the boundary flatness compactness to 10, and extract the segmented superpixel blocks as sub-block images after optimizing the parameters. It will be used in the present invention to customize the mask outline of the target object as the superpixel segmentation range, and to achieve the effect of identifying multiple scattered damaged roofs on a remote sensing image and performing superpixel segmentation within the corresponding mask range at the same time. The specific operation process is as follows:
[0023] S41. For each input image, within the mask range Mask area of each damaged roof target object, there are i pixels. Given the number of superpixels N, the Euclidean distance transform method is used to iteratively place seed points so that the distance between the placed seed points and the boundary and other seed points is maximized, indicating that the position of the seed points should be far away from the image boundary and other already placed seed points. The purpose is to ensure that the seed points can cover the entire object or area as much as possible and are not too dense with each other. The Euclidean distance transform is used to transform a binary image into a grayscale image, using the most commonly used Euclidean distance as the distance metric to find the distance between each foreground pixel and the nearest background pixel. B is a set of background (non-mask) labels, and L is a set containing background B and seed points P, that is, L=B∪P, and the initial P={}. The specific form is as follows:
[0024]
[0025] Where D(x) represents the distance between points, (x, y) represents the spatial position information of pixel i, and n represents the number of spatial dimensions. The maximum distance p* is obtained as follows:
[0026]
[0027] P becomes P∪{p*} corresponding to the next iteration, and the iteration needs to be repeated N times.
[0028] S42. Apply the SLIC algorithm to the seed point P with only distance features. The distance function used for clustering in the SLIC method is d, and the specific form is as follows:
[0029] Where d = d s , d f Denotes the feature distance, d s represents the spatial distance, and r represents the weight of feature distance and spatial distance.
[0030] This step optimizes the placement of seed points based on the mask range. On the one hand, it prevents the superpixel block from being affected by the changes in the critical pixels around the mask range; on the other hand, it avoids the failure of superpixel clustering due to the absence of seed points in the mask due to the deviation in the relative position of the mask and the seed point.
[0031] The principle of the above SLIC algorithm is to place cluster center grids at equal distances on the image, apply local k-means clustering to assign each pixel to the cluster center, and update the cluster center based on the assigned pixels. The update process is repeated until the distance between the new seed point and the original seed point is small enough, and the iteration is terminated. Finally, it is applied to the pixels defined within the mask range.
[0032] Furthermore, the SVM classifier in step S5 is an optimization algorithm based on supervised learning, which is mainly used to solve the problem of binary classification of data in the field of remote sensing image recognition. In the paper "Leaf Image Segmentation Based on Support Vector Machine" published by Wu Zhangqian et al. in 2022, it is mentioned that the SVM classifier is based on the principle of structural risk minimization. By constructing an N-dimensional hyperplane as a decision surface, the classification interval between positive and negative samples is maximized. By training the classification model on the positive and negative sample sets, the test data is classified to achieve the purpose of image segmentation. The building roofs identified in the present invention include the load-bearing and enclosure components on the indoor space, the patio and courtyard of the indoor space. When calculating the damage rate, it is only necessary to obtain the data of the damaged area and the non-damaged area corresponding to the load-bearing and enclosure components above the indoor space. Therefore, the SVM classifier used in the present invention needs to realize the three classifications of the damaged roof into damaged area, non-damaged area, and patio and courtyard area: a one-to-many SVM multi-classifier is constructed through multiple SVM binary classifiers, and three SVM binary classifiers are constructed for the three categories in the present invention. Each classifier uses one of the categories as a positive sample and all other categories as negative samples. Finally, the category of the test sample is determined by probability or distance, and image segmentation is performed based on the image features (such as material, color, etc.) of the damaged area, non-damaged area, patio and courtyard area in the building roof, so as to solve the three classification problems of the damaged area, non-damaged area, patio and courtyard of the building roof in the remote sensing image. The specific steps for making and training the SVM classifier are as follows:
[0033] S51, obtaining a remote sensing image of a single building roof in a traditional village as an initial image;
[0034] S52, using the SLIC algorithm to perform superpixel segmentation on all the above single building roof remote sensing images to obtain different sub-block images R = {R 1 ,R 2 ,R 3 ,R 4 ...R n}, the sub-block images are divided into three categories, the first category is the non-damaged area, the corresponding label is 0; the second category is the damaged area, the corresponding label is 1; the third category is the patio and courtyard area, the corresponding label is 2; in order to more accurately identify each category of blocks, the sub-block images need to be manually screened after extraction, and the sub-block images containing multiple feature target recognition types are eliminated. For example, when a sub-block image contains both damaged areas and non-damaged areas, it needs to be manually eliminated; at the same time, the sub-block image name and the corresponding label are written into the train_labels.txt document, normalized to 128px×100px size, as the training set D for the next step of training the SVM classifier;
[0035] S53, extract the color features and HOG features of each sub-block image in the training set D to form a combined feature vector, and then input the combined feature vector into the SVM classifier after normalization. Specifically, color features are the most widely used and intuitive visual features in image segmentation applications. They are closely related to different types of targets and scenes in the image, and can distinguish pixel areas with different semantic information without being affected by the image's own attributes; HOG features describe the appearance and shape of the target on the local grid cells of the image, and can maintain good invariance to the optical and deformation of the image geometry. The color features and HOG features of the image are used to describe the features of the segmented area, which can ignore the slight deviation of the coarse spatial area of the building roof and improve the recognition efficiency;
[0036] Specifically, the commonly used color spaces in the color feature mainly include RGB, YCbCr, HSV, CIELab, CMYK, HIS, etc. Each color space has a usage background suitable for its own characteristics. Since the HSV color space is more in line with human vision than other types of color spaces, it is more sensitive to brightness and is conducive to the distinction of color features. Therefore, the present invention extracts the features of the HSV color space of the training set D; the long axis of the sub-block image after normalization is 128 pixels and the wide axis is 100 pixels, so the area of 128×100 pixels centered on the centroid is extracted for calculating the HOG feature; the cell size of the HOG feature is 8×8 pixels, and 12 direction blocks are extracted in the gradient direction, generating a total of 31680 HOG features. In order to prevent smaller feature components from being ignored in the calculation, two different types of feature quantities are normalized so that all components have the same weight when describing the features.
[0037] S54, inputting the combined feature vector into an SVM classifier for training, and obtaining an SVM classifier with optimized parameters.
[0038] Furthermore, in step S5, the sub-block image is input into the trained SVM classifier, and the image name and the corresponding recognition result label are written into the results.txt document to obtain the recognition result r of each sub-block image. The recognition result r is only to detect the sub-block image category and assign the corresponding label. At this time, the sub-block image is still an independent image file. In order to return these individual sub-block image files to the original image position and clearly show the position of the damaged area in the original image, it is necessary to illustrate the recognition result into a damaged area recognition image. The specific steps are as follows: convert the combined feature vectors with labels of 0 and 2 in the recognition result r into a binary matrix with a pixel value of 0, and convert the combined feature vectors with a label of 1 in the recognition result into a binary matrix with a pixel value of 1, and obtain a total of W binary matrices to reconstruct the binary image, superimpose the binary image and the image in the test sample, and obtain the damaged area recognition image.
[0039] Furthermore, in step S6, since the damaged area recognition image is a superposition of the binary image and the image in the test sample, direct calculation will result in repeated superposition of pixels, so the damage rate calculation uses the pixels of the sub-block image for calculation, and the damage rate calculation formula is:
[0040]
[0041] Pixels 1 Represents the total number of pixels in the damaged area sub-block image of a single damaged roof, pixels 0 Represents the total number of pixels in the sub-block image of the non-damaged area of a single damaged roof.
[0042] Furthermore, in step S6, the pixel summation calculation process of each type of sub-block image is as follows: define the sub-block image name and the corresponding category label according to the recognition result r; traverse each sub-block image in the test set d, calculate the number of non-transparent pixels in the image and continue to accumulate them to the corresponding category, and obtain the pixel summation of the required type. Since the damage rate calculation only uses the pixel data of the damaged area and the non-damaged area, the sub-block image with the label of 2 can be eliminated when the pixels are accumulated, thereby improving the traversal calculation efficiency.
[0043] Compared with the prior art, the present invention has the following advantages and effects:
[0044] 1. The method of the present invention proposes a method for identifying damaged roofs of traditional village buildings. On the one hand, since traditional village buildings are mainly made of double-slope roofs and tile materials, which are inconsistent with the image features of modern buildings that are mainly made of flat roofs and concrete materials, the present invention produces a traditional village remote sensing image dataset, combines the YOLOv8 module training and obtains a damaged roof instance segmentation model for traditional village buildings; on the other hand, the building categories in traditional villages also include other non-rectangular building forms, such as dragon-enclosed houses, round buildings, and gun-shaped quadrangular buildings. The instance segmentation model constructed by the present invention is suitable for irregular objects and can be used to identify other non-rectangular building forms on remote sensing images in different regions, increasing the types of buildings that can identify roofs and expanding the geographical scope of roof damage identification.
[0045] 2. The method of the present invention proposes a method for superpixel segmentation in the region of interest of the building roof. By optimizing the traditional SLIC superpixel segmentation method, it is possible to customize the superpixel segmentation range, place seed points within the customized range and cluster the pixel points, thereby identifying damaged areas in non-rectangular and irregular roofs, breaking the limitations of traditional methods on object morphology, and proposing a superpixel segmentation method suitable for special morphological ranges.
[0046] 3. The present invention can capture the shape features of the roof of traditional village buildings and distinguish different areas. Since the patio and courtyard areas in traditional village buildings are part of the whole building but do not belong to the roof of the building, it is impossible to distinguish the patio and courtyard areas from the building roof during instance segmentation. Therefore, by optimizing the SVM binary classifier into a multi-classifier, the color features and HOG features of the sub-block images of different categories of buildings are extracted, and the three categories of non-damaged areas, damaged areas, and patio and courtyard areas are identified. When calculating the damage rate, the patio and courtyard areas are excluded to improve the accuracy of the calculation of the damage rate of the building roof.
[0047] 4. The method of the present invention quantifies the degree of damage of the building roof into a numerical value. By superimposing the pixel points of the damaged area with the pixel points of the non-damaged area and using a formula to calculate the damage rate of a single building roof, this method is used to traverse the buildings of the entire traditional village, and the degree of decline of the traditional village can be evaluated, further strengthening the quantitative research on the collection of basic data on traditional villages. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0049] Figure 1 It is a flowchart of the steps of a method for identifying damage to the roof of a traditional village building and calculating the damage rate disclosed in the present invention;
[0050] Figure 2 It is a flow chart of the YOLACT algorithm used by the YOLOv8 network model used in the present invention;
[0051] Figure 3 This is a damaged roof instance segmentation model result diagram obtained through multiple training iterative optimizations in Example 1 of the present invention;
[0052] Figure 4 is a schematic diagram of an example segmentation result image M randomly selected in Example 1 of the present invention;
[0053] Figure 5 is a schematic diagram of the mask range of the damaged roof in the image M extracted in Example 1 of the present invention;
[0054] Figure 6 is a schematic diagram of the segmentation result of performing superpixel segmentation within the mask range of a damaged roof in the image M according to the first embodiment of the present invention;
[0055] Figure 7 is a binary image of a damaged area of the image M in the first embodiment of the present invention;
[0056] Figure 8is a damaged area identification map of image M according to embodiment 1 of the present invention;
[0057] Fig. 9 is a damaged area identification diagram of the image M after being enlarged according to the first embodiment of the present invention;
[0058] Fig.10 is a schematic diagram of the segmentation result of performing superpixel segmentation within the mask range of a damaged roof in the image M according to the second embodiment of the present invention;
[0059] Fig.11 is a damaged area identification map of image M according to embodiment 2 of the present invention;
[0060] Fig.12 It is a comparison chart of the results of Example 1, Example 2 and manual identification of damaged areas of the present invention. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0062] Example 1
[0063] This embodiment discloses a method for identifying damage to the roof of a traditional village building and calculating the damage rate. The steps of the method for identifying damage to a damaged roof and calculating the damage rate are as follows:
[0064] S1. Obtaining remote sensing images of traditional villages: Using satellite remote sensing images from Google Earth as the basic image source, download remote sensing images of traditional villages; use 90% of the remote sensing images as training samples and the remaining 10% as test samples;
[0065] In the above S1 step, first download Meizhou, Xingning, Heyuan, Dongguan, Yunfu, Jieyang, Shenzhen, Huizhou and other places in Guangdong Province that are publicly available on Google Earth, select ≥18 level original image data, and convert the original image format into jpg; a total of 100 traditional village remote sensing images are obtained, of which 90 are used as training samples and the remaining 10 are used as test samples.
[0066] S2. Create a training set to build a damaged roof instance segmentation model: Use the training samples from the previous step to annotate the remote sensing images containing traditional village buildings to form a training set T, where the training set T contains two types of target objects. The first type of target object is labeled broken, corresponding to the damaged roof of traditional village buildings; the second type of target object is labeled non-broken, corresponding to the non-damaged roof of traditional village buildings. Use the training set T to train on the basis of the yolov8x-seg.pt pre-trained weight model to obtain the damaged roof instance segmentation model Posun_BEST.pt;
[0067] In the above step S2:
[0068] For the training set T: put the training samples in step S1 into the Labelme image annotation tool and use the polygon tool to annotate. The annotated target objects are divided into three categories. The first category is damaged buildings, and the corresponding label is broken; the second category is non-damaged buildings, and the corresponding label is non-broken. When annotating, it is necessary to pay attention to the number and position of the polygon key points. The number of key points of each image x = {x 1 , x 2 , x 3 …x n , n≥8}; each marked polygon represents a single building or a complete building group, covering the complete image information of the courtyard, patio, etc.
[0069] To obtain the damaged roof instance segmentation model Posun_BEST.pt:
[0070] (1) Custom configuration file: Customize the YOLOv8x network model data configuration file posun.yaml, set the number of categories nc to 2, and the segmentation category names names to broken and non-broken;
[0071] (2) Adjust parameters to optimize the model and obtain the model: put the set posun.yaml file into the configured computer; load the yolov8x-seg.pt pre-trained weight model to obtain better network model initialization parameters; load the training set T. The training iteration statement is adjusted to 300 generations and training is started. Repeat the training process to make YOLOv8 gradually converge; observe the training result data in real time, and save the optimal model Posun_BEST.pt after the training is completed. The training results are as follows Figure 3 shown.
[0072] S3, input the test sample to be segmented into the damaged roof instance segmentation model to obtain the instance segmentation result: input the picture in the test sample in step S1 into the damaged roof instance segmentation model Posun_BEST.pt for segmentation, and obtain the damaged roof and non-damaged roof instance segmentation results in each picture by calculation;
[0073] In the above step S3, the image in the test sample in step S1 is input into the model Posun_BEST.pt for calculation; each remote sensing image instance segmentation result is saved, wherein the result includes the target object type, the target object detection frame, and the target object mask contour. The coordinates of the key points of each target object mask contour on the image and the labels corresponding to the target object type are sequentially written into a txt document. A txt document contains one or more target objects of a remote sensing image instance segmentation result. This embodiment randomly selects one instance segmentation result image M to perform subsequent steps, such as Figure 4 ; A total of two objects are segmented from the image M, one is a non-broken target object type, and the other is a broken target object type. The coordinates of the key points of the mask contour of the image M on the image and the labels corresponding to the target object types are written into the document M_location.txt.
[0074] S4. Define the mask range of the damaged roof in the instance segmentation result to perform superpixel segmentation, and extract the superpixel sub-block image of a single damaged roof: Use the instance segmentation result of the previous step to extract the mask range of the damaged roof in each image one by one, perform superpixel segmentation within the mask range using the SLIC algorithm, obtain the clustered superpixel block, and extract the superpixel block as the sub-block image;
[0075] In the above step S4, the M_location.txt document generated in step S3 is used to return the coordinates of the key points of the mask contour of the broken target object type on the image M, and the pixel values inside the contour are converted to 1, and the pixel values outside the contour are converted to 0, so as to obtain the mask range of the broken roof in the instance segmentation result image M, as shown in FIG. Figure 5 , perform superpixel segmentation within the mask range; the superpixel segmentation method used is obtained from the network data configuration file maskSLIC, set the number of segmented sub-blocks n_segments to 100, set the boundary flatness compactness to 10, and obtain the superpixel segmentation result, such as Figure 6 , 91 super-pixel blocks are obtained by co-clustering within the mask range of image M; then the 91 super-pixel blocks are extracted one by one as sub-block images to form the test set d.
[0076] S5. Input the sub-block image into the trained SVM classifier: Use the sub-block image in the previous step and input it into the trained SVM classifier, wherein the classifier includes three target recognition categories, the first category is the sub-block image of the non-damaged area, with a label of 0; the second category is the sub-block image of the damaged area, with a label of 1; the third category is the sub-block image of the patio and courtyard area, with a label of 2; use the SVM classifier for recognition, and obtain the classification results of the three types of sub-block images: damaged area, non-damaged area, patio and courtyard area;
[0077] In the above step S5, the SVM classifier production process is as follows:
[0078] S51. Acquire a remote sensing image of a single building roof in a traditional village as an initial image. In this embodiment, a total of 20 remote sensing images of building roofs in traditional villages are acquired.
[0079] S52, using the SLIC algorithm to perform superpixel segmentation on all the above single building roof remote sensing images, a total of 756 sub-block images R = {R 1 ,R 2 ,R 3 ,R 4 ...R 756}, the sub-block images are divided into three categories, the first category is the non-damaged area, the corresponding label is 0, a total of 532 images; the second category is the damaged area, the corresponding label is 1, a total of 101 images; the third category is the patio and courtyard area, the corresponding label is 2, a total of 123 images. After manually screening the sub-block images, the sub-block image names and corresponding labels are written into the train_labels.txt file, normalized to 128px×100px size, as the training set D for the next step of training the SVM classifier;
[0080] S53, extract the color features and HOG features of each sub-block image in the training set D to form a combined feature vector, and then normalize the combined feature vector and input it into the SVM classifier. The color feature is the HSV color space feature; then extract the area of 128×100 pixels centered on the centroid for calculating the HOG feature, the cell size is set to 8×8 pixels, 12 direction blocks are extracted in the gradient direction, and a total of 31680 HOG features are generated for one sub-block image. In order to prevent smaller feature components from being ignored in the calculation, the two different types of feature quantities are normalized so that all components have the same weight in the feature description.
[0081] S54, inputting the combined feature vector into an SVM classifier for training, and obtaining an SVM classifier with optimized parameters.
[0082] Input 91 sub-block images in the test set d into the trained SVM classifier to determine the category of the sub-block images. A total of 6 damaged area sub-block images, i.e., sub-block images with a label of 1, 21 patio and courtyard area sub-block images, i.e., sub-block images with a label of 2, and 64 non-damaged area sub-block images, i.e., sub-block images with a label of 0, are detected. The combined feature vectors with labels of 0 and 2 in the recognition results are converted into a binary matrix with a pixel value of 0, and the combined feature vectors with a label of 1 in the recognition results are converted into a binary matrix with a pixel value of 1. A total of W binary matrices are obtained and reconstructed into binary images, as shown in FIG. Figure 7 ; Superimpose the binary image and the corresponding test sample image in step S1 to obtain a damaged area identification map, such as Figure 8 ; Zoom in on the recognition result and get Fig. 9 .
[0083] S6. Damage rate calculation: Using the classification result of the previous step, calculate the value of the ratio of the pixel points of the damaged area sub-block image of a single damaged roof to the sum of the pixel points of the damaged area and non-damaged area sub-block images. This value is the calculation result of the damage rate of a single building roof.
[0084] In the above step S6,
[0085] The breakage rate calculation formula is:
[0086]
[0087] Pixels 1 The sum of pixels representing the type of damaged area of a single building, that is, the sum of pixels of the sub-block image with label 1 in the recognition result; pixels 0 The sum of pixels representing the non-damaged area type of a single building; that is, the sum of pixels of the sub-block image with label 0 in the recognition result.
[0088] The pixel sum calculation procedure of each type of sub-block image is as follows: define the sub-block image name and the corresponding category label, traverse each sub-block image in the test set d, calculate the number of non-transparent pixels in the image and continue to accumulate them to the corresponding category, and obtain the pixel sum of each type. The calculation results of Example 1 show that the number of pixels in the 6 damaged area sub-block images is 2004, and the number of pixels in the 64 non-damaged area sub-block images is 23614. The damage rate of the damaged roof in image M is 7.82%.
[0089] Example 2
[0090] This embodiment discloses a method for identifying damage to the roof of a traditional village building and calculating the damage rate. The steps of the method for identifying damage to a damaged roof and calculating the damage rate are as follows:
[0091] S1, this step refers to step S1 in Example 1;
[0092] S2, this step refers to step S2 in Example 1;
[0093] S3, this step refers to step S3 in Example 1;
[0094] S4. Define the mask range of the damaged roof in the instance segmentation result to perform superpixel segmentation, and extract the superpixel sub-block image of a single damaged roof: Use the instance segmentation result of the previous step to extract the mask range of the damaged roof in each image one by one, perform superpixel segmentation within the mask range using the SLIC algorithm, obtain the clustered superpixel block, and extract the superpixel block as the sub-block image;
[0095] In the above step S4, the mask range of the damaged roof in the instance segmentation result image M of step S4 of embodiment 1 is used, such as Figure 5 , perform superpixel segmentation within the mask range, set the number of segmented sub-blocks n_segments to 60, set the boundary flatness compactness to 10, and obtain the superpixel segmentation result, as shown Fig.10 , 58 super-pixel blocks are obtained by co-clustering within the mask range of image M; then the 58 super-pixel blocks are extracted one by one as sub-block images to form the test set f.
[0096] S5. This step refers to step S5 in Example 1. The sub-block images in the test set f are input into the trained SVM classifier, and a total of 4 damaged area sub-block images, i.e., sub-block images with a label of 1, are detected; 10 patio and courtyard area sub-block images, i.e., sub-block images with a label of 2, and 44 non-damaged area sub-block images, i.e., sub-block images with a label of 0. The combined feature vectors with labels of 0 and 2 in the recognition result are converted into a binary matrix with a pixel value of 0, and the combined feature vectors with a label of 1 in the recognition result are converted into a binary matrix with a pixel value of 1, and a total of W binary matrices are obtained and reconstructed into a binary image; the binary image and the corresponding test sample image in step S1 are superimposed to obtain a damaged area recognition map, such as Fig.11 .
[0097] S6: This step refers to step S6 in Example 1 to obtain the calculation results of Example 2. The results show that the number of pixels in the 4 damaged area sub-block images is 2080, the number of pixels in the 44 non-damaged area sub-block images is 25652, and the damage rate of the damaged roof in image M is 7.50%.
[0098] The method of this embodiment is substantially the same as that of the embodiment 1 provided, and the main difference is that the number of sub-blocks n_segments in the original superpixel segmentation method is set from 100 to 60, thereby reducing the number of sub-block images that are clustered as superpixels. The calculation results of embodiment 1 and embodiment 2 are listed in Table 1. For the operation results of image M, the damage rate calculated by embodiment 1 is 7.82%, and the absolute value of the difference with the manually calculated damage rate (8.17%) is 0.35; the damage rate calculated by embodiment 1 is 7.50%, and the absolute value of the difference with the manually calculated damage rate (8.17%) is 0.37. From the data, the operation of embodiment 1 is better than that of embodiment 2.
[0099] Table 1. Data comparison table of different embodiments
[0100]
[0101]
[0102] The number of superpixel sub-blocks will affect the image segmentation accuracy and computational efficiency. A smaller number of superpixels will result in a segmentation result that is too rough and cannot accurately represent the detailed information in the image; a larger number of superpixels will increase the complexity of the computation and slow down the algorithm. Since Example 2 reduces the number of superpixel sub-blocks, although the difference between the damage rate calculation result and the manually calculated damage rate result is relatively small, by comparing Example 1 with the manually annotated image M's damaged area ( Fig.12 ), it is found that Example 2 incorrectly judges the location of the damaged area of the building roof in actual recognition, which is far from the actual damaged area of the building roof. In Example 2, due to the small number of superpixel sub-blocks set, the boundaries of the generated sub-block patterns become blurred, and some sub-block images contain both pixel points of the damaged area and pixel points of the non-damaged area, which will cause incorrect judgments when the program performs recognition.
[0103] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.
Claims
1. A method for identifying damage to roofs of traditional village buildings and calculating damage rates, characterized in that: The roof damage identification and damage rate calculation method comprises the following steps: S1. Obtaining remote sensing images of traditional villages: using satellite remote sensing images as the basic image source, downloading remote sensing images of traditional villages; dividing the remote sensing images into training samples and test samples according to proportion; S2. Create a training set to construct a damaged roof instance segmentation model: Use the training samples to annotate remote sensing images containing traditional village buildings to form a training set T, wherein the training set T contains two types of target objects. The first type of target object is labeled as broken, corresponding to the damaged roof of traditional village buildings; the second type of target object is labeled as non-broken, corresponding to the non-damaged roof of traditional village buildings. Use the training set T to train on the yolov8x-seg.pt pre-trained weight model to obtain the damaged roof instance segmentation model Posun_BEST.pt; S3, input the test sample to be segmented into the damaged roof instance segmentation model to obtain the instance segmentation result: input the picture in the test sample into the damaged roof instance segmentation model Posun_BEST.pt for segmentation, and calculate the damaged roof and non-damaged roof instance segmentation results in each picture; S4. Define the mask range of the damaged roof in the instance segmentation result to perform superpixel segmentation, and extract the superpixel sub-block image of a single damaged roof: Use the instance segmentation result to extract the mask range Mask of the damaged roof in each image one by one, perform superpixel segmentation within the mask range using the SLIC algorithm, obtain clustered superpixel blocks, extract the superpixel blocks as sub-block images, and constitute the test set d; S5, input the sub-block image into the trained SVM classifier to obtain classification results of three types of sub-block images: damaged area, non-damaged area, and patio and courtyard area; wherein the SVM classifier includes three target recognition categories, the first category is the sub-block image of the non-damaged area, with a label of 0; the second category is the sub-block image of the damaged area, with a label of 1; the third category is the sub-block image of the patio and courtyard area, with a label of 2; S6. Damage rate calculation: The ratio of the pixel points of the damaged area sub-block image of a single damaged roof to the sum of the pixel points of the damaged area and non-damaged area sub-block images is calculated according to the classification result. This value is the calculation result of the damage rate of a single building roof.
2. A method for identifying damage to roofs of traditional village buildings and calculating damage rates according to claim 1, characterized in that: In the step S2, the training samples are labeled by using the Labelme image labeling tool to form a training set T.
3. The method for identifying damage to the roof of a traditional village building and calculating the damage rate according to claim 1 is characterized in that: The training and acquisition process of the damaged roof instance segmentation model Posun_BEST.pt in step S2 includes: setting the initial parameters of the YOLOv8x network data configuration file and inputting the YOLOv8x network model, using the pre-trained weights of yolov8x-seg.pt, training the iteration number of 300 generations, and finally obtaining the damaged roof instance segmentation model Posun_BEST.pt.
4. The method for identifying damage to the roof of a traditional village building and calculating the damage rate according to claim 1 is characterized in that: In the step S3, the test sample is input into the damaged roof instance segmentation model Posun_BEST.pt for calculation, and the instance segmentation result of each remote sensing image is saved, wherein the result includes the target object type, the target object detection frame, and the target object mask contour. The coordinates of the key points of each target object mask contour on the image and the labels corresponding to the target object type are sequentially written into a txt document. A txt document contains one or more target objects of the instance segmentation result of a remote sensing image.
5. A method for identifying damage to roofs of traditional village buildings and calculating damage rates according to claim 4, characterized in that: In the step S4, the target object type with label 1 is extracted from the txt document of step S3, and the coordinates of the key points of the mask contour corresponding to the target object type are returned to the remote sensing image to generate a damaged roof mask range image in png format.
6. A method for identifying damage to the roof of a traditional village building and calculating the damage rate according to claim 5, characterized in that: In step S4, superpixel segmentation is performed within the mask range by using the SLIC algorithm, the number of segmented superpixel blocks n_segments is 100, the boundary flatness compactness is set to 10, and after optimizing the parameters, the segmented superpixel blocks are extracted as sub-block images.
7. A method for identifying damage to roofs of traditional village buildings and calculating damage rates according to claim 1, characterized in that: The process of making the SVM classifier in step S5 includes: obtaining a remote sensing image of a single building roof in a traditional village, where each building roof should include a damaged area and a non-damaged area; using the SLIC algorithm to segment the building roof to obtain different sub-block images R = {R1, R2, R3, ... R n }, normalize the sub-block image size, extract the color features and HOG features of the sub-block image to construct a combined feature vector, and produce a SVM classifier.
8. The method for identifying damage to the roof of a traditional village building and calculating the damage rate according to claim 1, characterized in that: In step S5, the sub-block image is input into the trained SVM classifier, the image name and the corresponding recognition result label are written into the results.txt document, and the recognition result r of each sub-block image is obtained; the combined feature vectors with labels 0 and 2 in the recognition result r are converted into a binary matrix with a pixel value of 0, and the combined feature vectors with a label 1 in the recognition result are converted into a binary matrix with a pixel value of 1, and a total of W binary matrices are obtained and reconstructed into a binary image, and the binary image and the image in the test sample are superimposed to obtain a damaged area recognition image.
9. The method for identifying damage to the roof of a traditional village building and calculating the damage rate according to claim 1, characterized in that: The breakage rate calculation formula in step S6 is: Among them, pixels1 represents the sum of the pixels of the sub-block image of the damaged area in a single damaged roof, and pixels0 represents the sum of the pixels of the sub-block image of the non-damaged area in a single damaged roof.
10. The method for identifying damage to the roof of a traditional village building and calculating the damage rate according to claim 1, characterized in that: In step S6, the calculation process of the pixel sum of each type of sub-block image is as follows: define the sub-block image name and the corresponding category label, traverse each sub-block image in the test set d, calculate the number of non-transparent pixels in the image and continue to accumulate them to the corresponding category, and obtain the pixel sum of each type.
