Skip to content

Image processing and computer vision pipeline that applies automated transformations and CNN training to plant leaf photos to support disease-classification.

Notifications You must be signed in to change notification settings

gkrusta/Leaffliction

Repository files navigation

Leaffliction

Overview

An image-processing and computer-vision pipeline that automatically transforms plant-leaf photos to support disease-classification workflows.

We built the system using Python, TensorFlow, Keras, PlantCV, and OpenCV, learning which image transformations and CNN model metrics produce effective visual-classification performance, achieving approx 94% prediction accuracy.

1. Analysis of the Data Set

This program will analyze a plant directory, counts all images in its subfolders, and generates bar and pie charts showing the distribution of classes.

python3 ./src/Distribution.py "./Apple"
Apple_bar_chart Apple_pie_chart

2. Image Transformation and Data Augmentation

  1. Transform a single image Displays the original and transformed versions on screen:
python3 ./src/Augmentation.py "images/leaves/Apple/Apple_healthy/image (1).JPG"

The program will: Generate and display transformed images such as:

  • Rotation
  • Horizontal flip
  • Blur
  • Contrast adjustment
  • Scaling (zoom)
  • Shear transformation transformations

  1. Process a directory If the path points to a directory, the tool detects subdirectories (if any) and performs data augmentation for each:
python3 ./src/Augmentation.py "images/leaves/"

The program will:

  • Copy original images into augmented_directory/
  • Generate additional images if a subdirectory has fewer images than the largest one
  • Preserve subdirectory structure

3. Image Transformation

The program takes source path, applies 6 transformations to the image or direcotry tree and and saves it in destination directory (in case of photo input not necessary to provide destination).

The advanced transformations may take a while so it is not recommended to use them on a big directories.

There are various possible execution ways.

transformations

Available transformations:

  • gaussian_blur
  • mask
  • negative_image
  • edges_image
  • posterize
  • sharpen
  • roi_object (advanced)
  • analyze_image (advanced)

image input:

python3 ./src/Transformation.py -src "./images/Apple/Apple_Black_rot/image (1).JPG" -dst new

python3 ./src/Transformation.py -src "./images/Apple/Apple_Black_rot/image (1).JPG" -f negative

python3 ./src/Transformation.py -src "./images/Apple/Apple_Black_rot/image (1).JPG" -f analyze --advanced

directory input:

python3 ./src/Transformation.py -src "./images/Apple" -dst transformed_apple

python3 ./src/Transformation.py -src "./images/Apple" -dst transformed_apple -f mask

python3 ./src/Transformation.py -src "./images/Apple" -dst transformed_apple -f roi --advanced

Basic transformations transformations

Advanced transformations transformations


4. Classification

4.1. Train

This program allows you to split an image dataset into training/validation sets, train a CNN using TensorFlow, and export the trained model along with the class names inside a .zip file.

python3 ./src/train.py Grape/

The Convolutional Neural Network (CNN) is composed of:

  • Rescaling layer
  • Conv2D layers
  • MaxPooling2D layer
  • Flatten layer
  • Dense layer

Training configuration:

  • Optimizer: Adam
  • Loss: sparse_categorical_crossentropy
  • Metric: accuracy

Once the training is complete, the program saves the model as a .h5 file, save the class names in a .csv file and creates a compressed ZIP file containing both files.


4.2. Predict

This program allows you to load a previously trained model (exported as a ZIP file), extract its contents, and classify a single image using the saved CNN.

python3 ./src/predict.py "Apple/apple_healthy/image (1).JPG" --model apple_model.zip

The program will: Validate the image path. Extract the model .h5 file and the class names .csv file from the provided ZIP archive. Load the trained model using TensorFlow/Keras. Run inference and compute prediction probabilities.

Example output:

Predicted class: apple_healthy. Confidence 0.97

prediction

About

Image processing and computer vision pipeline that applies automated transformations and CNN training to plant leaf photos to support disease-classification.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages