# johri-lab/automatic-leaf-infection-identifier architecture

> Architecture diagram of the GitHub repository johri-lab/automatic-leaf-infection-identifier, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/johri-lab/automatic-leaf-infection-identifier
- Repository: https://github.com/johri-lab/automatic-leaf-infection-identifier

## Overview

1. This repository is a local, Python-based desktop application for classifying leaf images as **healthy** or **infected**. The core architecture is a simple image-processing pipeline feeding a machine-learning classifier.

2. The main user entry point is **`GUIdriver.py`**. It launches the application UI and lets the user browse for an image file to analyze. The GUI layer is separate from the image-processing logic, so the interface is thin and the actual work happens in backend scripts.

3. The UI is defined by **`design.ui`** and mirrored in **`design.py`**, which strongly suggests a Qt/Qt Designer-style desktop front end. This layer handles file selection and result display, but does not contain the detection logic itself.

4. The primary processing pipeline lives in **`main.py`**. According to the README, it performs:
   - RGB image acquisition
   - RGB-to-HSI color conversion
   - green-pixel masking
   - removal of healthy leaf regions
   - segmentation of candidate diseased regions
   - extraction of numerical features for classification

5. **`classifier.py`** is the model boundary. `main.py` calls into it after feature extraction, and the README says the classifier is an **SVM** used to decide whether the leaf is infected or healthy. In architecture terms, this is the inference layer that consumes extracted features and returns the final label.

6. The repository includes a dataset artifact, **`Datasetinfectedhealthy.csv`**, which likely stores the extracted feature vectors and class labels used to train or validate the classifier. This CSV is the structured data boundary between image processing and machine learning.

7. The **`leaf sampler/`** directory is a separate dataset-generation subsystem. It contains:
   - `leafdetectionALLmix.py`
   - `leafdetectionALLsametype.py`
   
   These scripts scan image directories and generate dataset entries from source images. The README indicates one script is for mixed healthy/infected collections, and the other is for a single category.

8. The **image assets** are packaged separately from the code in **`Image Dataset/`** as zip files, and there is also a **`testimage/`** directory for sample inputs. This shows the project is organized around offline local files rather than networked data sources.

9. The system’s data flow is essentially:
   **selected leaf image → preprocessing/segmentation in `main.py` → numeric features → SVM classification in `classifier.py` → healthy/infected result shown in GUI**.

10. Packaging and environment setup are lightweight: **`requirements.txt`** defines Python dependencies, and **`setup.py`** supports installation. The repo is self-contained and does not depend on external services or a backend server.

11. In architectural terms, the important boundaries are:
   - **Presentation layer:** GUI files
   - **Image-processing layer:** `main.py`
   - **ML inference layer:** `classifier.py`
   - **Dataset preparation layer:** `leaf sampler/`
   - **Static data layer:** CSV and image archives

12. For a diagram, the key interaction to show is that the GUI is only a front end; the real computation is a local pipeline that transforms leaf imagery into features and then into a binary disease decision.

