A method for extracting vegetation areas from ground images based on texture features
By extracting vegetation areas in ground images, and using texture feature vector fusion technology, the problem of low vegetation extraction accuracy in the prior art is solved, and higher accuracy and robustness of vegetation area recognition are achieved.
Patent Information
- Application Number
- CN202410660313.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-27
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2044-05-27
AI Technical Summary
When extracting vegetation areas from ground images, it is difficult to distinguish the subtle differences between vegetation and non-vegetation, and the spectral characteristics are easily disturbed by factors such as lighting conditions, topography influences and sensor characteristics, resulting in low extraction accuracy.
Using a texture feature-based method, vegetation areas are extracted from the ground image, and by acquiring the ground image, the grayscale correlation between vegetation cells is calculated, the grayscale correlation texture feature vector is generated, and the grayscale correlation texture feature vector is fused through the construction of image segmentation and grayscale symbiosis matrix, the grayscale correlation texture feature vector and the difference correlation texture feature vector are obtained to obtain the joint texture feature vector, and finally the vegetation area is extracted.
Through the use of texture characteristics, subtle structural changes in vegetation areas can be captured, the ability to distinguish different vegetation types is improved, the sensitivity to factors such as lighting conditions, topography and sensor characteristics is reduced, the accuracy and robustness of vegetation extraction is improved, and it is suitable for the processing of large-scale ground image data.
Smart Images

