How to count the Pixels of green vegetation in the image attached below?

3 Ansichten (letzte 30 Tage)
Vijay H
Vijay H am 6 Dez. 2021
Beantwortet: Prasanna am 22 Feb. 2024
Hello everyone, i have a project regading identification of green vegeration area to calculate percentage of inversion. i have done thresholding and facing some problem. Bcause of sunlight i am not able to identify acculrately the vegetation. Even the soil is also bright in colour.

Antworten (1)

Prasanna
Prasanna am 22 Feb. 2024
Hi Vijay,
It is my understanding that you would like to calculate the number of green pixels in the image provided to calculate percentage of inversion.
To count the number of pixels with green vegetation, you can convert the image to HSV colour space, extract the hue channel, define a range of hues corresponding to green, create a binary mask of the green pixels based on the hue range, and then count the number of green pixels using the sum function.
% Read the image
image = imread('Weedafter1.jpg');
% Convert the image to the HSV color space
hsvImage = rgb2hsv(image);
% Extract the hue channel
hueChannel = hsvImage(:, :, 1);
% Define the green hue range (adjust the values as needed)
greenHueRange = [0.2 0.4];
% Create a binary mask of the green pixels
greenMask = (hueChannel >= greenHueRange(1)) & (hueChannel <= greenHueRange(2));
% Count the number of green pixels
numGreenPixels = sum(greenMask(:));
% Display the result
disp(['Number of green pixels: ' num2str(numGreenPixels)]);
Please note that the specific hue range for green may vary depending on the image and lighting conditions. You may need to adjust the values accordingly to accurately identify the green vegetation. To further improve the mask and count even more accurately, you can do the following methods:
  • Use of Multispectral Imagery: If you have access to multispectral imagery, you can use different spectral bands to better distinguish between vegetation and soil. For example, vegetation has characteristic reflectance patterns in the green, red-edge, and NIR bands.
  • Image Segmentation Techniques: Advanced image segmentation techniques like k-means clustering, Otsu's method, or mean shift clustering can be used to separate vegetation from non-vegetation areas based on their spectral signatures.
  • Shadow and Highlight Compensation: Pre-process the images to reduce the effects of shadows and highlights. Techniques such as histogram equalization or adaptive histogram equalization can help.
  • Morphological Operations: After thresholding, use morphological operations like erosion, dilation, opening, and closing to refine the areas of interest and remove noise.
  • Manual Correction: In some cases, you might need to manually correct the results after automated processing, especially if there are areas that are consistently misclassified.
You can use the following documentation for explanation on the above functions:
Hope this helps.
Regards,
Prasanna

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by