Main entry points: [`GUIdriver.py`](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/GUIdriver.py) (GUI driver), [`main.py`](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py) (Image pipeline), [`classifier.py`](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/classifier.py) (SVM model), [`Datasetinfectedhealthy.csv`](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/Datasetinfectedhealthy.csv) (Feature data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_gui_driver["GUI driver<br/>desktop entry<br/>[GUIdriver.py]"]
  node_design_ui["UI form<br/>qt layout<br/>[design.ui]"]
  node_design_py["UI code<br/>qt generated<br/>[design.py]"]
  node_setup_pkg["Package setup<br/>install config<br/>[setup.py]"]
  node_deps["Dependencies<br/>python deps<br/>[requirements.txt]"]
end

subgraph group_pipeline["Processing"]
  node_image_pipeline["Image pipeline<br/>preprocess<br/>[main.py]"]
  node_rgb_hsi(("Color convert<br/>preprocess step<br/>[main.py]"))
  node_segmentation(("Mask & segment<br/>segmentation step<br/>[main.py]"))
  node_features(("Feature vector<br/>feature extraction<br/>[main.py]"))
end

subgraph group_model["Classifier"]
  node_svm_classifier["SVM model<br/>inference<br/>[classifier.py]"]
end

subgraph group_prep["Dataset Prep"]
  node_leaf_mix["Mix sampler<br/>dataset script"]
  node_leaf_same["Single sampler<br/>dataset script"]
end

subgraph group_data["Data"]
  node_dataset_csv["Feature data<br/>csv dataset"]
  node_image_archives[("Image archives<br/>image packs")]
  node_sample_inputs[("Sample inputs<br/>test images")]
end

node_gui_driver -->|"boots UI"| node_design_py
node_design_ui -.->|"mirrors"| node_design_py
node_gui_driver -->|"send image"| node_image_pipeline
node_image_pipeline -->|"convert"| node_rgb_hsi
node_rgb_hsi -->|"mask"| node_segmentation
node_segmentation -->|"extract"| node_features
node_features -->|"infer"| node_svm_classifier
node_svm_classifier -->|"result"| node_gui_driver
node_dataset_csv -.->|"train/validate"| node_svm_classifier
node_leaf_mix -->|"builds"| node_dataset_csv
node_leaf_same -->|"builds"| node_dataset_csv
node_image_archives -->|"source"| node_leaf_mix
node_image_archives -->|"source"| node_leaf_same
node_sample_inputs -->|"input"| node_image_pipeline
node_setup_pkg -.->|"installs"| node_deps

click node_gui_driver "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/GUIdriver.py"
click node_design_ui "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/design.ui"
click node_design_py "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/design.py"
click node_image_pipeline "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py"
click node_rgb_hsi "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py"
click node_segmentation "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py"
click node_features "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py"
click node_svm_classifier "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/classifier.py"
click node_dataset_csv "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/Datasetinfectedhealthy.csv"
click node_leaf_mix "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/leaf sampler/leafdetectionALLmix.py"
click node_leaf_same "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/leaf sampler/leafdetectionALLsametype.py"
click node_image_archives "https://github.com/johri-lab/automatic-leaf-infection-identifier/tree/master/Image Dataset"
click node_sample_inputs "https://github.com/johri-lab/automatic-leaf-infection-identifier/tree/master/testimage"
click node_setup_pkg "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/setup.py"
click node_deps "https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/requirements.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gui_driver,node_design_ui,node_design_py,node_setup_pkg,node_deps toneBlue
class node_image_pipeline,node_rgb_hsi,node_segmentation,node_features toneAmber
class node_svm_classifier toneMint
class node_leaf_mix,node_leaf_same toneRose
class node_dataset_csv,node_image_archives,node_sample_inputs toneIndigo
```

## Components

### Presentation

Desktop UI and user entry point

- [GUI driver](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/GUIdriver.py): desktop entry · Launches the app and handles image selection/result display · `GUIdriver.py`
- [UI form](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/design.ui): qt layout · Qt Designer interface definition · `design.ui`
- [UI code](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/design.py): qt generated · Python mirror of the desktop form · `design.py`
- [Package setup](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/setup.py): install config · Project installation and dependency wiring · `setup.py`
- [Dependencies](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/requirements.txt): python deps · Pinned runtime requirements · `requirements.txt`

### Processing

Image preprocessing and feature extraction

- [Image pipeline](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py): preprocess · Loads leaf images and prepares them for analysis · `main.py`
- [Color convert](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py): preprocess step · RGB acquisition and RGB-to-HSI conversion · `main.py`
- [Mask & segment](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py): segmentation step · Green masking, healthy-region removal, and diseased-region segmentation · `main.py`
- [Feature vector](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/main.py): feature extraction · Produces numeric descriptors for classification · `main.py`

### Classifier

Machine-learning inference boundary

- [SVM model](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/classifier.py): inference · Consumes features and returns healthy or infected label · `classifier.py`

### Dataset Prep

Scripts that build feature datasets

- [Mix sampler](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/HEAD/leaf%20sampler/leafdetectionALLmix.py): dataset script · Generates dataset entries from mixed healthy/infected image collections · `leaf sampler/leafdetectionALLmix.py`
- [Single sampler](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/HEAD/leaf%20sampler/leafdetectionALLsametype.py): dataset script · Generates dataset entries from one category at a time · `leaf sampler/leafdetectionALLsametype.py`

### Data

Static datasets and sample inputs

- [Feature data](https://github.com/johri-lab/automatic-leaf-infection-identifier/blob/master/Datasetinfectedhealthy.csv): csv dataset · Stored feature vectors and labels · `Datasetinfectedhealthy.csv`
- [Image archives](https://github.com/johri-lab/automatic-leaf-infection-identifier/tree/HEAD/Image%20Dataset): image packs · Packaged source image datasets · `Image Dataset`
- [Sample inputs](https://github.com/johri-lab/automatic-leaf-infection-identifier/tree/master/testimage): test images · Local example images for trial runs · `testimage`

## Connections

- GUI driver → UI code: boots UI · The desktop entry point initializes the generated Qt interface
- UI form → UI code: mirrors · The UI form is mirrored into Python code
- GUI driver → Image pipeline: send image · Selected leaf images are handed to the processing pipeline
- Image pipeline → Color convert: convert · Pipeline first normalizes color space for analysis
- Color convert → Mask & segment: mask · Converted image is used for healthy-region masking and diseased-region isolation
- Mask & segment → Feature vector: extract · Segmented candidate regions are transformed into numeric features
- Feature vector → SVM model: infer · Feature vectors are classified by the SVM boundary
- SVM model → GUI driver: result · Final healthy/infected decision is returned to the UI
- Feature data → SVM model: train/validate · Structured feature data underpins the classifier model
- Mix sampler → Feature data: builds · Mixed-collection sampler writes dataset rows
- Single sampler → Feature data: builds · Single-category sampler contributes dataset rows
- Image archives → Mix sampler: source · Packaged archives provide input images for dataset generation
- Image archives → Single sampler: source · Packaged archives provide input images for dataset generation
- Sample inputs → Image pipeline: input · Local sample images can be analyzed through the main pipeline
- Package setup → Dependencies: installs · Package setup depends on project requirements