Figure CN118411614B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent processing technology, and in particular to a method for extracting vegetation areas from a ground image based on texture features. Background Art
[0002] Extracting vegetation areas from ground images is becoming increasingly important for fields such as agricultural monitoring, ecological assessment, and urban planning. Traditional vegetation extraction methods mainly rely on spectral features, which can identify vegetation to a certain extent, but often have difficulty distinguishing the subtle differences between vegetation and non-vegetation, especially in cases of diverse vegetation types or complex environments. In addition, spectral features are easily disturbed by factors such as lighting conditions, terrain effects, and sensor characteristics, resulting in low extraction accuracy.
[0003] In order to improve the accuracy of vegetation extraction, researchers began to explore methods based on texture features. Texture features can describe the spatial distribution pattern of pixels in an image and have unique advantages in capturing subtle structural changes in vegetation areas. However, existing vegetation extraction methods based on texture features have some limitations. For example, some methods rely on manually designed texture operators, which may be difficult to adapt to different vegetation types and environmental conditions. In addition, some methods have high computational complexity and are not suitable for large-scale data processing. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a method for extracting vegetation areas from ground images based on texture features, so as to at least solve or alleviate the above problems existing in the prior art.
[0005] In order to achieve the above object, according to one aspect of the present application, a method for extracting vegetation areas from a ground image based on texture features is provided, which comprises:
[0006] Acquire ground imagery;
[0007] Extracting vegetation pixels from the ground image and calculating the grayscale correlation between the vegetation pixels;
[0008] According to the grayscale correlation between the vegetation pixels, a grayscale correlation texture feature vector is generated;
[0009] Performing image segmentation on the ground image to obtain a plurality of image blocks, and calculating the difference distribution of pixel values within each image block;
[0010] Based on the constructed gray-level co-occurrence matrix, the difference distribution of the internal pixel values of all image blocks is calculated to generate the differential correlation texture feature vector;
[0011] fusing the grayscale-related texture feature vector and the difference-related texture feature vector to obtain a joint texture feature vector;
[0012] According to the joint texture feature vector, feature extraction is performed on the ground image to obtain texture features;
[0013] A vegetation area is extracted from the ground image according to the texture feature.
[0014] In the present application, the recognition ability of vegetation area is enhanced by texture features, and the subtle structural changes of vegetation area can be captured, which helps to distinguish different vegetation types, even in the case of diverse vegetation types or complex environment. In addition, since texture features describe the spatial distribution pattern between pixels, compared with spectral features, it is less sensitive to factors such as lighting conditions, terrain effects and sensor characteristics, thereby improving the robustness of vegetation extraction. Furthermore, by calculating the grayscale correlation between vegetation pixels, the method can generate grayscale-related texture feature vectors adapted to different vegetation types, thereby realizing a feature extraction method based on the data itself, which has better adaptability than hand-designed texture operators. Finally, the method can process image blocks in parallel through image segmentation and the construction of grayscale co-occurrence matrix, thereby improving computational efficiency. At the same time, by fusing grayscale-related texture feature vectors and differential-related texture feature vectors, the required computing resources can be reduced while maintaining feature extraction accuracy, and by fusing grayscale-related texture feature vectors and differential-related texture feature vectors, the method can comprehensively utilize the advantages of the two features to improve the accuracy of vegetation area extraction. After generating the joint texture feature vector, this method further extracts features from the ground image to obtain more accurate texture features, thereby improving the accuracy of identifying and distinguishing vegetation areas from the image. In addition, in the overall process, since this method optimizes the algorithm and reduces the computational complexity, it is more suitable for processing large-scale ground image data. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The drawings constituting a part of this application are used to provide a further understanding of this application, so that other features, purposes and advantages of this application become more obvious. The schematic embodiment drawings and their descriptions of this application are used to explain this application and do not constitute an improper limitation on this application. In the drawings:
[0016] Figure 1 The present invention is a flowchart of a method for extracting vegetation areas from a ground image based on texture features according to an embodiment of the present application. DETAILED DESCRIPTION
[0017] In order to enable those skilled in the art to better understand the solution of the present application, the following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0018] Figure 1 FIG. 1 is a flow chart of a method for extracting vegetation areas from ground images based on texture features according to an embodiment of the present application. Figure 1 As shown, it includes:
[0019] Acquire ground imagery;
[0020] Extracting vegetation pixels from the ground image and calculating the grayscale correlation between the vegetation pixels;
[0021] According to the grayscale correlation between the vegetation pixels, a grayscale correlation texture feature vector is generated;
[0022] Performing image segmentation on the ground image to obtain a plurality of image blocks, and calculating the difference distribution of pixel values within each image block;
[0023] Based on the constructed gray-level co-occurrence matrix, the difference distribution of the internal pixel values of all image blocks is calculated to generate the differential correlation texture feature vector;
[0024] fusing the grayscale-related texture feature vector and the difference-related texture feature vector to obtain a joint texture feature vector;
[0025] According to the joint texture feature vector, feature extraction is performed on the ground image to obtain texture features;
[0026] A vegetation area is extracted from the ground image according to the texture feature.
[0027] In the present application, the recognition ability of vegetation area is enhanced by texture features, and the subtle structural changes of vegetation area can be captured, which helps to distinguish different vegetation types, even in the case of diverse vegetation types or complex environments. In addition, since texture features describe the spatial distribution pattern between pixels, compared with spectral features, it is less sensitive to factors such as lighting conditions, terrain effects and sensor characteristics, thereby improving the robustness of vegetation extraction. Furthermore, by calculating the grayscale correlation between vegetation pixels, the method can generate grayscale-related texture feature vectors adapted to different vegetation types, thereby realizing a feature extraction method based on the data itself, which has better adaptability than hand-designed texture operators. Finally, the method can process image blocks in parallel through image segmentation and the construction of grayscale co-occurrence matrix, thereby improving computational efficiency. At the same time, by fusing grayscale-related texture feature vectors and differential-related texture feature vectors, the required computing resources can be reduced while maintaining feature extraction accuracy, and by fusing grayscale-related texture feature vectors and differential-related texture feature vectors, the method can comprehensively utilize the advantages of the two features to improve the accuracy of vegetation area extraction. After generating the joint texture feature vector, this method further extracts features from the ground image to obtain more accurate texture features, thereby improving the accuracy of identifying and distinguishing vegetation areas from the image. In addition, in the overall process, since this method optimizes the algorithm and reduces the computational complexity, it is more suitable for processing large-scale ground image data.
[0028] Optionally, extracting vegetation pixels from the ground image and calculating grayscale correlations between the vegetation pixels includes:
[0029] Extracting vegetation pixels from the ground image based on a set grayscale threshold;
[0030] Based on the covariance of the grayscale difference between each vegetation pixel and its neighboring vegetation pixels, the grayscale correlation between the vegetation pixels is calculated.
[0031] To this end, the use of grayscale thresholds can effectively distinguish vegetation pixels from ground images, because vegetation usually has a specific grayscale range, so that vegetation areas can be more accurately identified, thereby improving the accuracy of vegetation extraction. Moreover, the method of setting grayscale thresholds can be adjusted according to different environmental conditions to adapt to different vegetation types and backgrounds. This flexibility enables the method to be widely used in various remote sensing images. Furthermore, by filtering out vegetation pixels through grayscale thresholds, the number of pixels that need to be considered in subsequent processing steps can be reduced, thereby reducing the amount of calculation and improving the processing speed. In addition, by calculating the covariance of the grayscale difference between vegetation pixels, the subtle grayscale changes between vegetation pixels can be captured, which helps to identify the texture features inside the vegetation and maintain high robustness even in the presence of changing lighting conditions or noise. In particular, grayscale covariance can provide statistical information on grayscale changes between vegetation pixels, which helps to construct richer and more expressive texture feature vectors. In the image segmentation step, the grayscale correlation information can be used to more accurately define the boundaries of image blocks, thereby obtaining more reasonable and accurate image block divisions. Accurate vegetation pixel extraction and grayscale correlation calculation provide high-quality input data for subsequent vegetation index calculation, biomass estimation and other analyses.
[0032] An exemplary implementation code is provided below:
[0033] import cv2
[0034] import numpy as np
[0035] # Assume ground_image is the loaded ground image
[0036] # Set the grayscale threshold
[0037] lower_threshold = 100 # Adjust according to actual situation
[0038] upper_threshold = 200 # Adjust according to actual situation
[0039] # Binarization operation to extract vegetation pixels
[0040] _, vegetation_mask = cv2.threshold(ground_image, upper_threshold,255, cv2.THRESH_BINARY_INV)
[0041] # Calculate the gray level co-occurrence matrix (GLCM)
[0042] glcm = cv2.GLCM(vegetation_mask, 0, 4, None, [0, 0], [5, 5],cv2.GLCM_CORREL)
[0043] # Extract grayscale correlation from GLCM
[0044] correlation_value = glcm[0, 0]
[0045] #Further vegetation area extraction based on correlation_value
[0046] # Display results
[0047] cv2.imshow('Vegetation Mask', vegetation_mask)
[0048] cv2.waitKey(0)
[0049] cv2.destroyAllWindows()
[0050] In the above code, the OpenCV library is used to load the ground image and set the grayscale threshold to extract the vegetation pixels. Then, the `cv2.threshold` function is used to perform a binarization operation to obtain the vegetation mask. Next, the `cv2.GLCM` function is used to calculate the gray-level co-occurrence matrix (such as GLCM) and extract the grayscale correlation value from the GLCM.
[0051] Optionally, the extracting vegetation pixels from the ground image based on the set grayscale threshold includes:
[0052] Based on the formula , convert the pixel value of each pixel point on the ground image into a radiation brightness value, is the radiance value, is the pixel value, is the gain coefficient of the vegetation spectral band, is the solar spectral irradiance, is the solar zenith angle, is the atmospheric path radiation correction factor;
[0053] Performing radiation correction on the ground image according to the radiation brightness value corresponding to each pixel point on the ground image;
[0054] Based on the set grayscale threshold, vegetation pixels are extracted from the radiation-corrected ground image.
[0055] To this end, through radiation correction, the actual situation on the ground can be more accurately reflected, and the quality and readability of the image can be improved. The image after radiation correction can more realistically reflect the radiation brightness value of the vegetation, which helps to set the grayscale threshold more accurately, thereby improving the accuracy of vegetation pixel extraction. Radiation correction takes into account the influence of atmospheric path radiation and solar zenith angle, which helps to reduce the interference of these factors on vegetation pixel extraction. Through radiation correction, the vegetation extraction algorithm can be applied not only to images under specific conditions, but also to images acquired under different lighting and atmospheric conditions. The calculation of vegetation indices (such as NDVI) depends on the radiation brightness value. Radiation correction can improve the accuracy of the calculation of these indices, thereby providing more reliable vegetation status information. When conducting multi-temporal analysis, radiation correction helps to ensure the consistency of image data acquired at different times in radiation brightness, thereby improving the reliability of temporal analysis.
[0056] An exemplary implementation code is provided below:
[0057] # ground_image is a two-dimensional array containing the pixel values of the ground image
[0058] # ESUN, a, theta, L are known parameters
[0059] ESUN = ... # Solar spectral irradiance
[0060] a = ... # additive constant
[0061] theta = ... # Solar zenith angle, in radians
[0062] L = ... # gain factors
[0063] # Convert pixel values to radiance values
[0064] ground_image_rad = (ground_image + a) / (ESUN * np.cos(theta) * L)
[0065] # Apply grayscale thresholding for radiometric correction
[0066] # Assume that lower_threshold and upper_threshold are preset radiance thresholds
[0067] lower_threshold = ...
[0068] upper_threshold = ...
[0069] vegetation_mask = (ground_image_rad>lower_threshold)&(ground_image_rad<= upper_threshold)
[0070] # The above code will generate a binary image of the same size as ground_image, where vegetation pixels are True and non-vegetation pixels are False
[0071] Optionally, performing radiation correction on the ground image according to the radiation brightness value corresponding to each pixel point on the ground image includes:
[0072] Performing inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding radiation energy quantization value;
[0073] Based on the quantized value of radiation energy corresponding to each pixel point on the ground image, a radiation-corrected ground image is generated.
[0074] To this end, inverse radiometric calibration converts pixel values from digital counts to radiation energy values with actual physical meaning, which helps to more accurately analyze surface features, such as vegetation index calculation. Inverse radiometric calibration processing can eliminate the radiation differences between images acquired by different sensors or at different times, making the data more comparable. Through inverse radiometric calibration, the radiation characteristics of the surface can be more accurately reflected, thereby improving the accuracy of subsequent analysis. Inverse radiometric calibration is a prerequisite for atmospheric correction, which helps to remove the influence of the atmosphere on the image and improve the quality and availability of the image. Inverse radiometric calibration ensures the consistency of the radiation brightness of image data acquired at different times, which is very important for multi-temporal analysis and time series analysis. Accurate radiation energy quantification values can improve the accuracy of object classification, especially for distinguishing between objects with different radiation characteristics such as vegetation, water bodies and urban areas.
[0075] An exemplary implementation code is provided below:
[0076] # Each pixel in ground_image is calibrated by inverse radiation
[0077] gain = ... # Gain factor, may vary depending on the sensor and band
[0078] bias = ... # bias value
[0079] # Perform inverse radiation calibration on each pixel
[0080] radiance_image = ground_image * gain - bias
[0081] #radiance_image contains the radiation brightness value, which can be used for subsequent analysis
[0082] #Convert radiance to radiant energy quantification# This usually depends on the specific application requirements and available auxiliary data
[0083] # Generate a radiation-corrected ground image based on the quantified radiation energy value
[0084] # radiance_image is the image after radiation correction
[0085] corrected_ground_image = radiance_image
[0086] # Display the radiometrically corrected image
[0087] import matplotlib.pyplot as plt
[0088] plt.imshow(corrected_ground_image, cmap='gray')
[0089] plt.title('Radiance Corrected Image')
[0090] plt.show()
[0091] Optionally, performing inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding radiation energy quantization value includes:
[0092] Based on the formula Performing linear inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding first radiation energy quantization value, is the radiance value, is the linear inverse radiation calibration parameter, is the linear inverse radiation calibration order, represents a first quantized value of radiation energy;
[0093] Based on the formula Perform piecewise linear inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding second radiation energy quantization value, is the radiance value, and Respectively represent the offset and gain coefficient in the Mth linear segment, are the thresholds for different linear segments, represents the second radiant energy quantization value, and the linear segment represents the value obtained by dividing all radiant brightness values into multiple intervals according to different linear segment thresholds;
[0094] Based on the formula performing a weighted operation on the first radiation energy quantization value and the second radiation energy quantization value, and using the result of the weighted operation as the corresponding radiation energy quantization value, represents the first quantized value of radiation energy, represents the second quantized value of radiation energy, and They represent the confidence weights, + =1.
[0095] To this end, inverse radiation calibration converts DN values into radiation brightness and radiation energy. These quantitative values have clear physical meanings and are easy to scientifically analyze and interpret. Through inverse radiation calibration, the effects of sensor differences and time changes can be eliminated, so that data acquired at different times or from different sensors have better consistency. Piecewise linear inverse radiation calibration can adapt to different ranges of radiation brightness values and provide more accurate conversion for data in different intervals. The combined use of linear inverse radiation calibration and piecewise linear inverse radiation calibration provides a flexible data correction method, and the calibration parameters can be adjusted according to actual needs. Inverse radiation calibration processing can reduce the impact of sensor noise and atmospheric interference and improve the accuracy and reliability of data. The weighted operation combines the advantages of the two inverse radiation calibration methods, and the weights can be adjusted according to different application scenarios and data characteristics to obtain the best radiation energy quantification value.
[0096] An exemplary implementation code is provided below:
[0097] import numpy as np
[0098] # ground_image is a two-dimensional array containing the radiance values of the ground image
[0099] # Linear inverse radiation calibration parameters
[0100] L_lambda = ... # radiance value
[0101] k = ... # Linear inverse radiation calibration parameters
[0102] n = ... # linear inverse radiation calibration order
[0103] # Piecewise linear inverse radiation calibration parameters
[0104] m = ... # number of linear segments
[0105] offsets = np.array([...])# List of offsets for the mth linear segment
[0106] gains = np.array([...]) # Gain coefficient list for the mth linear segment
[0107] thresholds = np.array([...]) # List of different linear segment thresholds
[0108] # Piecewise linear inverse radiation calibration processing
[0109] second_quantitative_value = np.zeros_like(L_lambda)
[0110] for i in range(m):
[0111] # Apply the gain and offset of the current linear segment
[0112] second_quantitative_value = np.where((L_lambda>thresholds[i])&(L_lambda<= thresholds[i+1]),
[0113] gains[i] * L_lambda + offsets[i],
[0114] second_quantitative_value)
[0115] # Weighted operation parameters
[0116] w1 = ... # Confidence weight of the first radiant energy quantization value
[0117] w2 = ... # Confidence weight of the second radiant energy quantization value (w1 + w2 = 1)
[0118] # Weighted operation
[0119] quantitative_value = w1 * first_quantitative_value + w2 * second_quantitative_value
[0120] # quantitative_value contains the quantitative value of radiation energy```
[0121] Optionally, the extracting vegetation pixels from the radiation-corrected ground image based on a set grayscale threshold includes:
[0122] Determining a grayscale threshold for extracting the vegetation pixel according to the spectral characteristics of the vegetation;
[0123] Converting the grayscale threshold into a normalized vegetation index;
[0124] Reflectance data is extracted from the ground image after the radiation correction, and matched with the normalized vegetation index to extract vegetation pixels.
[0125] To this end, the Normalized Difference Vegetation Index (NDVI) is used to reflect the health and density of vegetation. Using the NDVI allows for more accurate identification and differentiation of vegetation areas. The NDVI is a standardized index that reduces the variability of data from different sensors and under different conditions, and improves the consistency and comparability of vegetation extraction. The NDVI can be adjusted to suit various vegetation cover conditions, including dense and sparse vegetation, based on different vegetation types. Using the NDVI can help reduce the interference of non-vegetated areas (such as water bodies, urban areas, etc.) on vegetation extraction. Vegetation pixels extracted by the NDVI can be directly used in a variety of applications, such as crop monitoring, forest resource assessment, and ecological change analysis. The stability and comparability of the NDVI make it very suitable for time series analysis to monitor changes in vegetation over time. In addition, by setting the grayscale threshold considering the spectral characteristics of vegetation, pixel extraction can be more accurately targeted at the reflectance characteristics of vegetation.
[0126] An exemplary implementation code is provided below:
[0127] # radiance_corrected_image is the ground image after radiation correction
[0128] # radiance_corrected_image[NIR] and radiance_corrected_image[Red] are the radiance values of the near infrared and red bands respectively.
[0129] # Calculate the Normalized Vegetation Index (NVI)
[0130] # NVI = (NIR - Red) / (NIR + Red + ε), ε is a small constant to prevent division by zero
[0131] epsilon = 0.01 # a small constant for numerical stability
[0132] nvi = (radiance_corrected_image[NIR] - radiance_corrected_image[Red]) / (radiance_corrected_image[NIR] + radiance_corrected_image[Red]+ epsilon)
[0133] # Determine the NVI threshold to extract vegetation pixels
[0134] nvi_threshold = 0.2# Assumed threshold value, which needs to be determined according to specific circumstances in actual application
[0135] # Extract vegetation pixels based on NVI threshold
[0136] # The NVI value of vegetation pixels is usually higher than that of non-vegetation pixels
[0137] vegetation_mask = nvi>nvi_threshold
[0138] # Apply vegetation mask to reflectance data to extract reflectance data of vegetation pixels
[0139] vegetation_reflectance = radiance_corrected_image[vegetation_mask]
[0140] #vegetation_reflectance contains the reflectance data of vegetation pixels
[0141] Optionally, the calculating the grayscale correlation between the vegetation pixels based on the covariance of the grayscale difference between each vegetation pixel and its neighboring vegetation pixels includes:
[0142] Obtaining a neighborhood defined according to the window function for each vegetation pixel, and determining an average grayscale value within the neighborhood;
[0143] Based on the formula Calculate the covariance of the grayscale difference between each vegetation pixel and its neighboring vegetation pixels. represents the gray value of the i-th vegetation pixel, represents the average gray value in the second-order neighborhood centered on the i-th vegetation pixel, represents the gray value of the jth vegetation pixel in the neighborhood, represents the average gray value of all vegetation pixels in the neighborhood, Represents the covariance of the grayscale difference between the i-th vegetation pixel and its neighboring vegetation pixels;
[0144] Based on the formula Calculate the grayscale correlation between vegetation pixels. and are the standard deviations of the grayscale values of the ith vegetation pixel and all vegetation pixels in its neighborhood, represents the grayscale correlation between the ith vegetation pixel and all vegetation pixels in its neighborhood, and n is the number of vegetation pixels in the neighborhood.
[0145] To this end, by calculating the covariance of grayscale differences, we can capture subtle texture changes within the vegetation area, which is very useful for distinguishing vegetation of different types or different health states. Grayscale correlation analysis helps distinguish vegetation from non-vegetation areas, especially when the vegetation has a high similarity to the background. Covariance and correlation can be used as additional features in the classification algorithm to improve the accuracy of classification.
[0146] An exemplary implementation code is provided below:
[0147] import numpy as np
[0148] from scipy.spatial import distance
[0149] # image is an array of radiometrically corrected ground images
[0150] # vegetation_mask is a Boolean array of the same size as image, True indicates vegetation pixels
[0151] # Define window function
[0152] window_size = 3
[0153] window = np.ones((window_size, window_size))
[0154] # Calculate the average gray value in the neighborhood
[0155] neighborhood_mean = np.zeros(image.shape)
[0156] for i in range(window_size / / 2, image.shape[0] - window_size / / 2):
[0157] for j in range(window_size / / 2, image.shape[1] - window_size / / 2):
[0158] neighborhood = image[i - window_size / / 2:i + window_size / / 2 + 1,
[0159] j - window_size / / 2:j + window_size / / 2 + 1]
[0160] neighborhood_mean[i, j] = np.mean(neighborhood[vegetation_mask[i -window_size / / 2:i + window_size / / 2 + 1,
[0161] j - window_size / / 2:j + window_size / / 2 + 1]])
[0162] # Initialize covariance and correlation arrays
[0163] covariance = np.zeros(image.shape)
[0164] correlation = np.zeros(image.shape)
[0165] # Calculate covariance and correlation
[0166] for i in range(image.shape[0]):
[0167] for j in range(image.shape[1]):
[0168] if vegetation_mask[i, j]: # Ensure that the current pixel is a vegetation pixel
[0169] neighborhood = image[i - window_size / / 2:i + window_size / / 2 + 1,
[0170] j - window_size / / 2:j + window_size / / 2 + 1]
[0171] Ii = image[i, j]
[0172] mean_I = neighborhood_mean[i, j]
[0173] Ij = neighborhood[vegetation_mask[i - window_size / / 2:i + window_size / / 2 + 1,
[0174] j - window_size / / 2:j + window_size / / 2 + 1]]
[0175] # Calculate covariance
[0176] covariance[i, j] = np.cov(Ii, Ij - mean_I)[0][1]
[0177] # Calculate the standard deviation of grayscale values
[0178] std_Ii = np.std(Ii)
[0179] std_Ij = np.std(Ij)
[0180] # Calculate correlation
[0181] if std_Ii * std_Ij != 0: # prevent division by zero
[0182] correlation[i, j] = covariance[i, j] / (std_Ii * std_Ij)
[0183] # covariance and correlation contain the calculation results of covariance and correlation respectively
[0184] Optionally, generating a grayscale correlation texture feature vector according to the grayscale correlation between vegetation pixels includes:
[0185] According to the grayscale correlation between vegetation pixels, the grayscale second-order moment, entropy and contrast characteristics of vegetation pixels are calculated;
[0186] The grayscale second-order moment, entropy and contrast features of the vegetation pixel are fused to obtain a grayscale-related texture feature vector.
[0187] To this end, the second moment of grayscale, entropy, and contrast are statistics that describe image texture, which can provide detailed information about the internal structure and complexity of vegetation areas, and help to more accurately distinguish different types of vegetation and non-vegetated areas. Texture feature vectors can enhance the analysis of vegetation coverage, density, and health. Texture features can better monitor the response of vegetation to environmental changes (such as drought, pests and diseases). Texture features are robust to lighting changes, shadows, and sensor noise, which helps to maintain the consistency of vegetation extraction under different conditions. The calculation of texture features can be parallelized and is suitable for the processing of large-scale remote sensing image data. Texture features can be used to analyze the trend of vegetation changes over time, which is very important for long-term ecological monitoring and assessment.
[0188] An exemplary implementation code is provided below:
[0189] def calculate_second_order_moment(image, window_size):
[0190] # Calculate the grayscale second moment
[0191] window = np.ones((window_size, window_size)) / (window_size ** 2)
[0192] filtered_image = np.array([image * window for _ in range(image.size)]).transpose()
[0193] return np.sum(filtered_image * image)
[0194] def calculate_entropy(image, window_size):
[0195] # Calculate entropy
[0196] window = np.ones((window_size, window_size)) / (window_size ** 2)
[0197] filtered_image = np.array([image * window for _ in range(image.size)]).transpose()
[0198] probabilities = filtered_image / np.sum(filtered_image)
[0199] probabilities = probabilities[np.where(probabilities != 0)]# exclude zero probability
[0200] return -np.sum(probabilities * np.log2(probabilities))
[0201] def calculate_contrast(image, window_size):
[0202] # Calculate contrast
[0203] window = np.ones((window_size, window_size)) / (window_size ** 2)
[0204] filtered_image = np.array([image * window for _ in range(image.size)]).transpose()
[0205] mean_intensity = np.sum(filtered_image, axis=0)
[0206] variance = np.sum((filtered_image - mean_intensity) ** 2) / (image.size - 1)
[0207] return np.sqrt(variance)
[0208] # ground_image is the ground image after radiation correction
[0209] # vegetation_mask is a Boolean array indicating the location of vegetation pixels
[0210] # window_size is the defined neighborhood size
[0211] # Calculate each feature
[0212] second_order_moment = calculate_second_order_moment(ground_image,window_size)
[0213] entropy = calculate_entropy(ground_image, window_size)
[0214] contrast = calculate_contrast(ground_image, window_size)
[0215] # Fusion features into texture feature vector
[0216] texture_feature_vector = np.array([second_order_moment, entropy,contrast])
[0217] # texture_feature_vector contains the grayscale related texture feature vector
[0218] Optionally, the calculating the grayscale second-order moment, entropy and contrast characteristics of the vegetation pixels according to the grayscale correlation between the vegetation pixels includes:
[0219] Based on the formula , calculate the second-order moment of the grayscale of vegetation pixels, represents the grayscale correlation between the i-th vegetation pixel and all vegetation pixels in its neighborhood. Indicates all The average value of indicates the average degree of grayscale correlation. represents the total number of vegetation pixels, Represents the second-order moment of the gray level of vegetation pixels;
[0220] Based on the formula , calculate the entropy of vegetation pixels, The grayscale correlation is The probability of grayscale correlation The frequency of divided by the total number of vegetation pixels, Represents the entropy of vegetation pixels;
[0221] Based on the formula , calculate the contrast characteristics of vegetation pixels, Indicates that the grayscale correlation value is and The probability of the pixel pair appearing is Represents the contrast characteristics of vegetation pixels.
[0222] To this end, the second moment of grayscale provides information about the variance of the grayscale distribution of vegetation pixels, which helps to describe the texture complexity of vegetation areas. Entropy measures the uncertainty of the grayscale correlation of vegetation pixels and provides a quantitative indicator for the heterogeneity of vegetation areas. Contrast features emphasize the significance of grayscale differences between vegetation pixels, which helps to distinguish vegetation types with different texture characteristics. These statistical features are robust to changes in illumination, partial shadows, etc. in natural environments, and can provide stable vegetation descriptions under different conditions. Grayscale second moment, entropy, and contrast features can enhance the ability of pattern recognition algorithms to distinguish different vegetation patterns, and can be calculated at different spatial scales, which helps to understand the performance of vegetation texture at different scales. By calculating these features, the direct processing of raw image data can be reduced, thereby improving the efficiency of data processing.
[0223] An exemplary implementation code is provided below:
[0224] # gray_correlation contains the grayscale correlation value between the vegetation pixel and all vegetation pixels in its neighborhood
[0225] # num_vegetation_pixels is the total number of vegetation pixels
[0226] # Grayscale second order moment
[0227] gray_second_moment = np.sum((gray_correlation - np.mean(gray_correlation))**2) / num_vegetation_pixels
[0228] # Calculate entropy
[0229] #Calculate the frequency of each grayscale correlation value
[0230] histogram, _ = np.histogram(gray_correlation, bins=range(1, int(num_vegetation_pixels) + 1), density=True)
[0231] # Calculate entropy
[0232] entropy = -np.sum(histogram * np.log2(histogram + np.finfo(float).eps)) # add a small constant to avoid taking the logarithm of zero
[0233] # Calculate contrast features
[0234] # Contrast feature
[0235] contrast_feature = np.ptp(gray_correlation)# ptp is the abbreviation of Peak to Peak, which means the difference between the maximum and minimum values
[0236] # Merge these features into a feature vector
[0237] texture_feature_vector = np.array([gray_second_moment, entropy,contrast_feature])
[0238] Optionally, the grayscale second-order moment, entropy and contrast features of the vegetation pixel are fused to obtain a grayscale-related texture feature vector, including:
[0239] Based on the formula , The grayscale second-order moment, entropy and contrast features are normalized to obtain normalized grayscale second-order moment eigenvalues, entropy eigenvalues and contrast eigenvalues, represents the value of the gray second moment, entropy or contrast feature of the i-th vegetation pixel, is the total number of vegetation pixels, represents the mean of the gray second moment or entropy or contrast characteristics of all vegetation pixels, represents the standard deviation of the grayscale second-order moment or entropy or contrast characteristics of all vegetation pixels, Represents the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, or contrast eigenvalue;
[0240] Based on the formula , , the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue are fused to obtain the grayscale-related texture eigenvector. represents the concatenated feature vectors, , , They represent the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue, respectively. Represents the weight vector, including , respectively correspond to the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue, Represents the grayscale-related texture feature vector.
[0241] To this end, normalization can eliminate the dimensional effects between different features, making the eigenvalues at the same level, which helps to improve the stability and consistency of subsequent processing steps. Normalized data can improve the performance of distance-based algorithms (such as clustering and classification) because they are sensitive to data scaling. After normalization, different features can be directly compared in terms of their contribution to texture description, which helps to more accurately identify and classify vegetation types. Normalized feature vectors can improve the generalization ability of machine learning models and reduce dependence on data distribution. By adjusting weights, the relative importance of different features in the final texture feature vector can be optimized to meet specific analysis needs. Normalization helps to reduce the impact of outliers, thereby improving the robustness of feature vectors to noise and changing conditions. Normalized feature vectors simplify the feature selection process because all features are adjusted to a similar scale. Normalization can reduce computational complexity, especially when processing large-scale data. Texture feature vectors that fuse multiple normalized features can provide a more comprehensive description of vegetation and help with complex image analysis tasks.
[0242] An exemplary implementation code is provided below:
[0243] import numpy as np
[0244] # features is a two-dimensional array, where each row represents a vegetation pixel and each column represents the grayscale second-order moment, entropy and contrast features.
[0245] # Calculate the characteristic mean and standard deviation of all vegetation pixels
[0246] mean_values = np.mean(features, axis=0)
[0247] std_values = np.std(features, axis=0)
[0248] # Normalize each feature
[0249] normalized_features = (features - mean_values) / std_values
[0250] # weights is a weight vector whose elements correspond to the weights of the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue
[0251] weights = np.array([w1, w2, w3]) # w1, w2, w3 are predetermined weights, and w1 +w2 + w3 = 1
[0252] # Perform weighted summation on the normalized eigenvalues to obtain the grayscale-related texture feature vector
[0253] texture_feature_vector = np.dot(normalized_features, weights)
[0254] # texture_feature_vector contains the grayscale-related texture feature vector of each vegetation pixel
[0255] Optionally, the performing image segmentation on the ground image to obtain a plurality of image blocks, and calculating the difference distribution of pixel values inside each image block, includes:
[0256] Based on a region growing multi-scale segmentation algorithm, the ground image is segmented to obtain a plurality of image blocks;
[0257] Based on the regional similarity algorithm, the similarity between several image blocks is calculated and the image blocks with similarity greater than the set threshold are merged to obtain the image blocks to be processed, so as to determine the difference distribution of the internal pixel values of each image block to be processed by calculating the histogram.
[0258] To this end, the region growing algorithm can segment the image by gradually growing similar regions, which can more accurately identify vegetation areas. The region growing algorithm retains the detailed information of the image during the segmentation process, which helps to understand the characteristics of the vegetation area more carefully in the subsequent analysis. The regional similarity algorithm can identify and merge visually similar image blocks, thereby improving the consistency of the image blocks. Multi-scale segmentation can adapt to vegetation areas of different sizes in the image, which helps to process vegetation of different densities and distributions. By merging image blocks with similarity above the threshold, the amount of calculation in the subsequent processing steps can be reduced and the processing efficiency can be improved. By calculating the histogram to determine the differential distribution of pixel values inside the image block, the texture characteristics of the image block can be better understood. It has a certain degree of robustness to changes in illumination, noise, and image quality, which helps to maintain the stability of the segmentation results under different conditions.
[0259] An exemplary implementation code is provided below:
[0260] # ground_image is the ground image
[0261] #Use region growing algorithm to perform image segmentation
[0262] # segmented_image = cv2.pyrMeanShiftFiltering(ground_image, 5, 5)
[0263] #Calculate the similarity between several image blocks
[0264] #Calculate the color histogram similarity between image blocks
[0265] #Define a function to calculate the histogram
[0266] def calculate_histogram(image, bins):
[0267] hist = cv2.calcHist([image], [0], None, [bins], [0, 256])
[0268] return hist
[0269] # Define a function to calculate the similarity between two histograms (e.g. using Euclidean distance)
[0270] def calculate_similarity(hist1, hist2):
[0271] return np.linalg.norm(hist1 - hist2)
[0272] # List of segmented image blocks
[0273] #Use the output of the region growing algorithm as the image block
[0274] image_blocks = segment_image_to_blocks(segmented_image)
[0275] # Calculate the histogram of each image block
[0276] histograms = [calculate_histogram(block, bins=32) for block in image_blocks]
[0277] #Merge image blocks whose similarity is greater than the set threshold
[0278] threshold = 0.5 # Assumed similarity threshold
[0279] merged_blocks = []
[0280] for i, hist_i in enumerate(histograms):
[0281] merged = False
[0282] for j, merged_block in enumerate(merged_blocks):
[0283] similarity = calculate_similarity(hist_i, merged_block['histogram'])
[0284] if similarity <threshold:
[0285] merged_blocks[j]['histogram']+= hist_i
[0286] merged_blocks[j]['area']+= 1
[0287] merged = True
[0288] break
[0289] if not merged:
[0290] merged_blocks.append({'histogram': hist_i, 'area': 1})
[0291] # 4. Calculate the difference distribution of internal pixel values for each image block to be processed
[0292] #Calculate the histogram of the merged image block
[0293] for block in merged_blocks:
[0294] block['histogram'] = block['histogram'] / block['area']# Normalize thehistogram
[0295] Optionally, the step of calculating the difference distribution of pixel values within all image blocks based on the constructed gray level co-occurrence matrix to generate a difference-correlated texture feature vector includes:
[0296] Based on the constructed gray-level co-occurrence matrix, the difference distribution of the internal pixel values of all image blocks is calculated, and the distance adjacency distribution characteristics of the pixel values in space and the angle adjacency distribution characteristics of the pixel values are calculated;
[0297] The inter-pixel distance adjacency distribution features and the inter-pixel angle adjacency distribution features are fused to obtain a differential correlation texture feature vector.
[0298] To this end, the difference distribution of pixel values calculated based on the gray-level co-occurrence matrix can provide rich information about the image texture, including the uniformity, directionality, and roughness of the texture. By considering the distance and angle between pixels, more complex spatial relationships in the image can be captured, thereby enhancing the expressiveness of the features. The differential correlation texture feature vector can be used as a powerful feature for image segmentation and classification tasks, which helps to improve the accuracy of these tasks. The analysis of the distance and angle between pixels helps to identify and distinguish areas with complex texture structures. The pixel distance adjacency distribution features and the pixel angle adjacency distribution features are robust to changes in illumination, noise, and image quality. The pixel distance adjacency distribution features and the pixel angle adjacency distribution features can be calculated at different scales, which helps to understand the performance of image texture at different scales.
[0299] An exemplary implementation code is provided below:
[0300] import numpy as np
[0301] from skimage.feature import greycomatrix, greycoprops
[0302] def calculate_glcm(image, distances, angles, levels, symmetric=True, return_mean_pure=True):
[0303] Calculate gray-level co-occurrence matrix and texture features
[0304] glcm = greycomatrix(image, distances=distances, angles=angles, levels=levels,
[0305] symmetric=symmetric, return_mean_pure=return_mean_pure)
[0306] # Calculate texture features
[0307] contrast = greycoprops(glcm, 'contrast')
[0308] dissimilarity = greycoprops(glcm, 'dissimilarity')
[0309] homogeneity = greycoprops(glcm, 'homogeneity')
[0310] correlation = greycoprops(glcm, 'correlation')
[0311] energy = greycoprops(glcm, 'energy')
[0312] return np.concatenate((contrast.flatten(), dissimilarity.flatten(),
[0313] homogeneity.flatten(), correlation.flatten(), energy.flatten()))
[0314] # ground_image is the ground image
[0315] # Define the calculation parameters
[0316] distances = [1]
[0317] angles = [0, np.pi / 4, np.pi / 2, 3*np.pi / 4]
[0318] levels = 256
[0319] glcm_features = calculate_glcm(ground_image, distances, angles,levels)
[0320] # glcm_features contains the texture feature vectors of all image blocks
[0321] In this example, the greycomatrix and greycoprops functions in the skimage library are used to calculate the gray-level co-occurrence matrix and texture features. The greycomatrix function is used to calculate the distance adjacency distribution features between pixels and the angle adjacency distribution features between pixels given the distance and angle, while the greycoprops function is used to extract specific texture features such as contrast, dissimilarity, uniformity, and correlation.
[0322] Optionally, the gray level co-occurrence matrix constructed based on the calculation of the difference distribution of the internal pixel values of all image blocks, the calculation of the inter-pixel distance adjacency distribution characteristics and the inter-pixel angle adjacency distribution characteristics of the pixel values in space, includes:
[0323] The constructed gray-level co-occurrence matrix samples all image blocks according to the set sampling step size and sampling angle to calculate the difference distribution of internal pixel values, so as to obtain the spatial adjacency distribution characteristics of pixel distance and pixel angle.
[0324] To this end, by considering the distance and angle between pixels, the spatial relationship of pixels in the image can be analyzed in more detail, thereby providing richer texture information. The adjacent distribution features of distance between pixels and the adjacent distribution features of angle between pixels can describe the second-order statistical characteristics of the image, including the uniformity, roughness and directionality of the texture, which helps to describe the texture characteristics of the image more comprehensively. The adjacent distribution features of distance between pixels and the adjacent distribution features of angle between pixels are robust to changes in illumination, shadows and image noise, which helps to maintain the stability of features under different conditions. By changing the sampling step size and angle, images can be analyzed at different scales, which helps to understand the texture changes of images at different scales.
[0325] An exemplary implementation code is provided below:
[0326] import numpy as np
[0327] from skimage.feature import greycomatrix
[0328] # ground_image is the grayscale image that has been loaded
[0329] # distances is an array of distances between pixels
[0330] # angles is an array of angles between pixels
[0331] # Set the sampling step size and sampling angle
[0332] distances = [1]
[0333] angles = [0, np.pi / 4, np.pi / 2, 3*np.pi / 4]
[0334] # Construct gray-level co-occurrence matrix
[0335] glcm = greycomatrix(ground_image, distances, angles, 256, symmetric=True, return_mean_pure_path=False)
[0336] # Calculate GLCM features such as energy, contrast, uniformity and correlation
[0337] energy = np.sum(glcm, axis=1) / glcm.sum()
[0338] contrast = np.sum(glcm**2, axis=1) / glcm.sum()
[0339] homogeneity = np.sum(glcm, axis=1) / (np.sum(glcm, axis=0) * np.sum(glcm, axis=1))
[0340] correlation = np.trace(glcm) / glcm.sum()
[0341] # Combine these features into a feature vector
[0342] texture_feature_vector = np.array([energy.flatten(), contrast.flatten(), homogeneity.flatten(), correlation.flatten()])
[0343] # texture_feature_vector contains texture features calculated based on GLCM
[0344] Optionally, the fusing the inter-pixel distance adjacency distribution features and the inter-pixel angle adjacency distribution features to obtain a differential correlation texture feature vector includes:
[0345] Aligning the inter-pixel distance adjacency distribution features and the inter-pixel angle adjacency distribution features;
[0346] The aligned pixel distance adjacent distribution features and the pixel angle adjacent distribution features are subjected to dot product operation to obtain the differential correlation texture feature vector.
[0347] To this end, by fusing the two features, the texture characteristics of the image can be more fully described, including the smoothness, roughness, and directionality of the texture. The fused feature vector may provide better discrimination between different vegetation types or vegetation of different health conditions. The fused feature vector is more robust to image noise, illumination changes, and sensor differences. Through the fusion process, the number of features that need to be considered separately can be reduced, simplifying feature selection and subsequent processing steps. The fused feature vector can be applied at different scales, which helps to understand the performance of image texture at different scales.
[0348] An exemplary implementation code is provided below:
[0349] import numpy as np
[0350] # distance_features and angle_features are the pixel distance and angle features extracted from the image block
[0351] # These features are extracted from the gray-level co-occurrence matrix and have the same length
[0352] # Align the adjacent distribution features of distance between pixels and the adjacent distribution features of angle between pixels
[0353] # Use dot product operation for fusion
[0354] #Perform dot product operation
[0355] distance_features_float = distance_features.astype(np.float64)
[0356] angle_features_float = angle_features.astype(np.float64)
[0357] # Perform dot product operation on the aligned features
[0358] dot_product = np.dot(distance_features_float, angle_features_float)
[0359] # Use the dot product result as an element of the differential related texture feature vector
[0360] #Fusion Strategy
[0361] differential_correlation_texture_feature_vector = np.array([dot_product])
[0362] Optionally, the step of fusing the grayscale-related texture feature vector and the difference-related texture feature vector to obtain a joint texture feature vector comprises:
[0363] According to the probability distribution of the grayscale-related texture feature vector and the probability distribution of the difference-related texture feature vector, respectively calculating the entropy of the grayscale-related texture feature vector and the difference-related texture feature vector;
[0364] Based on the entropy weight method, determining respective fusion weights according to the entropies corresponding to the grayscale-related texture feature vector and the difference-related texture feature vector respectively;
[0365] Based on the respective fusion weights of the grayscale-related texture feature vector and the difference-related texture feature vector, the grayscale-related texture feature vector and the difference-related texture feature vector are weighted-fused to obtain a joint texture feature vector.
[0366] To this end, the entropy weight method can help determine the importance of each feature vector, thereby optimizing the final feature representation. The weight is calculated based on the entropy of the data itself. This method is data-driven and reduces human subjectivity. Through weighted fusion, the ability to distinguish different vegetation types or states can be enhanced. Considering the uncertainty and information content of the features, the entropy weight method can help reduce the impact of noise and irrelevant features.
[0367] An exemplary implementation code is provided below:
[0368] import numpy as np
[0369] # gray_texture_features and diff_texture_features are two feature vectors
[0370] # They represent grayscale-related texture features and difference-related texture features respectively
[0371] # Calculate the probability distribution of each eigenvalue
[0372] def calculate_probability_distribution(features):
[0373] features = features.flatten() # Ensure that features are one-dimensional
[0374] unique_values, counts = np.unique(features, return_counts=True)
[0375] probabilities = counts / features.size
[0376] return unique_values, probabilities
[0377] # Calculate entropy
[0378] def calculate_entropy(probabilities):
[0379] return -np.sum(probabilities * np.log2(probabilities + np.finfo(float).eps))
[0380] # Calculate entropy weight
[0381] def calculate_weight(entropy):
[0382] return 1 - entropy # Entropy weight is 1 minus entropy
[0383] # Calculate the probability distribution and entropy of the eigenvector
[0384] gray_unique_values, gray_probabilities = calculate_probability_distribution(gray_texture_features)
[0385] gray_entropy = calculate_entropy(gray_probabilities)
[0386] gray_weight = calculate_weight(gray_entropy)
[0387] diff_unique_values, diff_probabilities = calculate_probability_distribution(diff_texture_features)
[0388] diff_entropy = calculate_entropy(diff_probabilities)
[0389] diff_weight = calculate_weight(diff_entropy)
[0390] # Make sure the weights add up to 1
[0391] total_weight = gray_weight + diff_weight
[0392] gray_weight / = total_weight
[0393] diff_weight / = total_weight
[0394] # Weighted fusion feature vector
[0395] combined_texture_feature_vector = gray_weight * gray_texture_features+ diff_weight * diff_texture_features
[0396] # combined_texture_feature_vector is the combined texture feature vector after fusion
[0397] Optionally, the extracting features of the ground image according to the joint texture feature vector to obtain texture features includes:
[0398] According to the joint texture feature vector, based on the constructed wavelet basis, the ground image is subjected to non-subsampled wavelet transform to obtain a feature coefficient matrix;
[0399] The variances of different sub-bands of the feature coefficient matrix are calculated and the calculated variances are concatenated to obtain texture features.
[0400] To this end, the wavelet transform can capture both local details and global information of the image. Through the wavelet transform, the features of the image can be extracted from different directions and scales, increasing the diversity of features. The wavelet transform can adapt to local changes in the image and has good adaptability to vegetation areas with different textures. The wavelet transform has good denoising performance and can reduce the impact of noise on texture feature extraction. The non-subsampled wavelet transform can reduce the amount of calculation and improve the efficiency of feature extraction. Variance is a statistic that measures energy distribution. By selecting the variance of different sub-bands, the most useful features for the analysis task can be flexibly selected.
[0401] An exemplary implementation code is provided below:
[0402] import numpy as np
[0403] import pywt
[0404] # ground_image is the ground image
[0405] # texture_feature_vector is the joint texture feature vector
[0406] # Choose a wavelet basis, for example 'db1', which means Daubechies wavelet, filter length is 1
[0407] wavelet = 'db1'
[0408] # Perform non-subsampled wavelet transform on the image
[0409] #Use two-dimensional wavelet transform and only perform one layer of transformation
[0410] coefficients = pywt.dwtn(ground_image, wavelet, mode='symmetric')
[0411] # Calculate the variance of different subbands of the characteristic coefficient matrix
[0412] #The variance of all subbands (horizontal, vertical, diagonal and approximate) will be calculated
[0413] variances = [np.var(coefficients[band]) for band in range(coefficients.shape[0])]
[0414] # Concatenate the calculated variances to get the texture features
[0415] texture_features = np.concatenate(variances)
[0416] # texture_features contains the texture features obtained based on wavelet transform
[0417] Optionally, extracting a vegetation area from the ground image according to the texture feature includes:
[0418] Calculating a Laws texture measure vector according to the texture features;
[0419] Performing cluster analysis on the Laws texture measurement vector to determine the vegetation area seed point;
[0420] Region growing is performed based on the vegetation region seed points to extract the vegetation region from the ground image.
[0421] To this end, the Laws texture measure, which can capture the subtle texture features of the image, helps to identify vegetation areas more accurately. By clustering the texture features, different texture patterns in the image can be identified, including vegetation and non-vegetation areas, thereby improving the robustness of vegetation extraction. Combining the Laws texture measure and the region growing algorithm can more accurately define the boundaries of the vegetation area.
[0422] An exemplary implementation code is provided below:
[0423] import numpy as np
[0424] import cv2
[0425] from sklearn.cluster import KMeans
[0426] # ground_image is the ground image
[0427] # texture_features is the texture feature vector
[0428] # 1. Calculate the Laws texture measure vector
[0429] laws_texture = cv2.Laplacian(ground_image, cv2.CV_64F)
[0430] laws_texture = cv2.convertScaleAbs(laws_texture) # Convert to 8-bit image
[0431] #Cluster analysis of Laws texture measurement vectors to determine the seed points of vegetation areas
[0432] # Convert the Laws texture measure to a 1D array for clustering
[0433] laws_texture_flat = laws_texture.ravel()
[0434] # Use KMeans for clustering analysis
[0435] kmeans = KMeans(n_clusters=2, random_state=0).fit(laws_texture_flat.reshape(-1, 1))
[0436] # Remap the cluster labels to the 2D shape of the image
[0437] cluster_labels = kmeans.labels_.reshape(ground_image.shape[:2])
[0438] # Determine the seed point of the vegetation area (cluster center 1 is the vegetation area)
[0439] seed_points = (cluster_labels == 1).astype(np.uint8) * 255
[0440] # Perform region growing based on vegetation region seed points to extract vegetation regions from ground images
[0441] # Define the termination conditions and criteria for region growing
[0442] criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100,0.001)
[0443] # Apply region growing algorithm
[0444] ret, region_grow = cv2.regionGrow(seed_points, None, criteria)
[0445] # region_grow contains the vegetation regions extracted based on the region growing algorithm
[0446] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A method for extracting vegetation areas from ground images based on texture features, characterized in that: include: Acquire ground imagery; Extracting vegetation pixels from the ground image and calculating the grayscale correlation between the vegetation pixels; According to the grayscale correlation between the vegetation pixels, a grayscale correlation texture feature vector is generated; Performing image segmentation on the ground image to obtain a plurality of image blocks, and calculating the difference distribution of pixel values within each image block; Based on the constructed gray-level co-occurrence matrix, the difference distribution of the internal pixel values of all image blocks is calculated to generate the differential correlation texture feature vector; fusing the grayscale-related texture feature vector and the difference-related texture feature vector to obtain a joint texture feature vector; According to the joint texture feature vector, feature extraction is performed on the ground image to obtain texture features; Extracting vegetation areas from the ground image according to the texture features; The step of extracting vegetation pixels from the ground image and calculating the grayscale correlation between the vegetation pixels includes: Extracting vegetation pixels from the ground image based on a set grayscale threshold; Based on the covariance of the grayscale difference between each vegetation pixel and its neighboring vegetation pixels, the grayscale correlation between the vegetation pixels is calculated; The step of extracting vegetation pixels from the ground image based on the set grayscale threshold includes: Based on the formula , convert the pixel value of each pixel point on the ground image into a radiation brightness value, is the radiance value, is the pixel value, is the gain coefficient of the vegetation spectral band, is the solar spectral irradiance, is the solar zenith angle, is the atmospheric path radiation correction factor; Performing radiation correction on the ground image according to the radiation brightness value corresponding to each pixel point on the ground image; Extracting vegetation pixels from the radiation-corrected ground image based on a set grayscale threshold; The step of performing radiation correction on the ground image according to the radiation brightness value corresponding to each pixel point on the ground image includes: Performing inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding radiation energy quantization value; Generate a radiation-corrected ground image based on the quantized value of radiation energy corresponding to each pixel point on the ground image; The inverse radiation calibration process is performed on the radiation brightness value corresponding to each pixel point on the ground image to obtain the corresponding radiation energy quantization value, including: Based on the formula Performing linear inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding first radiation energy quantization value, is the radiance value, is the linear inverse radiation calibration parameter, is the linear inverse radiation calibration order, represents a first quantized value of radiation energy; Based on the formula Perform piecewise linear inverse radiation calibration processing on the radiation brightness value corresponding to each pixel point on the ground image to obtain a corresponding second radiation energy quantization value, is the radiance value, and Respectively represent the offset and gain coefficient in the Mth linear segment, are the thresholds for different linear segments, represents the second radiant energy quantization value, and the linear segment represents the value obtained by dividing all radiant brightness values into multiple intervals according to different linear segment thresholds; Based on the formula performing a weighted operation on the first radiation energy quantization value and the second radiation energy quantization value, and using the result of the weighted operation as the corresponding radiation energy quantization value, represents the first quantized value of radiation energy, represents the second quantized value of radiation energy, and They represent the confidence weights, + =1; The step of fusing the grayscale-related texture feature vector and the difference-related texture feature vector to obtain a joint texture feature vector includes: According to the probability distribution of the grayscale-related texture feature vector and the probability distribution of the difference-related texture feature vector, respectively calculating the entropy of the grayscale-related texture feature vector and the difference-related texture feature vector; Based on the entropy weight method, determining respective fusion weights according to the entropies corresponding to the grayscale-related texture feature vector and the difference-related texture feature vector respectively; Based on the respective fusion weights of the grayscale-related texture feature vector and the difference-related texture feature vector, weighted fusion is performed on the grayscale-related texture feature vector and the difference-related texture feature vector to obtain a joint texture feature vector; The step of extracting features from the ground image to obtain texture features according to the joint texture feature vector includes: According to the joint texture feature vector, based on the constructed wavelet basis, the ground image is subjected to non-subsampled wavelet transform to obtain a feature coefficient matrix; Calculating the variances of different sub-bands of the feature coefficient matrix and concatenating the calculated variances to obtain texture features; The step of extracting the vegetation area from the ground image according to the texture feature includes: Calculating a Laws texture measure vector according to the texture features; Performing cluster analysis on the Laws texture measurement vector to determine the vegetation area seed point; Region growing is performed based on the vegetation region seed points to extract the vegetation region from the ground image.
2. The method according to claim 1, characterized in that The step of extracting vegetation pixels from the radiation-corrected ground image based on the set grayscale threshold includes: Determining a grayscale threshold for extracting the vegetation pixel according to the spectral characteristics of the vegetation; Converting the grayscale threshold into a normalized vegetation index; Reflectance data is extracted from the ground image after the radiation correction, and matched with the normalized vegetation index to extract vegetation pixels.
3. The method according to claim 2, characterized in that The grayscale correlation between the vegetation pixels is calculated based on the covariance of the grayscale difference between each vegetation pixel and its neighboring vegetation pixels, including: Obtaining a neighborhood defined according to the window function for each vegetation pixel, and determining an average grayscale value within the neighborhood; Based on the formula Calculate the covariance of the grayscale difference between each vegetation pixel and its neighboring vegetation pixels. represents the gray value of the i-th vegetation pixel, represents the average gray value in the second-order neighborhood centered on the i-th vegetation pixel, represents the gray value of the jth vegetation pixel in the neighborhood, represents the average gray value of all vegetation pixels in the neighborhood, Represents the covariance of the grayscale difference between the i-th vegetation pixel and its neighboring vegetation pixels; Based on the formula Calculate the grayscale correlation between vegetation pixels. and are the standard deviations of the grayscale values of the ith vegetation pixel and all vegetation pixels in its neighborhood, represents the grayscale correlation between the ith vegetation pixel and all vegetation pixels in its neighborhood, and n is the number of vegetation pixels in the neighborhood.
4. The method according to claim 1, characterized in that: The step of generating a grayscale correlation texture feature vector according to the grayscale correlation between the vegetation pixels comprises: According to the grayscale correlation between vegetation pixels, the grayscale second-order moment, entropy and contrast characteristics of vegetation pixels are calculated; The grayscale second-order moment, entropy and contrast features of the vegetation pixel are integrated to obtain a grayscale-related texture feature vector; The step of calculating the grayscale second-order moment, entropy and contrast characteristics of vegetation pixels according to the grayscale correlation between vegetation pixels includes: Based on the formula , calculate the second-order moment of the grayscale of vegetation pixels, represents the grayscale correlation between the i-th vegetation pixel and all vegetation pixels in its neighborhood. Indicates all The average value of indicates the average degree of grayscale correlation. represents the total number of vegetation pixels, Represents the second-order moment of grayscale of vegetation pixels; Based on the formula , calculate the entropy of vegetation pixels, The grayscale correlation is The probability of grayscale correlation The frequency of divided by the total number of vegetation pixels, Represents the entropy of vegetation pixels; Based on the formula , calculate the contrast characteristics of vegetation pixels, Indicates that the grayscale correlation value is and The probability of the pixel pair appearing is Represents the contrast characteristics of vegetation pixels.
5. The method according to claim 4, characterized in that The grayscale second-order moment, entropy and contrast features of the vegetation pixel are fused to obtain a grayscale-related texture feature vector, including: Based on the formula , The grayscale second-order moment, entropy and contrast features are normalized to obtain normalized grayscale second-order moment eigenvalues, entropy eigenvalues and contrast eigenvalues, represents the value of the gray second moment, entropy or contrast feature of the i-th vegetation pixel, is the total number of vegetation pixels, represents the mean of the gray second moment or entropy or contrast characteristics of all vegetation pixels, represents the standard deviation of the grayscale second-order moment or entropy or contrast characteristics of all vegetation pixels, Represents the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, or contrast eigenvalue; Based on the formula , , the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue are fused to obtain the grayscale-related texture eigenvector. represents the concatenated feature vectors, , , They represent the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue, respectively. Represents the weight vector, including , respectively correspond to the normalized grayscale second-order moment eigenvalue, entropy eigenvalue, and contrast eigenvalue, Represents the grayscale-related texture feature vector.
6. The method according to claim 1, characterized in that The step of segmenting the ground image to obtain a plurality of image blocks and calculating the difference distribution of pixel values within each image block includes: Based on a region growing multi-scale segmentation algorithm, the ground image is segmented to obtain a plurality of image blocks; Based on the regional similarity algorithm, the similarity between several image blocks is calculated and the image blocks with similarity greater than the set threshold are merged to obtain the image blocks to be processed, so as to determine the difference distribution of the internal pixel values of each image block to be processed by calculating the histogram.
7. The method according to claim 1, characterized in that The gray-level co-occurrence matrix constructed based on the above method calculates the difference distribution of the internal pixel values of all image blocks and generates the difference-related texture feature vector, including: Based on the constructed gray-level co-occurrence matrix, the difference distribution of the internal pixel values of all image blocks is calculated, and the distance adjacency distribution characteristics of the pixel values in space and the angle adjacency distribution characteristics of the pixel values are calculated; The inter-pixel distance adjacency distribution features and the inter-pixel angle adjacency distribution features are fused to obtain a differential correlation texture feature vector; The gray-level co-occurrence matrix constructed based on the above method calculates the difference distribution of the internal pixel values of all image blocks, calculates the spatial adjacency distribution characteristics of the pixel values, and calculates the adjacency distribution characteristics of the pixel distances and the angles between the pixels, including: The constructed gray-level co-occurrence matrix samples all image blocks according to the set sampling step size and sampling angle to calculate the difference distribution of the internal pixel values, so as to obtain the spatial adjacency distribution characteristics of the pixel values and the adjacency distribution characteristics of the pixel angles. The step of fusing the inter-pixel distance adjacency distribution features and the inter-pixel angle adjacency distribution features to obtain a differential correlation texture feature vector includes: Aligning the inter-pixel distance adjacency distribution features and the inter-pixel angle adjacency distribution features; The aligned pixel distance adjacent distribution features and the pixel angle adjacent distribution features are subjected to dot product operation to obtain the differential correlation texture feature vector.
Citation Information
Patent Citations
Radiation correction method and device for eliminating vignetting and stripes of noctilucent remote sensing image
CN115690603A
Cultivated land classification method and system based on remote sensing image and fuzzy recognition
CN116188880A