A building roof contour extraction method and device, electronic equipment and storage medium
By employing a locally oriented convergent matching mechanism driven by global geometric prior knowledge, combined with normalized cross-correlation similarity measurement and morphological processing, the problem of incomplete extraction and misidentification of urban building cluster outlines is solved, achieving accurate and rapid extraction in complex environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN SCIENCE & TECHNOLOGY INSTITUTE OF URBAN SAFETY DEVELOPMENT
- Filing Date
- 2026-05-25
- Publication Date
- 2026-08-04
AI Technical Summary
Traditional methods often fail to extract complete building outlines in high-density, high-floor-ratio urban building complexes and are prone to misidentification. They are also severely affected by factors such as lighting and climate, resulting in limited accuracy.
A local directional convergence matching mechanism driven by global geometric prior knowledge is adopted. Template matching is performed through normalized cross-correlation similarity metric. Combined with Euclidean distance transformation and morphological dilation, the outline of the building roof is refined and the search range is dynamically narrowed to reduce the probability of mismatch.
It enables accurate and rapid batch extraction of building roof outlines in complex urban scenarios, enhances the algorithm's anti-interference capabilities and accuracy, and adapts to multiple seasons and lighting conditions.
Smart Images

Figure CN122265850B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of building outline extraction technology, specifically to a method, apparatus, electronic device, and storage medium for extracting the outline of a building roof. Background Technology
[0002] Currently, existing buildings in cities are generally characterized by high density and high floor area ratio, with significant differences in individual building sizes and irregular shapes, resulting in complex spatial layouts and topological relationships within building complexes, and severe mutual occlusion and interference between buildings. As a result, the accuracy of traditional image segmentation methods is limited, and problems such as incomplete building contour extraction and misidentification of targets easily occur. Summary of the Invention
[0003] This invention provides a method, apparatus, electronic device, and storage medium for extracting the outline of a building roof, in order to solve the problems of incomplete outline extraction or misidentification in traditional technologies.
[0004] In a first aspect, the present invention provides a method for extracting the outline of a building roof, the method comprising: Acquire optical remote sensing images and vector maps of the target building complex; extract building boundaries from the optical remote sensing images; and extract building vector boxes from the vector maps. Within a predefined initial search space, a global search is performed using a normalized cross-correlation similarity metric, template matching is conducted, and the building roof outline is initially located. Calculate the global offset main direction angle, set the angle tolerance, generate a fan-shaped search space with the global offset main direction angle as the central axis and the angle tolerance as the half width. Within the fan-shaped search space, perform local optimization using the normalized cross-correlation similarity metric, perform template matching, iterate the angle tolerance, converge the fan-shaped search space, repeat template matching, and obtain the final building roof outline.
[0005] This invention extracts building boundaries and building vector frames, performs hierarchical matching from global search to local optimization, uses normalized cross-correlation similarity metric for template matching, completes the initial positioning of the building roof, reduces unnecessary search areas, performs refined matching in a sector-shaped search space, dynamically converges the search range, and achieves complete and accurate extraction of the building roof outline.
[0006] In one alternative implementation, the initial search space is determined as follows: Based on the building vector frame, expand the buffer to obtain a rectangular area; Calculate the intersection area between the building vector frame and the candidate building boundaries within the rectangular area, identify building boundaries that meet the overlap requirements as target objects, and determine the outline range of the target objects as the initial search space.
[0007] This invention filters target objects and determines the initial search space by the intersection area of the building vector frame and the candidate building boundary within the rectangular area. This focuses the search range on the area strongly related to the target building group, reducing interference from other buildings and lowering the probability of false matches.
[0008] In one alternative implementation, after extracting building boundaries from optical remote sensing imagery and building vector boxes from a vector map, the method further includes: The outline of the building boundary and building vector frame is optimized by using Euclidean distance transformation and morphological dilation.
[0009] This invention optimizes the contours by using Euclidean distance transformation and morphological dilation, resulting in smoother edges of building boundaries and building vector frames.
[0010] In one optional implementation, within a predefined initial search space, a global search is performed using a normalized cross-correlation similarity metric to perform template matching and initially locate the building roof outline, including: Calculate the average gray value of the search domain image in the area covered by the template image, and the average gray value of the template image, respectively. The search domain image and the template image are both zero-mean processed. Calculate the normalized cross-correlation coefficients between the search domain image and the template image; Select the target location with the highest cross-correlation coefficient, and determine the area corresponding to the target location as the preliminary positioning result of the building roof outline.
[0011] This invention calculates the average grayscale value of the search domain image and the template image, and then performs zero-mean processing to effectively offset the brightness deviation caused by changes in illumination and atmospheric effects. It uses the magnitude of the normalized cross-correlation coefficient to select the target position and initially locate the outline of the building roof, thus avoiding the positioning error of traditional matching methods.
[0012] In one optional implementation, calculating the global offset principal direction angle includes: Calculate the offset vector, which is used to characterize the spatial offset relationship between the building boundary and the building vector frame; The offset vector is converted into a direction angle using the four-quadrant arctangent function, thus obtaining the offset direction angle; The offset direction angle is normalized. The global offset principal direction angle is calculated using the interquartile range truncated mean method.
[0013] This invention quantifies the spatial offset relationship between the building boundary and the building vector frame, and then uses the four-quadrant arctangent function to quantify the offset direction angle, eliminates angle deviation, and statistically analyzes the global offset main direction angle, providing directional basis for the sector search space in the local optimization stage.
[0014] In one optional implementation, the global offset principal direction angle is calculated using the interquartile range truncated mean method, including: Sort all sets of offset principal direction angles in ascending order to obtain an ordered sequence; Determine the previous and next indexes of the valid samples, and remove extreme values; Extract samples from the next and previous indices of the ordered sequence to obtain an effective subset; The arithmetic mean of the effective subset is used to obtain the global offset principal direction angle.
[0015] This invention obtains the global offset principal direction angle by calculating the arithmetic mean of the effective subset obtained from the index of the ordered sequence, thereby reducing the interference of abnormal data in subsequent local optimization.
[0016] In one alternative implementation, the method further includes: The offset angle is recalculated, the global offset main direction angle is updated, the angle tolerance is reduced, the sector search space is updated, and the final building roof outline is optimized.
[0017] This invention recalculates the offset angle, updates the global offset main direction angle, reduces the angle tolerance, adapts to the changes in each round of matching results in real time, dynamically corrects the direction deviation, and improves the contour extraction accuracy.
[0018] In a second aspect, the present invention provides a building roof contour extraction device, the device comprising: The acquisition module is used to acquire optical remote sensing images and vector maps of the target building complex, extract building boundaries from the optical remote sensing images, and extract building vector boxes from the vector maps. The global search module is used to perform a global search within a predefined initial search space using a normalized cross-correlation similarity metric, perform template matching, and initially locate the outline of the building roof. The local optimization module is used to calculate the global offset main direction angle, set the angle tolerance, and generate a fan-shaped search space with the global offset main direction angle as the central axis and the angle tolerance as the half width. Within the fan-shaped search space, local optimization is performed using the normalized cross-correlation similarity metric, template matching is performed, the angle tolerance is iterated, the fan-shaped search space is converged, and template matching is repeated to obtain the final building roof outline.
[0019] Thirdly, the present invention provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the building roof outline extraction method described in the first aspect or any corresponding embodiment.
[0020] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to perform the building roof outline extraction method described in the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0021] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0022] Figure 1 This is a schematic flowchart of a method for extracting the outline of a building roof according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the global search process according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the initial search space setting according to an embodiment of the present invention; Figure 4 This is a schematic diagram of template matching according to an embodiment of the present invention; Figure 5 This is a schematic diagram of a globally consistent optimal solution according to an embodiment of the present invention; Figure 6 This is a schematic diagram of a local optimization process according to an embodiment of the present invention; Figure 7 This is a schematic diagram of the building boundary and building vector frame extraction results according to an embodiment of the present invention; Figure 8 This is a schematic diagram of the global search main offset direction and abnormal matching pair extraction results according to an embodiment of the present invention; Figure 9 This is a schematic diagram of the local optimization result of the building top profile according to an embodiment of the present invention; Figure 10 This is a structural block diagram of a building roof contour extraction device according to an embodiment of the present invention; Figure 11 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0024] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.
[0025] Because the boundaries of existing buildings are often blurred in images, the outlines of different buildings often appear "stuck" in the extraction results, making it difficult to separate individual buildings. In addition, optical satellite remote sensing is affected by factors such as lighting conditions, atmospheric effects, and sensor differences, which further increase the uncertainty and complexity of image interpretation.
[0026] This invention provides a method for extracting building roof contours. It constructs a local directional convergence matching mechanism driven by global geometric prior knowledge. In the global search phase, a normalized cross-correlation similarity metric is used to perform rapid template matching between vector data and remote sensing imagery within the initial search space, completing the preliminary localization of the building roof contours. This significantly reduces unnecessary search areas and identifies and handles abnormal matches in advance. In the local optimization phase, the offset vectors of all building contours are statistically analyzed using the preliminary localization results, and the principal offset direction angle is calculated to establish global geometric prior knowledge. Based on the principal offset direction angle, a directional fan-shaped search space is constructed for refined matching. By gradually reducing the angle tolerance and adjusting the principal offset direction angle, the search range is dynamically converged. This eliminates matching ambiguity and significantly enhances the algorithm's resistance to interference from heterogeneous sensor data and external conditions such as lighting / season, achieving accurate and rapid batch extraction of building roof contours in complex urban scenes.
[0027] First, the proper nouns appearing in the embodiments of this invention will be explained: Template matching is a method for finding the best matching position of a template image within a reference image. This method involves iterating through a sliding window, calculating the similarity between the template image and the area covered by each window in the reference image, and selecting the window position with the highest similarity as the best matching result. In this invention, a building vector frame is used as the template image, and an optical remote sensing image is used as the reference image. Simultaneously, a pre-defined search area in the reference image is used as the search domain. The algorithm performs the matching operation within this search domain. Search space: During template matching, the pre-defined search domain in the reference image for each individual building; Angular tolerance: During the local optimization matching process, the allowable deviation range set around the main offset direction angle is used to define the half-angle width of the sector search area.
[0028] According to an embodiment of the present invention, a method for extracting the outline of a building roof is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0029] This embodiment provides a method for extracting the outline of a building roof. Figure 1 This is a flowchart of a method for extracting the outline of a building roof according to an embodiment of the present invention, as shown below. Figure 1 As shown, the process includes the following steps: Step S101: Obtain optical remote sensing images and vector maps of the target building complex, extract building boundaries from the optical remote sensing images, and extract building vector boxes from the vector maps.
[0030] In embodiments of the present invention, such as Figure 2 As shown, the target building group is the complex of buildings whose outlines are to be extracted. Optical remote sensing images of the target building group are acquired, and building boundaries are extracted from the optical remote sensing images. For complex scenes with multiple types of buildings at the city level, a panoramic segmentation model (Segment Anything Model, SAM) is used to extract building boundaries. A vector map of the target building group is obtained through a geographic information public service platform or industry data, and the bottom vectors of the buildings are extracted from the vector map to form the building vector boxes.
[0031] It should be noted that when the optical image quality is poor, the accuracy of boundary extraction using SAM has certain limitations. Therefore, edge detection algorithms based on traditional machine vision are adopted as an alternative. Operators such as Canny and Sobel are used to achieve more stable building boundary feature extraction under complex background interference.
[0032] It should be noted that, in order to ensure the spatial consistency of the two types of data, optical remote sensing imagery and vector map, they are unified to the same spatial coordinate reference system. The building vector frame is converted into raster data with the same spatial resolution as the optical remote sensing imagery, and rasterization is performed. The center point method is used to assign the pixel covered by the polygon to "1" and the background to "0", generating a binary image.
[0033] Step S102: Within the predefined initial search space, a global search is performed using a normalized cross-correlation similarity metric to perform template matching and initially locate the building roof outline.
[0034] In this embodiment of the invention, during the global search phase, an initial search space is defined for each building. Within the initial search space, a global search is performed using a normalized cross-correlation similarity metric to perform template matching, find the best matching position of the building's vector frame, and initially locate the building's roof outline.
[0035] Step S103: Calculate the global offset main direction angle, set the angle tolerance, generate a fan-shaped search space with the global offset main direction angle as the central axis and the angle tolerance as the half width, perform local optimization in the fan-shaped search space using the normalized cross-correlation similarity metric, perform template matching, iterate the angle tolerance, converge the fan-shaped search space, repeat the template matching, and obtain the final building roof outline.
[0036] In this embodiment of the invention, a principal orientation angle is calculated, an angle tolerance is set, and a fan-shaped search space is generated with the principal orientation angle as the central axis and the angle tolerance as the half-width. Template matching is strictly limited to a high-probability region consistent with the global offset principal orientation angle. Within the fan-shaped search space, local optimization is performed using a normalized cross-correlation similarity metric, template matching is performed, the angle tolerance is iterated, the fan-shaped search space is converged, and template matching is repeated to obtain the final building roof outline.
[0037] The building roof outline extraction method provided in this embodiment extracts the building boundary and building vector frame, performs hierarchical matching from global search to local optimization, uses normalized cross-correlation similarity metric for template matching, completes the initial positioning of the building roof, reduces unnecessary search areas, performs fine matching in the fan-shaped search space, dynamically converges the search range, and achieves complete and accurate extraction of the building roof outline.
[0038] This embodiment provides a method for extracting the outline of a building roof. The process includes the following steps: Step S301: Obtain optical remote sensing images and vector maps of the target building complex, extract building boundaries from the optical remote sensing images, and extract building vector boxes from the vector maps.
[0039] Please see details Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0040] In some alternative implementations, the method further includes: Step S302: Use Euclidean distance transformation and morphological dilation to optimize the outline of the building boundary and building vector frame.
[0041] In this embodiment of the invention, the SAM model typically outputs a probability map, which converts the building boundary probabilities into binary images. Euclidean distance transformation and morphological dilation are then applied to the binary images of the building boundaries and building vector boxes for contour optimization.
[0042] Specifically, distance transformation, as an image transformation algorithm, describes the distance between a pixel and a region in an image, converting a binary image into a distance image, i.e., a grayscale image, which is used for target thinning, skeleton extraction, shape interpolation and matching, separation of adhered objects, etc.
[0043] Using Euclidean distance transformation, assume a binary image I, where the background pixels (value 0) have a point set B, and the foreground pixels (value 1) have a point set F.
[0044] For any foreground pixel in the image Its Euclidean distance transformation value Defined as the distance from this point to all background pixels. The minimum Euclidean distance:
[0045] in, This represents the Euclidean distance transformation value. Foreground pixels, Let B be the background pixel, and let B be the set of background pixels.
[0046] Specifically, morphological dilation is an optimization operation that expands the foreground and enhances features of a building's outline. It involves sliding a structuring element (such as a 5x5 polygon) across the image to enlarge the foreground edges. This is applicable to grayscale images after distance transformation. and structural elements The dilation operation calculates the maximum sum of pixel values and the structuring element within the area covered by the structuring element.
[0047] in, This is the pixel value at coordinates (x, y) of the output image after the dilation operation. Let f be the pixel value at coordinates (xu, yv) of the original input image f after translation (u, v). Let B be the pixel value of the structuring element at its own coordinates (u, v), and let B be the neighborhood defined by the structuring element b.
[0048] By filtering target objects based on the intersection area of the building vector frame and the candidate building boundary within the rectangular area, the initial search space is determined, focusing the search range on areas strongly related to the target building group, reducing interference from other buildings, and lowering the probability of false matches.
[0049] Step S303: Within the predefined initial search space, a global search is performed using a normalized cross-correlation similarity metric to perform template matching and initially locate the outline of the building roof.
[0050] Specifically, the initial search space in step S303 above is determined as follows: Step Sa involves using Euclidean distance transformation and morphological dilation to optimize the outline of the building boundary and building vector frame.
[0051] In this embodiment of the invention, during the global search phase, it is necessary to define an initial search space for each building.
[0052] First, such as Figure 3 As shown, based on the building vector frame of each building, a buffer of fixed width is extended outward to define an initial rectangular region within the image. Subsequently, by calculating the intersection area between the building vector frame and all candidate building boundaries extracted by SAM within the rectangular region, the building boundary with the highest overlap is accurately identified as the target object, and the outline range of the target object is used as the initial search space for each building.
[0053] By utilizing Euclidean distance transformation and morphological dilation, contour optimization is performed, resulting in smoother edges of building boundaries and building vector frames.
[0054] Specifically, step S303 includes: Step S3031: Calculate the average gray value of the search domain image in the area covered by the template image and the average gray value of the template image, respectively. Step S3032: Perform zero-mean processing on the search domain image and the template image respectively; Step S3033: Calculate the normalized cross-correlation coefficient between the search domain image and the template image; Step S3034: Select the target location with the largest cross-correlation coefficient and determine the area corresponding to the target location as the preliminary positioning result of the building roof outline.
[0055] In this embodiment of the invention, template matching is performed using a normalized cross-correlation metric within the initial search space to find the optimal matching position of the building vector frame.
[0056] Normalized cross-correlation is a gray-level-based template matching method used to locate the region in a search image that is most similar to a template image. It evaluates similarity by calculating the normalized cross-correlation coefficient and exhibits some robustness to changes in illumination. Figure 4 As shown, the template slides along the horizontal and vertical directions within the search domain. For each translation position... Calculate the normalized cross-correlation coefficient corresponding to this position. Finally, the position with the largest coefficient is selected as the best matching result. The specific calculation process is as follows: Let the search domain reference image be The template image is The template size is At each location to be evaluated First, calculate the average gray value of the search domain image in the template coverage area. and the average gray value of the template image. :
[0057]
[0058] in, The average gray value of the search domain reference image within the template coverage area. The average grayscale value of the template image; For the search domain reference image The pixel value represents the position. Based on, offset The pixel value after that, template image In coordinates The pixel value at that location, where and These are the offsets of the template in the horizontal and vertical directions, respectively. m and n are the number of rows and columns of the template.
[0059] The search domain reference image and template image are respectively zero-mean processed, that is, their respective mean values are subtracted to eliminate the influence of the overall brightness deviation.
[0060] Based on this, the normalized cross-correlation coefficient between the search domain image and the template image is calculated. :
[0061] The variance term introduced in the denominator of this formula is used to normalize the cross-correlation coefficients, making... The value of falls within the interval [-1, 1], thus enabling a consistent measurement of similarity. When When the value approaches 1, it indicates that the image region at that location is highly similar to the template; conversely, when it approaches -1, it indicates that the regions are highly dissimilar.
[0062] By traversing all possible translation positions within the search image Then, the best matching position Determined by the following formula:
[0063] in, For the best matching position, The translation position is the position to be shifted during the traversal.
[0064] By calculating the average grayscale value of the search domain image and the template image, and then performing zero-mean processing, the brightness deviation caused by changes in illumination and atmospheric effects is effectively offset. The target position is selected by using the magnitude of the normalized cross-correlation coefficient, and the outline of the building roof is initially located, avoiding the positioning error of traditional matching methods.
[0065] Step S304: Calculate the global offset main direction angle, set the angle tolerance, generate a fan-shaped search space with the global offset main direction angle as the central axis and the angle tolerance as the half width, perform local optimization using the normalized cross-correlation similarity metric within the fan-shaped search space, perform template matching, iterate the angle tolerance, converge the fan-shaped search space, repeat template matching, and obtain the final building roof outline.
[0066] Specifically, calculating the global offset principal direction angle in step S304 above includes: Step S3041: Calculate the offset vector, which is used to characterize the spatial offset relationship between the building boundary and the building vector frame; Step S3042: The offset vector is converted into a direction angle using the four-quadrant arctangent function to obtain the offset direction angle; Step S3043: Normalize the offset direction angle; Step S3044: The global offset principal direction angle is calculated using the interquartile range truncated mean method.
[0067] In this embodiment of the invention, the spatial offset relationship between the building boundary and the building vector frame is calculated using the offset vector. Representation, defining the center coordinates of the building vector frame as The coordinates of the center of the target building complex boundary are Then the offset vector for:
[0068] Offset direction angle quantization uses the four-quadrant arctangent function to convert the two-dimensional offset vector into a direction angle. With the top-left corner of the image as the origin, the x-axis points horizontally to the right, and the y-axis points vertically downwards. The offset direction angle is then calculated. The calculation formula is:
[0069] in, This is a minimum value to avoid calculation errors when dx=0.
[0070] Offset direction angle normalization processing, building vector frame direction angle and building boundary direction angle Deviation between The periodic ambiguity in the circumferential direction is eliminated through normalization:
[0071]
[0072] After normalization The range of values is It directly reflects the degree of offset between the building boundary and the building vector frame.
[0073] Global offset direction angle statistics are performed using the interquartile range truncated mean method to calculate the global offset main direction angle. By removing extreme outliers (the first 25% and the last 25%), the central tendency of the middle 50% of valid samples is retained.
[0074] By quantifying the spatial offset relationship between the building boundary and the building vector frame, and then using the four-quadrant arctangent function to quantify the offset direction angle, the angle deviation is eliminated, and the global offset main direction angle is statistically analyzed, providing directional basis for the sector search space in the local optimization stage.
[0075] Specifically, step S3044 includes: Step S30441: Sort all sets of offset principal direction angles in ascending order to obtain an ordered sequence; Step S30442: Determine the previous and next indexes of the valid samples and remove extreme values; Step S30443: Extract samples of the next and previous indices from the ordered sequence to obtain an effective subset; Step S30444: Calculate the arithmetic mean of the effective subset to obtain the global offset principal direction angle.
[0076] In this embodiment of the invention, the samples are first sorted, and the normalized offset direction angle set of all building boundaries and building vector frames within the image is then processed. Sort in ascending order to obtain an ordered sequence: , where N is the number of samples.
[0077] Then, the truncation index is calculated, and the upper and lower bound indices of the effective samples are determined according to the following formula to remove extreme values.
[0078]
[0079] Where L is the lower bound index and U is the upper bound index.
[0080] Then, an effective subset is constructed by extracting samples from indices L to U in the ordered sequence. : .
[0081] Finally, the global offset principal direction angle is calculated, and the effective subset is... The arithmetic mean is used to obtain the global offset direction angle, as shown below:
[0082] in, The number of samples in the effective subset. It reflects the overall offset trend between the building boundaries and the building vector frame within the area.
[0083] By obtaining the effective subset from the index of the ordered sequence, and calculating the arithmetic mean, the global offset principal direction angle is obtained, reducing the interference of abnormal data in subsequent local optimization.
[0084] In some alternative implementations, the method further includes: Step S305: Recalculate the offset angle, update the global offset main direction angle, reduce the angle tolerance, update the sector search space, and optimize the final building roof outline.
[0085] In embodiments of the present invention, such as Figure 5 As shown, based on the matching results of this round, the offset angles of all buildings are recalculated, and the global offset principal direction angle is updated. Simultaneously, the angle tolerance is gradually reduced, causing the sector search space to converge round by round. Figure 6 As shown, when the main direction angle tends to stabilize, the matching positions of all buildings continuously converge to a high-precision and globally consistent optimal solution.
[0086] By recalculating the offset angle and updating the global offset main direction angle, the angle tolerance is reduced to adapt to the changes in the matching results of each round in real time, dynamically correct the direction deviation, and improve the contour extraction accuracy.
[0087] The building roof contour extraction method provided in this embodiment addresses the challenges of complex spatial layouts and topological relationships in urban building clusters, and the susceptibility of optical remote sensing images to interference from seasonal changes, illumination variations, and shadow occlusion. Traditional image segmentation methods generally suffer from technical bottlenecks such as blurred building boundaries, poor contour continuity, and insufficient algorithm robustness. To overcome these limitations, this invention proposes a novel automatic method for extracting building roof contours in complex urban scenarios. This method can accurately and rapidly extract roof contours of urban building clusters characterized by "narrowness, density, and disorder" in complex environments with multiple seasons, angles, and illumination conditions.
[0088] As one or more specific application embodiments of the present invention, taking a community in City S as the research object, based on two high-resolution optical remote sensing images from April 30, 2010 and November 24, 2020, the roof outline extraction work was carried out, and the specific implementation results are as follows: First, remote sensing data preprocessing is performed, including radiometric calibration, atmospheric correction, orthorectification, and image fusion. Then, SAM (Search Engine Awareness System) unguided panoramic segmentation is performed on the preprocessed image, initially outputting all building boundaries. Building vector box data utilizes existing building baseline data from relevant industry authorities. The result of overlaying both is shown below. Figure 7 As shown, the green outline represents the building boundary, and the red outline represents the building vector frame.
[0089] Then, within the initial search area of each building, a template matching method based on normalized cross-correlation is used for global search and global offset direction is calculated. The global offset direction in this round is 119.52º. Figure 8 As shown, the green arrows indicate the global offset main direction, the green boxes indicate matching pairs that conform to the global offset main direction, the red arrows indicate non-offset main directions, and the red boxes indicate abnormal matching pairs.
[0090] After a global search, main direction constraints and angle tolerances are set. Following local optimization matching, the final matching result is as follows: Figure 9 As shown. After manual verification, the roof outlines of the houses in this area were 100% accurately extracted. The robustness of this method was tested using two optical remote sensing images with different seasons, light intensities, and shooting angles.
[0091] This embodiment also provides a building roof outline extraction device, which is used to implement the above embodiments and preferred embodiments, and will not be repeated as already described. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0092] This embodiment provides a device for extracting the outline of a building roof, such as... Figure 10 As shown, it includes: The acquisition module 1001 is used to acquire optical remote sensing images and vector maps of the target building complex, extract building boundaries from the optical remote sensing images, and extract building vector boxes from the vector maps. The global search module 1002 is used to perform a global search within a predefined initial search space using a normalized cross-correlation similarity metric, perform template matching, and initially locate the outline of the building roof. The local optimization module 1003 is used to calculate the global offset main direction angle, set the angle tolerance, generate a fan-shaped search space with the global offset main direction angle as the central axis and the angle tolerance as the half width, perform local optimization using normalized cross-correlation similarity metric within the fan-shaped search space, perform template matching, iterate the angle tolerance, converge the fan-shaped search space, repeat template matching, and obtain the final building roof outline.
[0093] In some alternative implementations, the global search module 1002 includes: The extended unit is used to expand the buffer based on the building vector frame to obtain a rectangular area; The initial search space determination unit is used to calculate the intersection area between the building vector frame and the candidate building boundaries within the rectangular area, identify building boundaries that meet the overlap requirements as target objects, and determine the outline range of the target objects as the initial search space.
[0094] In some alternative embodiments, the device further includes: The contour optimization module is used to optimize the contours of building boundaries and building vector frames using Euclidean distance transformation and morphological dilation.
[0095] In some alternative implementations, the global search module 1002 includes: The first calculation unit is used to calculate the average gray value of the search domain image in the area covered by the template image and the average gray value of the template image, respectively. The zero-mean processing unit is used to perform zero-mean processing on the search domain image and the template image respectively; The second calculation unit is used to calculate the normalized cross-correlation coefficient between the search domain image and the template image; The preliminary positioning unit is used to select the target location with the largest cross-correlation coefficient and determine the area corresponding to the target location as the preliminary positioning result of the building roof outline.
[0096] In some optional implementations, the local optimization module 1003 includes: The third calculation unit is used to calculate the offset vector, which is used to characterize the spatial offset relationship between the building boundary and the building vector frame. The conversion unit is used to convert the offset vector into a direction angle using the four-quadrant arctangent function, thus obtaining the offset direction angle. The normalization unit is used to normalize the offset direction angle; The statistical unit is used to calculate the global offset principal direction angle using the interquartile range truncated mean method.
[0097] In some alternative implementations, the third computing unit includes: The sorting subunit is used to sort all sets of offset principal direction angles in ascending order to obtain an ordered sequence. Eliminate sub-units to determine the upper and lower indices of valid samples and remove extreme values; Extracting sub-units is used to extract samples of the next and previous indices in an ordered sequence to obtain an effective subset; The arithmetic mean calculation subunit is used to extract samples from the next and previous indices of an ordered sequence to obtain an effective subset.
[0098] In some alternative embodiments, the device further includes: The update module is used to recalculate the offset angle, update the global offset main direction angle, reduce the angle tolerance, update the sector search space, and optimize the final building roof outline.
[0099] The building roof contour extraction device provided in this embodiment of the invention can execute the building roof contour extraction method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method. Further functional descriptions of the above modules and units are the same as in the corresponding embodiments described above, and will not be repeated here.
[0100] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.
[0101] The following is a detailed reference. Figure 11 The diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, a graphics processing unit, etc.) 1101, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1102 or a program loaded from memory 1108 into random access memory (RAM) 1103. The RAM 1103 also stores various programs and data required for the operation of the electronic device. The processor 1101, ROM 1102, and RAM 1103 are interconnected via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0102] Typically, the following devices can be connected to I / O interface 1105: input devices 1106 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 1107 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 1108 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1109. Communication device 1109 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 11Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.
[0103] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 1109, or installed from a memory 1108, or installed from a ROM 1102. When the computer program is executed by the processor 1101, it performs the functions defined in the building roof contour extraction method of the embodiments of the present invention.
[0104] Figure 11 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0105] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the building roof contour extraction method shown in the above embodiments is implemented.
[0106] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0107] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and all such modifications and variations fall within the scope defined by the appended invention.
Claims
1. A method for extracting the outline of a building roof, characterized in that, The method includes: Acquire optical remote sensing images and vector maps of the target building complex, extract building boundaries from the optical remote sensing images, and extract building vector boxes from the vector maps; Within a predefined initial search space, a global search is performed using a normalized cross-correlation similarity metric, followed by template matching to initially locate the building roof outline. This includes: calculating the average gray value of the search domain image within the area covered by the template image, and the average gray value of the template image; performing zero-mean processing on both the search domain image and the template image; calculating the normalized cross-correlation coefficient between the search domain image and the template image; selecting the target location with the highest cross-correlation coefficient, and determining the region corresponding to the target location as the initial location result of the building roof outline. Calculate the global offset main direction angle, set the angle tolerance, and generate a fan-shaped search space with the global offset main direction angle as the central axis and the angle tolerance as the half width. Within the fan-shaped search space, perform local optimization using the normalized cross-correlation similarity metric, perform template matching, iterate the angle tolerance, converge the fan-shaped search space, repeat template matching, and obtain the final building roof outline. The calculation of the global offset principal direction angle includes: calculating an offset vector, which represents the spatial offset relationship between the building boundary and the building vector frame; converting the offset vector into a direction angle using a four-quadrant arctangent function to obtain the offset direction angle; normalizing the offset direction angle; and using the interquartile range truncated mean method to calculate the global offset principal direction angle, including: sorting the set of global offset principal direction angles in ascending order to obtain an ordered sequence; determining the upper and lower bound indices of the effective samples and removing extreme values; extracting samples between the lower and upper bound indices in the ordered sequence to obtain an effective subset; and calculating the arithmetic mean of the effective subset to obtain the global offset principal direction angle.
2. The method according to claim 1, characterized in that, The initial search space is determined as follows: Based on the building vector frame, the buffer is expanded to obtain a rectangular area; Calculate the intersection area between the building vector frame and the candidate building boundaries within the rectangular area, identify building boundaries that meet the overlap requirements as target objects, and determine the outline range of the target objects as the initial search space.
3. The method according to claim 1, characterized in that, After extracting building boundaries from the optical remote sensing image and building vector boxes from the vector map, the method further includes: The building boundary and the building vector frame are contour optimized by using Euclidean distance transformation and morphological dilation.
4. The method according to claim 1, characterized in that, The method further includes: The offset angle is recalculated, the global offset main direction angle is updated, the angle tolerance is reduced, the sector search space is updated, and the final building roof outline is optimized.
5. A device for extracting the outline of a building roof, characterized in that, The device includes: The acquisition module is used to acquire optical remote sensing images and vector maps of the target building complex, extract building boundaries from the optical remote sensing images, and extract building vector boxes from the vector maps. The global search module is used to perform a global search within a predefined initial search space using a normalized cross-correlation similarity metric, perform template matching, and initially locate the building roof outline. This includes: calculating the average gray value of the search domain image within the area covered by the template image, and the average gray value of the template image; performing zero-mean processing on both the search domain image and the template image; calculating the normalized cross-correlation coefficient between the search domain image and the template image; selecting the target location with the highest cross-correlation coefficient, and determining the region corresponding to the target location as the initial location result of the building roof outline. The local optimization module is used to calculate the global offset principal direction angle, set the angle tolerance, and generate a fan-shaped search space with the global offset principal direction angle as the central axis and the angle tolerance as the half-width. Within the fan-shaped search space, local optimization is performed using a normalized cross-correlation similarity metric, template matching is performed, the angle tolerance is iterated, the fan-shaped search space is converged, and template matching is repeated to obtain the final building roof outline. Specifically, the local optimization module is used to: calculate the offset vector, which represents the spatial offset relationship between the building boundary and the building vector frame; convert the offset vector into a direction angle using a four-quadrant arctangent function to obtain the offset direction angle; normalize the offset direction angle; and use the interquartile range truncated mean method to calculate the global offset principal direction angle, including: sorting the set of global offset principal direction angles in ascending order to obtain an ordered sequence; determining the upper and lower bound indices of the effective samples and removing extreme values; extracting samples between the lower and upper bound indices in the ordered sequence to obtain an effective subset; and calculating the arithmetic mean of the effective subset to obtain the global offset principal direction angle.
6. An electronic device, characterized in that, include: The system includes a memory and a processor, which are interconnected and the memory stores computer instructions. The processor executes the computer instructions to perform the building roof outline extraction method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the building roof outline extraction method according to any one of claims 1 to 4.