Image Processing for Plant Health Assessment: HSV Color Range Detection

Hello everyone,

I’m working on a project to detect diseases in leaves by analyzing the color of the leaf tips. Specifically, I am using the HSV color space to detect gray or yellow-gray areas. Below are the characteristics of my images and the details of my approach:

Image Characteristics:

  1. The images mainly feature green leaves, but some leaves have yellow areas caused by disease.
  2. The background often contains yellow wood chips, which can interfere with color detection.
  3. My goal is to detect yellow-gray areas near the leaf tips to determine if the leaves are diseased.

Here is the current function I’m using for detection:

def detect_color_with_three_ranges(image, lower_hsv1, upper_hsv1, lower_hsv2, upper_hsv2, lower_hsv3, upper_hsv3, area_threshold):
    hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

    mask1 = cv2.inRange(hsv_image, lower_hsv1, upper_hsv1)
    mask2 = cv2.inRange(hsv_image, lower_hsv2, upper_hsv2)
    mask3 = cv2.inRange(hsv_image, lower_hsv3, upper_hsv3)

    combined_mask = cv2.bitwise_or(mask1, mask2)
    combined_mask = cv2.bitwise_or(combined_mask, mask3)

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    cleaned_mask = cv2.morphologyEx(combined_mask, cv2.MORPH_CLOSE, kernel)
    cleaned_mask = cv2.morphologyEx(cleaned_mask, cv2.MORPH_OPEN, kernel)

    contours, _ = cv2.findContours(cleaned_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

    diseased_area = 0
    for contour in contours:
        area = cv2.contourArea(contour)
        if area > area_threshold:
            diseased_area += area

    is_diseased = diseased_area > area_threshold
    return cleaned_mask, is_diseased

Current Challenges:

  1. Setting HSV Ranges:
  • How can I determine effective HSV ranges for detecting gray or yellow-gray areas at the leaf tips?
  • The yellow wood chips in the background are often mistaken for diseased areas. How can I effectively separate the background from the leaf?
  1. Preprocessing Suggestions:
  • Are there any preprocessing techniques (e.g., background removal or image enhancement) that can improve detection accuracy?
  1. Region of Interest:
  • I currently focus on the center region of the images to minimize background interference. Are there better methods for isolating the leaf tips for detection?
  1. Detection Goal:
  • The primary goal is to accurately identify yellow-gray areas near the leaf tips while ignoring other areas and the background.

If anyone has experience or suggestions related to HSV range adjustment, preprocessing methods, or background filtering techniques, I would greatly appreciate your help! Thank you!

1 Like

Hello, @Jean1083848, and welcome to the Python community!

Someone here may be able to offer help with this, but you could also check out the Scientific Community Image Forum.

Thank you!
I’ll look into the Scientific Community Image Forum.

1 Like

If you click on the Community Partners dropdown there, it will reveal an array of dozens of beautiful icons, including those of napari, scikit-image, and others also related to Python. Enjoy exploring that site!

1 Like

Thank you so much! This is indeed a fantastic forum website . I appreciate your guidance and will explore the Community Partners section for more tools and insights.

1 Like

We wish the best of success to you over there! Please let us know how that works out, and feel welcome to ask additional questions back here.