Skip to content

ECOPOM/Leaf_Area_Scanner_LA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Leaf and Target Area Measurement (Computer Vision Analysis)

Overview

This repository contains a Python script designed as a computer vision pipeline to measure the total area of leaves and count/measure distinct red target objects present in a set of images.

The script leverages the OpenCV library for robust image processing and color-based segmentation, and Pandas for structured data storage and analysis. It processes images sequentially, isolates the desired objects (leaves and targets), calculates their real-world areas in square centimeters ($\text{cm}^2$), and outputs the results to both visual plots and CSV files.


Prerequisites

To run the analysis script, you will need:

  • Python (3.x)
  • The following Python libraries:
    • opencv-python (cv2)
    • numpy
    • pandas
    • matplotlib
    • pathlib
  • A global constant IMAGE_FILES_PATH (the file path to the directory containing your input images).
  • A global constant A3_SHEET_AREA (the known real-world area, in $\text{cm}^2$, of the background sheet used for scaling—e.g., $623.7 \text{ cm}^2$ for an A3 sheet).

How to take the images

It is important to keep the leaves separated during the scanning so that the system can isolate them (if they are overlapped the system sees these leaves as one).


How the Script Works (Analysis Pipeline)

The core script executes a recursive process over all .jpg files in the input folder:

1. Image Conversion and Scaling

  • Color Space: Images are converted from BGR to the HSV (Hue, Saturation, Value) color space, which is ideal for isolating colors regardless of lighting variations.
  • Spatial Resolution: A conversion factor (pixel_spatial_res_cm) is calculated using the known A3_SHEET_AREA to accurately translate pixel areas into real-world square centimeters.

2. Segmentation using Color Masking

The script uses predefined HSV ranges to create binary masks that isolate key image components:

  • Red Targets: Identified using dual HSV ranges to account for the wrap-around nature of the red color on the Hue scale. In this version the red square has known area and it is used to check the system error level.
  • White Background: Isolated using a high Value and low Saturation range.
  • Leaves (Foreground): Created by combining the Red Target and White Background masks into a single Background Mask, and then inverting it to find

About

Automatic calculator for leaf area for scanned images

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors