Method and system for extracting building shadow based on image segmentation
By preprocessing and feature calculation of remote sensing images, combined with Quick Shift and random forest classification models, the poor effect of Quick Shift algorithm in extracting building shadows is solved, and more accurate shadow extraction is achieved, which is suitable for building height monitoring. and urban planning.
Patent Information
- Application Number
- CN202410449581.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-15
- Publication Date
- 2024-09-10
AI Technical Summary
The Quick Shift algorithm cannot accurately extract building shadows when segmenting remote sensing images, resulting in poor shadow extraction results.
A method based on image segmentation is used to obtain high-resolution remote sensing images for preprocessing, calculate remote sensing image features, use the Quick Shift algorithm for image segmentation, and combine it with random forest classification model screening and calculation to finally obtain the building shadow area.
By using the calculated shadow feature index, the image segmentation effect of the Quick Shift algorithm is improved, making the extracted shadow areas more pure and accurate, suitable for building height monitoring and urban planning.
Smart Images

Figure CN118628729A
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of remote sensing digital image processing, and in particular to a method and system for extracting building shadows based on image segmentation. Background Art
[0002] Shadows are common elements in remote sensing images. Shadows refer to the darker imaging areas formed on the remote sensing images due to the backlighting of buildings, mountains, trees and other objects blocking the sunlight. Shadows in remote sensing images block part of the object information and are one of the noises in the image. However, at the same time, shadows can also reflect some object information and are one of the sources of remote sensing image information. The shadow information of buildings can reflect the height, structure and other information of the buildings. This information can be applied to many fields, such as urban change monitoring, urban 3D reconstruction, urban planning, natural disaster monitoring, wireless network base station planning, etc.
[0003] The methods for extracting shadow areas in remote sensing images can be divided into two types: pixel-oriented and object-oriented. Compared with the pixel-oriented classification method, the object-oriented method can directly obtain the target objects at different scales. It not only considers the characteristics of each pixel itself, but also considers the characteristics of its surrounding pixels and the spatial relationship with the surrounding pixels, which can make the classification results more accurate. The object-oriented image classification method is mainly divided into two steps. The first step is to segment the image into homogeneous objects, and the second step is to classify these homogeneous objects according to their characteristics. The key lies in the image segmentation algorithm. In many cases, the results of image analysis are meaningful only when the image is segmented into homogeneous objects.
[0004] The Quick Shift algorithm is a pattern search clustering algorithm with lower computational complexity than the MeanShift algorithm. However, experiments have shown that when the Quick Shift algorithm is used to segment images to extract building shadows, the shadow objects cannot be accurately segmented, resulting in poor building shadow extraction results. Summary of the invention
[0005] In view of the above-mentioned problems, the present invention is proposed.
[0006] Therefore, the technical problem solved by the present invention is that after the Quick Shift algorithm segments the image, the shadow extraction effect is not good.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions: a method for extracting building shadows based on image segmentation, comprising: obtaining high-resolution remote sensing images and performing preprocessing.
[0008] The remote sensing image features are calculated based on the preprocessed images, and the image segmentation algorithm is used.
[0009] The image segmentation results are screened and classified using the random forest classification model to obtain the initial shadow area.
[0010] The initial shadow area is calculated to obtain a final shadow area.
[0011] As a preferred solution of the method for extracting building shadows based on image segmentation described in the present invention, the acquisition of high-resolution remote sensing images and preprocessing include performing radiation calibration, atmospheric correction, orthorectification on the images, and image fusion of panchromatic images and multispectral images.
[0012] As a preferred solution of the method for extracting building shadows based on image segmentation described in the present invention, the remote sensing image features include the first principal component PCA1, the brightness component I, the morphological shadow index MSI, the normalized shadow index NDSI, the normalized vegetation index NDVI, and the normalized water index NDWI.
[0013] The first principal component PCA1 is the first principal component obtained by performing principal component transformation on the four bands of red, green, blue and near infrared of the fused image.
[0014] The calculation formula of the brightness component I is expressed as:
[0015]
[0016] Among them, R represents the red channel intensity value, G represents the green channel intensity value, and B represents the blue channel intensity value.
[0017] The calculation steps of the morphological shadow index MSI are as follows:
[0018] Input preprocessed full-color image f, the shape, direction d, and size range s of the structural element B min ~s max , size change step Δs.
[0019] Perform morphological black hat operation, subtract the original image from the result of the closing operation, and set the result after the operation as g. The formula of the black hat operation is expressed as:
[0020] g(d,s)=f·B(d,s)-f
[0021] Calculate the morphological profile MPs. The morphological profile of each pixel is defined as a one-dimensional vector consisting of the values of the black hat operation obtained by the structural elements of different sizes at the pixel point. For a certain direction d and a certain size s of the structural element, the formula of the morphological profile MPs (d, s) is expressed as:
[0022]
[0023] Calculate the differential morphological profile DMPs. The differential morphological profile of each pixel is defined as a one-dimensional vector composed of the difference between adjacent elements in the morphological profile vector at the pixel. The formula is expressed as:
[0024] DMPs(d,s)=|MPs(d,s+Δs)-MPs(d,s)|
[0025] To calculate MSI, the formula is:
[0026]
[0027] Where D represents the number of directions of the structural element, S represents the number of dimensions of the structural element, and S is expressed as:
[0028]
[0029] The normalized shadow index NDSI formula is expressed as:
[0030] NDSI=(S'-I) / (S'+I),
[0031] Wherein, S' represents saturation, S'=1-(3min(R,G,B)) / (R+G+B).
[0032] The normalized difference vegetation index NDVI formula is expressed as:
[0033] NDVI = (NIR-R) / (NIR+R)
[0034] The normalized water index NDWI formula is expressed as:
[0035] NDWI=(G-NIR) / (G+NIR)
[0036] Among them, NIR stands for near infrared band.
[0037] As a preferred solution of the method for extracting building shadows based on image segmentation described in the present invention, the image segmentation using an algorithm includes image segmentation using a Quick Shift algorithm, the steps are as follows:
[0038] Input the calculation results of the first principal component PCA1, the brightness component I, and the morphological shadow index MSI, and set the ratio coefficient ratio, the bandwidth kernel_size, and the maximum distance max_dist.
[0039] Calculate the probability density of each pixel in the image:
[0040]
[0041]
[0042] Among them, (x, y) represents the spatial coordinates of each pixel, φ b (D ij ) represents kernel density estimation, b represents bandwidth, and N represents point x i The number of pixels in a neighborhood. The size of the neighborhood is determined by the bandwidth. ij Represents pixel point x i With x j The distance between the pixels, x' represents the distance between the pixels x j The spatial coordinates of y' represent other pixels x j The spatial coordinates of , I(x,y) represents the spectral characteristics, expressed as:
[0043] I(x,y)=(PCA1,I,MSI)
[0044] Traverse the entire image to find the mode point to which each pixel point belongs. i , find the point x i The nearest point y with a higher probability density i (1):
[0045]
[0046] y i (1) As a parent node, it forms a branch of the tree.
[0047] Keep moving point x i , repeatedly traverse the entire image to find the mode point to which each pixel point belongs, calculate layer by layer, connect each pixel of the image in turn, and build a tree.
[0048] According to the set maximum distance max_dist, the trees are divided into a forest. Each tree in the forest is a cluster and a local mode.
[0049] As a preferred solution of the method for extracting building shadows based on image segmentation described in the present invention, the filtering of image segmentation results includes filtering the image segmentation results, selecting image homogeneous objects, and eliminating objects with a pixel number less than a specific value.
[0050] As a preferred solution of the method for extracting building shadows based on image segmentation described in the present invention, wherein: the calculation of the initial shadow area includes classifying using a random forest classification model to obtain two types of results, shadow and non-shadow, and performing morphological opening and closing operations on the shadow area, and the specific steps are:
[0051] The opening operation first erodes the original image and then performs a dilation operation.
[0052] The image after the opening operation is g(x,y), and the definition of the opening operation is expressed as:
[0053]
[0054] The closing operation first dilates the original image and then performs an erosion operation.
[0055] The image after the closing operation is g1(x,y), and the closing operation is defined as:
[0056]
[0057] in, Indicates expansion, represents erosion, f(x,y) represents the grayscale image to be processed, and B' represents the structural element.
[0058] When the structural element B' expands the grayscale image f(x,y), the structural element translates in the grayscale image with the anchor point as the center point. When the anchor point of the structural element moves to (z x ,z y ), the pixel point (z x ,z y ) is the maximum value of the pixels in the neighborhood determined by the structural element in the original image. Let the expanded image be g2(x,y), and the grayscale expansion is expressed as:
[0059]
[0060] As a preferred solution of the method for extracting building shadows based on image segmentation described in the present invention, wherein: the calculation of the initial shadow area includes: when the structural element B' erodes the grayscale image f(x, y), the structural element is translated in the grayscale image with the anchor point as the center point, and when the anchor point of the structural element moves to (z x ,z y ), the pixel point (z x ,z y ) is the minimum value of the pixel in the neighborhood determined by the structural element in the original image. Let the image after corrosion be g3(x,y), and the grayscale corrosion is expressed as:
[0061]
[0062] Among them, (x b ,y b ) represents the position coordinates of the pixel in the structural element B'.
[0063] A system for extracting building shadows based on image segmentation, characterized by: comprising:
[0064] The preprocessing module obtains high-resolution remote sensing images and performs preprocessing.
[0065] The image segmentation module calculates the remote sensing image features based on the preprocessed images and uses algorithms to perform image segmentation.
[0066] The classification module is filtered to filter the image segmentation results, and the random forest classification model is used for classification to obtain the initial shadow area.
[0067] The calculation module calculates the initial shadow area to obtain a final shadow area.
[0068] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0069] A computer-readable storage medium stores a computer program, which implements the steps of the method described above when executed by a processor.
[0070] The beneficial effects of the present invention are as follows: by using the three calculated shadow features instead of the RGB image as the input data of Quick Shift, the shadow area in the remote sensing image can be extracted more accurately. After inspection, the object boundary obtained by the Quick Shift image segmentation algorithm after taking into account the shadow feature index is more in line with the shadow boundary, so that the obtained shadow object is purer, and thus the final effect of extracting the shadow is better. The method for extracting the shadow of a building established by the present invention can more accurately extract the shadow of a building, thereby obtaining information such as the structure and height of the building, which plays an important role in building height monitoring, urban volume ratio calculation, and urban development planning. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0072] Figure 1 An overall flow chart of a method for extracting building shadows based on image segmentation provided by the first embodiment of the present invention;
[0073] Figure 2 An overall flow chart of a method for extracting building shadows based on image segmentation provided by a second embodiment of the present invention;
[0074] Figure 3An overall flow chart of a method for extracting building shadows based on image segmentation provided by a second embodiment of the present invention;
[0075] Figure 4 An overall flow chart of a method for extracting building shadows based on image segmentation provided by a second embodiment of the present invention;
[0076] Figure 5 An overall flow chart of a method for extracting building shadows based on image segmentation provided by a second embodiment of the present invention;
[0077] Figure 6 An overall flow chart of a method for extracting building shadows based on image segmentation provided for the second embodiment of the present invention. DETAILED DESCRIPTION
[0078] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.
[0079] Example 1
[0080] Reference Figure 1 , as an embodiment of the present invention, provides a method for extracting building shadows based on image segmentation, comprising:
[0081] S1: Obtain high-resolution remote sensing images and perform preprocessing.
[0082] Perform radiometric calibration, atmospheric correction, and orthorectification on the images, and perform image fusion on panchromatic and multispectral images.
[0083] S2: Calculate the remote sensing image features based on the preprocessed image and use the algorithm to perform image segmentation.
[0084] The remote sensing image characteristics include the first principal component PCA1, brightness component I, morphological shadow index MSI, normalized shadow index NDSI, normalized vegetation index NDVI, and normalized water index NDWI.
[0085] The first principal component PCA1 is the first principal component obtained after principal component transformation of the red, green, blue and near-infrared bands of the fused image.
[0086] The calculation formula of the brightness component I is expressed as:
[0087]
[0088] Among them, R represents the red channel intensity value, G represents the green channel intensity value, and B represents the blue channel intensity value.
[0089] The calculation steps of the morphological shadow index MSI are as follows:
[0090] Input preprocessed full-color image f, the shape, direction d, and size range s of the structural element B min ~s max , size change step Δs.
[0091] Perform morphological black hat operation, subtract the original image from the result of the closing operation, and set the result after the operation as g. The formula of the black hat operation is expressed as:
[0092] g(d,s)=f·B(d,s)-f
[0093] Calculate the morphological profile MPs. The morphological profile of each pixel is defined as a one-dimensional vector consisting of the values of the black hat operation obtained by the structural elements of different sizes at the pixel point. For a certain direction d and a certain size s of the structural element, the formula of the morphological profile MPs (d, s) is expressed as:
[0094]
[0095] Calculate the differential morphological profile DMPs. The differential morphological profile of each pixel is defined as a one-dimensional vector composed of the difference between adjacent elements in the morphological profile vector at the pixel. The formula is expressed as:
[0096] DMPs(d,s)=|MPs(d,s+Δs)-MPs(d,s)|
[0097] To calculate MSI, the formula is:
[0098]
[0099] Where D represents the number of directions of the structural element, S represents the number of dimensions of the structural element, and S is expressed as:
[0100]
[0101] The normalized shadow index NDSI formula is expressed as:
[0102] NDSI=(S'-I) / (S'+I),
[0103] Wherein, S' represents saturation, S'=1-(3min(R,G,B)) / (R+G+B).
[0104] The formula of normalized vegetation index NDVI is:
[0105] NDVI = (NIR-R) / (NIR+R)
[0106] The normalized water index NDWI formula is expressed as:
[0107] NDWI=(G-NIR) / (G+NIR)
[0108] Among them, NIR stands for near infrared band.
[0109] S3: Filter the image segmentation results and use the random forest classification model to classify and obtain the initial shadow area.
[0110] Use the Quick Shift algorithm to perform image segmentation. The steps are as follows:
[0111] Input the calculation results of the first principal component PCA1, the brightness component I, and the morphological shadow index MSI, and set the ratio coefficient ratio, bandwidth kernel_size, and maximum distance max_dist.
[0112] Calculate the probability density of each pixel in the image:
[0113]
[0114]
[0115] Among them, (x, y) represents the spatial coordinates of each pixel, φ b (D ij ) represents kernel density estimation, b represents bandwidth, and N represents point x i The number of pixels in a neighborhood. The size of the neighborhood is determined by the bandwidth. ij Represents pixel point x i With x j The distance between the pixels, x' represents the distance between the pixels x j The spatial coordinates of y' represent other pixels x j The spatial coordinates of , I(x,y) represents the spectral characteristics, expressed as:
[0116] I(x,y)=(PCA1,I,MSI)
[0117] It should be noted that in order to balance the importance of spectral features and spatial features, a ratio coefficient ratio is usually assigned to the spectral features. In order to make the formula more concise, the ratio coefficient ratio is not added to the formula. In practical applications, the spectral feature I(x,y) is first multiplied by ratio. It should be noted that x i The difference between x and i represents each pixel point, while x and y represent the pixel point x iThe spatial coordinates of the pixel x are represented by x' and y'. j The spatial coordinates of .
[0118] Traverse the entire image to find the mode point to which each pixel point belongs. i , find the point x i The nearest point y with a higher probability density i (1):
[0119]
[0120] y i (1) As a parent node, it forms a branch of the tree.
[0121] Keep moving point x i , repeatedly traverse the entire image to find the mode point to which each pixel point belongs, calculate layer by layer, connect each pixel of the image in turn, and build a tree.
[0122] According to the set maximum distance max_dist, the trees are divided into a forest. Each tree in the forest is a cluster and a local mode.
[0123] The obtained image objects are screened for homogeneity, and objects with a number of pixels less than a certain value are eliminated.
[0124] It should be noted that this is to remove the interference of shadows of other objects, such as shadows of vegetation. The specific value is set based on experience. In different images, the number of pixels occupied by building shadows is different. According to the results of visual interpretation, only one value needs to be set to retain the shadows of buildings while removing the shadows of most other smaller objects.
[0125] Furthermore, the method for calculating the eigenvalues of each homogeneous object is to first sort the pixels in the homogeneous object according to the value of the brightness component I, remove the first 25% of the data and the last 25% of the data, and then calculate the average value of each eigenvalue of the remaining 50% of the pixels as the eigenvalue of the homogeneous object.
[0126] S4: Calculate the initial shadow area to obtain the final shadow area.
[0127] The random forest classification model is used for classification to obtain two types of results: shadow and non-shadow. Morphological opening and closing operations are performed on the shadow area. The specific steps are as follows:
[0128] The opening operation first erodes the original image and then performs a dilation operation.
[0129] The image after the opening operation is g(x,y), and the definition of the opening operation is expressed as:
[0130]
[0131] The closing operation first dilates the original image and then performs an erosion operation.
[0132] The image after the closing operation is g1(x,y), and the closing operation is defined as:
[0133]
[0134] in, Indicates expansion, represents erosion, f(x,y) represents the grayscale image to be processed, and B' represents the structural element.
[0135] It should be noted that the purpose of the opening and closing operations is to modify the shadow boundaries, remove broken shadow blocks, and fill the holes inside the shadow.
[0136] When the structural element B' expands the grayscale image f(x,y), the structural element translates in the grayscale image with the anchor point as the center point. When the anchor point of the structural element moves to (z x ,z y ), the pixel point (z x ,z y ) is the maximum value of the pixels in the neighborhood determined by the structural element in the original image. Let the expanded image be g2(x,y), and the grayscale expansion is expressed as:
[0137]
[0138] When the structural element B' erodes the grayscale image f(x,y), the structural element translates in the grayscale image with the anchor point as the center point. When the anchor point of the structural element moves to (z x ,z y ), the pixel point (z x ,z y ) is the minimum value of the pixel in the neighborhood determined by the structural element in the original image. Let the image after corrosion be g3(x,y), and the grayscale corrosion is expressed as:
[0139]
[0140] Among them, (x b ,y b ) represents the position coordinates of the pixel in the structural element B'.
[0141] The above embodiments also include a system for extracting building shadows based on image segmentation, specifically:
[0142] The preprocessing module obtains high-resolution remote sensing images and performs preprocessing.
[0143] The image segmentation module calculates the remote sensing image features based on the preprocessed images and uses algorithms to perform image segmentation.
[0144] The classification module is filtered to filter the image segmentation results, and the random forest classification model is used for classification to obtain the initial shadow area.
[0145] The calculation module calculates the initial shadow area to obtain the final shadow area.
[0146] The computer device may be a server. The computer device includes a processor, a memory, an input / output interface (I / O for short) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data cluster data of a power monitoring system. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method is implemented.
[0147] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0148] Example 2
[0149] Reference Figure 2 to Figure 6 , which is an embodiment of the present invention, provides a method and system for extracting building shadows based on image segmentation. In order to verify the beneficial effects of the present invention, scientific demonstration is carried out through simulation experiments.
[0150] The experimental steps are as follows:
[0151] Step 1: Preprocess the GF-2 remote sensing image and crop the preprocessed data to the target research area;
[0152] This step preprocesses the panchromatic and multispectral images, including radiometric calibration, atmospheric correction, orthorectification, and image fusion.
[0153] Step 2: Use the preprocessed image to calculate six characteristic variables, including the first principal component PCA1, brightness component I, morphological shadow index MSI, normalized shadow index NDSI, normalized vegetation index NDVI, and normalized water index NDWI;
[0154] The characteristic variables calculated in this step are as follows Figure 2 shown.
[0155] Step 3: The first principal component PCA1, brightness component I, and morphological shadow index MSI calculated in step 2 are used as input images instead of the original three bands of red, green, and blue. The image segmentation is performed using the Quick Shift algorithm. At the same time, for comparison, RGB is also used as the input image and the image converted from RGB to Lab is used as the input image for image segmentation.
[0156] The Quick Shift image segmentation algorithm code used in this step comes from the Python package skimage. The segmentation parameters used are kernel_size=5, max_dist=15, ratio=0.5. The image segmentation results are shown in the figure below. Figure 3 As shown in the figure, 3(a) is the image of the study area, 3(b) is the segmentation result when the RGB image is directly used as the input image, 3(c) is the segmentation result after converting the RGB color space to the Lab color space, and 3(d) is the segmentation result when PCA1, I, and MSI are used as the input image. Figure 3 The segmentation boundary in (d) is closer to the boundary of the shadow area.
[0157] Step 4: Filter the homogeneous objects in the image obtained in step 3 and remove the objects with less than 50 pixels;
[0158] This step is to remove the interference of shadows from other objects, such as shadows from vegetation.
[0159] Step 5: Use the random forest classification model to classify into two categories: shadow and non-shadow. The number of decision trees is set to 100. The feature values used include the preprocessed remote sensing image, brightness component I, morphological shadow index MSI, normalized shadow index NDSI, normalized water index NDWI, and normalized vegetation index NDVI. In this way, the initial shadow area is obtained.
[0160] The method for calculating the eigenvalues of each homogeneous object in this step is to first sort the pixels in the homogeneous object according to the value of the brightness component I, remove the first 25% of the data and the last 25% of the data, and then calculate the average value of each eigenvalue of the remaining 50% of the pixels as the eigenvalue of the homogeneous object.
[0161] Step 6: Perform morphological opening and closing operations on the initial shadow area to obtain the final shadow area.
[0162] This step is to modify the shadow boundary, remove broken shadow blocks, and fill the holes inside the shadow. The structure element used is a 3-square structure element. The final shadow is as follows Figure 4 As shown, 4(a) is the manually drawn shadow area, 4(b) is the shadow area obtained when the RGB image is directly used as the input image, 4(c) is the shadow area calculated after converting the RGB color space to the Lab color space, and 4(d) is the shadow area obtained when PCA1, I, and MSI are used as the input image;
[0163] Step 7: In order to verify the effectiveness of the method proposed in the present invention, the shadow area obtained by the method in the present invention is compared with the real shadow area, and the Kappa coefficient of the shadow pixel classification is calculated;
[0164] In this step, Figure 4 (b), 4(c), 4(d) and Figure 4 The shadow areas in (a) are compared and the Kappa coefficients of shadow pixel classification are calculated. The results are 0.3651, 0.5854, and 0.8986, respectively.
[0165] Step 8: In order to verify the stability of the present invention, the influence of the segmentation scale on the experiment, that is, the influence of the values of the three parameters ratio, kernel_size, and max_dist on the experiment is excluded. The value range of ratio is set to {0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}, the value range of kernel_size and max_dist is set to {5, 10, 15, 20, 25}, and all combinations of these three parameters are traversed. The three input images are used for calculation respectively to obtain the Kappa coefficient of the shadow pixel classification results under different conditions.
[0166] The schematic diagram of parameter combination in this step is as follows Figure 5 As shown, the results are as follows Figure 6 As shown in the figure, rgb in the legend means that RGB is used as the input image, lab means that RGB is converted to Lab color space as the input image, and variable means that PCA1, I, and MSI are used as the input image. Figure 6It can be seen from the figure that when an appropriate segmentation scale is used for segmentation, the method invented in this paper can obtain better shadow extraction results.
[0167] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for extracting building shadows based on image segmentation, characterized in that: include: Acquire high-resolution remote sensing images and perform preprocessing; Calculate remote sensing image features based on preprocessed images and use algorithms to perform image segmentation; Filter the image segmentation results and use the random forest classification model to classify and obtain the initial shadow area; The initial shadow area is calculated to obtain a final shadow area.
2. The method for extracting building shadows based on image segmentation as claimed in claim 1, characterized in that: The acquisition of high-resolution remote sensing images and preprocessing include performing radiation calibration, atmospheric correction, orthorectification on the images, and image fusion of panchromatic images and multispectral images.
3. The method for extracting building shadows based on image segmentation as claimed in claim 2, characterized in that: The remote sensing image features include the first principal component PCA1, the brightness component I, the morphological shadow index MSI, the normalized shadow index NDSI, the normalized vegetation index NDVI, and the normalized water index NDWI; The first principal component PCA1 is the first principal component obtained by performing principal component transformation on the four bands of red, green, blue and near infrared of the fused image; The calculation formula of the brightness component I is expressed as: Among them, R represents the intensity value of the red channel, G represents the intensity value of the green channel, and B represents the intensity value of the blue channel; The calculation steps of the morphological shadow index MSI are as follows: Input preprocessed full-color image f, the shape, direction d, and size range s of the structural element B min ~s max , size change step Δs; Perform morphological black hat operation, subtract the original image from the result of the closing operation, and set the result after the operation as g. The formula of the black hat operation is expressed as: g(d,s)=f·B(d,s)-f Calculate the morphological profile MPs. The morphological profile of each pixel is defined as a one-dimensional vector consisting of the values of the black hat operation obtained by the structural elements of different sizes at the pixel point. For a certain direction d and a certain size s of the structural element, the formula of the morphological profile MPs (d, s) is expressed as: Calculate the differential morphological profile DMPs. The differential morphological profile of each pixel is defined as a one-dimensional vector composed of the difference between adjacent elements in the morphological profile vector at the pixel. The formula is expressed as: DMPs(d,s)=|MPs(d,s+Δs)-MPs(d,s)| To calculate MSI, the formula is: Where D represents the number of directions of the structural element, S represents the number of dimensions of the structural element, and S is expressed as: The normalized shadow index NDSI formula is expressed as: NDSI = (S′-I) / (S′+I), Wherein, S' represents saturation, S'=1-(3min(R, G, B)) / (R+G+B); The normalized difference vegetation index NDVI formula is expressed as: NDVI = (NIR-R) / (NIR+R) The normalized water index NDWI formula is expressed as: NDWI=(G-NIR) / (G+NIR) Among them, NIR stands for near infrared band.
4. The method for extracting building shadows based on image segmentation as claimed in claim 3, characterized in that: The image segmentation using an algorithm includes using a Quick Shift algorithm to segment the image, and the steps are as follows: Input the calculation results of the first principal component PCA1, the brightness component I, and the morphological shadow index MSI, and set the ratio coefficient ratio, the bandwidth kernel_size, and the maximum distance max_dist; Calculate the probability density of each pixel in the image: Among them, (x, y) represents the spatial coordinates of each pixel, φ b (D ij ) represents kernel density estimation, b represents bandwidth, and N represents point x i The number of pixels in the neighborhood. The size of the neighborhood is determined by the bandwidth. ii Represents pixel point x i With x j The distance between the pixels, x′ represents the distance between the pixels x j The spatial coordinates of y′ represent other pixels x j The spatial coordinates of , I(x, y) represents the spectral characteristics, expressed as: I(x, y) = (PCA1, I, MSI) Traverse the entire image to find the mode point to which each pixel point belongs; for each pixel point x i , find the point x i The nearest point y with a higher probability density i (1): y i (1) As a parent node, forming branches of the tree; Keep moving point x i , repeatedly traverse the entire image to find the mode point to which each pixel belongs, calculate layer by layer, connect each pixel of the image in turn, and build a tree; According to the set maximum distance max_dist, the trees are divided into a forest. Each tree in the forest is a cluster and a local mode.
5. The method for extracting building shadows based on image segmentation as claimed in claim 4, characterized in that: The screening of the image segmentation results includes screening the image segmentation results, selecting homogeneous objects in the images, and eliminating objects whose pixel numbers are less than a specific value.
6. The method for extracting building shadows based on image segmentation as claimed in claim 5, characterized in that: The calculation of the initial shadow area includes using a random forest classification model to classify the shadow and non-shadow results, and performing morphological opening and closing operations on the shadow area. The specific steps are: The opening operation first erodes the original image and then performs the dilation operation; The image after the opening operation is g(x, y), and the definition of the opening operation is expressed as: The closing operation first dilates the original image and then performs an erosion operation; The image after the closing operation is g1(x, y), and the closing operation is defined as: in, Indicates expansion, represents corrosion, f(x, y) represents the grayscale image to be processed, and B′ represents the structural element; When the structural element B′ expands the grayscale image f(x, y), the structural element translates in the grayscale image with the anchor point as the center point. When the anchor point of the structural element moves to (z x , z y ), the pixel point (z x , z y ) is the maximum value of the pixels in the neighborhood determined by the structural element in the original image; let the expanded image be g2(x, y), and the grayscale expansion is expressed as:
7. The method for extracting building shadows based on image segmentation as claimed in claim 6, characterized in that: The calculation of the initial shadow area includes: when the structural element B′ erodes the grayscale image f(x, y), the structural element is translated in the grayscale image with the anchor point as the center point, and when the anchor point of the structural element moves to (z x , z y ), the pixel point (z x , z y ) is the minimum value of the pixel in the neighborhood determined by the structural element in the original image; let the image after corrosion be g3(x, y), and the grayscale corrosion is expressed as: Among them, (x b ,y b ) represents the position coordinates of the pixel in the structural element B′.
8. A system for extracting building shadows based on image segmentation using the method according to any one of claims 1 to 7, characterized in that: Preprocessing module, to obtain high-resolution remote sensing images and perform preprocessing; The image segmentation module calculates the remote sensing image features based on the preprocessed images and uses algorithms to perform image segmentation; Screening classification module, screening image segmentation results, using random forest classification model for classification, and obtaining initial shadow area; The calculation module calculates the initial shadow area to obtain a final shadow area.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
