LeafColor is a project designed to analyze the color of leaves from images, with the specific goal of detecting, segmenting, and comparing leaf colors using reference charts and image processing techniques. This tool is ideal for plant biologists, agricultural researchers, or hobbyists who want to automate the assessment of leaf color for health, classification, or research purposes.
LeafColor combines Python (with OpenCV and Pillow for image processing), a web frontend (JavaScript/React), and various scientific libraries to create an end-to-end pipeline for:
- Uploading and processing leaf images
- Detecting green objects (leaves) in photographs
- Segmenting and cropping leaf areas
- Calculating average RGB color values for individual leaves
- Comparing leaf colors to reference charts or other objects
- Normalizing color data to account for lighting and background effects
- Leaf Detection & Segmentation: Uses image processing to identify and isolate leaf regions from uploaded images.
- Color Analysis: Computes the average RGB color of detected leaves, removing lighting artifacts and normalizing against background black/white regions.
- Comparison Engine: Compares the color of the selected leaf to a set of reference images, displaying similarity percentages and visual matches.
- Interactive Frontend: Allows users to upload images, view detected leaves, select a leaf for analysis, and review detailed color data and comparisons.
- Visual Feedback: Cropped images, processed data, and comparison results are displayed directly in the web interface.
- Upload an Image: Users can upload a photo containing leaves via the web app.
- Leaf Segmentation: The backend uses OpenCV to segment green objects (leaves) and isolate them from the image.
- Background Normalization: The system detects black and white background regions to correct for lighting variations.
- Color Calculation: For each segmented leaf, the average RGB color is computed.
- Comparison: The processed leaf color is compared against a set of reference images, showing the closest match and similarity score.
- Visualization: Results, including cropped leaf images, average colors, and comparison tables, are displayed interactively.
- Upload a leaf image.
- The system segments all green objects and displays cropped leaf images.
- Select a leaf to analyze; its average RGB is calculated.
- The selected leaf is compared with other reference objects; similarity scores and images are displayed.
- Review processed data and download results as needed.
- Python (main backend, image processing)
- OpenCV, Pillow (image analysis)
- Django REST API (backend communication)
- React, JavaScript (frontend interface)
- Cython, C, C++ (performance optimization in some routines)
- Matplotlib, SciPy (scientific computation)
- HTML/CSS (web interface elements)
model2/views.py
: Core logic for image upload, segmentation, RGB calculation, background normalization, and result packaging.frontend/src/pages/Profile.js
: Handles frontend logic for image upload, displaying processed results, and user interactions.venv/Lib/site-packages/
: Contains scientific libraries for color and clustering analysis (used in backend).
- Python 3.8+ installed
- Node.js and npm installed (for frontend)
- (Recommended) Use a virtual environment for Python
-
Clone the repository:
git clone https://github.com/pranavrbm/leafcolor.git cd leafcolor
-
Create and activate a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install backend dependencies:
pip install -r requirements.txt
-
Run migrations (if using Django ORM):
python manage.py migrate
-
Start the backend server:
python manage.py runserver
By default, the backend runs on
http://localhost:8000/
.
-
Navigate to the frontend directory:
cd frontend
-
Install frontend dependencies:
npm install
-
Start the frontend development server:
npm start
By default, the frontend runs on
http://localhost:3000/
.
- Open http://localhost:3000/ in your browser.
- Upload a leaf image, select a leaf, and view color analysis results.
- The backend must be running for the frontend to communicate with the API.
- You may need to configure CORS in the backend for local development.
- Make sure all dependencies are installed as required in
requirements.txt
andpackage.json
.
This project automates and standardizes leaf color analysis, making it easy to compare, document, and research plant health or species. Its core innovation is the normalization and segmentation pipeline, ensuring robust results regardless of lighting or background.
Currently, this project does not specify a license. Please contact the project owner for usage details.