A comprehensive computer vision framework for analyzing rice leaf diseases using multiple approaches:
- 📊 Principal Component Analysis (PCA) for infection pattern discovery
- 🌿 Classical computer vision for disease segmentation and severity estimation
- 🤖 Deep learning models for advanced disease detection
The system processes rice leaf images and produces:
- PCA feature loadings
- spatial infection maps
- automatic leaf segmentation
- disease spot detection
- infection severity estimation
- lesion segmentation using deep learning
- disease classification
- severity heatmaps
The goal is to enhance subtle disease patterns in rice leaves that are difficult to observe in standard RGB images.
Plant diseases significantly impact global agricultural productivity, especially in rice farming.
Early disease detection helps:
- reduce crop loss
- improve yield management
- support precision agriculture
This project combines three different computer vision approaches for analyzing rice leaf infections.
Unsupervised feature analysis used to detect hidden infection patterns.
Traditional image processing methods for disease detection.
Modern deep learning models for segmentation and classification.
Together these pipelines create a complete research workflow for plant disease detection.
The framework contains three main analysis pipelines.
This pipeline reveals hidden infection patterns using Principal Component Analysis.
The rice leaf image is loaded using OpenCV and converted from BGR to RGB format.
A Gray-World assumption is applied to normalize lighting conditions.
Multiple image features are extracted.
- R
- G
- B
- ExG (Excess Green) – vegetation intensity
- ExR (Excess Red) – highlights disease regions
- NDI (Normalized Difference Index) – chlorophyll variation
- r_norm
- g_norm
- b_norm
Separates stain-like components:
- Hematoxylin
- Eosin
- DAB
(optional depending on image compatibility)
Two blurred images are generated:
- σ = 1
- σ = 2
These capture texture and spatial information.
All extracted features are:
- Flattened
- Z-score normalized
- Processed using PCA
The model extracts:
- PC1
- PC2
- PC3
These components represent the dominant patterns in the leaf image.
This pipeline performs automatic disease detection using image processing.
The leaf is isolated using HSV color thresholding.
Disease regions are detected using vegetation indices such as ExG.
Disease severity is calculated as:
severity = diseased_area / leaf_area × 100
A Random Forest classifier predicts disease type.
Example classes:
- Healthy
- Brown Spot
- Leaf Blast
A deep learning pipeline is implemented for advanced disease analysis.
Uses DeepLabV3 semantic segmentation to isolate the leaf.
Uses a U-Net CNN to detect infected regions.
Uses EfficientNet to classify leaf diseases.
Example categories:
- Healthy
- Brown Spot
- Leaf Blast
A color heatmap visualizes the infection intensity across the leaf.
The framework generates several visual outputs.
pca_loadings.png
Shows how each feature contributes to principal components.
pc1_scoremap.png pc2_scoremap.png pc3_scoremap.png
These maps highlight:
- infection regions
- chlorosis
- texture variation
pc_rgb_composite.png
Mapping:
- Red → PC1
- Green → PC2
- Blue → PC3
This creates a feature-enhanced visualization of the leaf.
Binary mask representing detected leaf area.
Detected infection regions on the leaf.
Color heatmap highlighting disease intensity.
Install required dependencies:
pip install scikit-image scikit-learn opencv-python matplotlib torch torchvision segmentation-models-pytorch
Or in Google Colab:
!pip install scikit-image scikit-learn opencv-python matplotlib torch torchvision segmentation-models-pytorch
Run one of the pipelines.
python pca_rice_leaf_analysis.py --image rice_leaf.jpg
python classical_rice_disease_detection.py
python deep_learning_rice_disease_detection.py
rice-leaf-disease-analysis/ │ ├── pca_rice_leaf_analysis.py ├── classical_rice_disease_detection.py ├── deep_learning_rice_disease_detection.py │ ├── README.md │ ├── results/ │ ├── pca_loadings.png │ ├── pc1_scoremap.png │ ├── pc2_scoremap.png │ ├── pc3_scoremap.png │ └── pc_rgb_composite.png │ └── sample_images/ └── rice_leaf_example.jpg
This framework can be used for:
- 🌾 Rice disease detection
- 🌱 Plant stress analysis
- 🧪 Agricultural research
- 📷 Image-based crop monitoring
- 🤖 Feature engineering for ML models
- 🚜 Precision agriculture
Possible enhancements:
- real-time disease detection systems
- hyperspectral imaging analysis
- Vision Transformer models
- mobile applications for farmers
- cloud-based crop monitoring platforms
- Python
- OpenCV
- Scikit-image
- Scikit-learn
- PyTorch
- segmentation-models-pytorch
- Matplotlib
- Google Colab
This project is released under the MIT License.
Developed for research in plant disease detection using computer vision and deep learning.
If you found this project useful, consider ⭐ starring the repository.