morelab/pollution-particle-analyzer
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
# Amiaire Project
Amiaire is a Python-based project for analyzing air quality by processing images of sensor papers. It extracts Regions of Interest (ROI), preprocesses these images, analyzes particulate matter, and estimates pollution levels based on correlations with reference sensor data (e.g., Atmotube).
## Features
* ROI extraction from sensor paper images (detects inner black square, perspective warp).
* Image preprocessing pipeline (grayscale, background improvement, intensity rescaling, CLAHE, Sauvola thresholding).
* Particle detection and analysis (contour filtering by area, solidity, aspect ratio, Feret diameter).
* Correlation analysis with reference sensor data (PM10, PM2.5) using linear regression.
* Estimation of pollution concentration (µg/m³) and classification into pollution levels (Good to Hazardous).
## Project Structure
pollution-particle-analyzer/
├── data/ # Input data (images, calibration CSVs, training JSONs)
├── output/ # Generated outputs (processed images, regression_params.json)
├── main/ # Main Python package
│ ├── main.py # Main script for image analysis pipeline
│ ├── config.py # Configurations (ROI, preprocessing, particle filters)
│ ├── roi.py # ROI extraction (adaptive threshold, contour detection, perspective warp)
│ ├── preprocessing.py # Image preprocessing (grayscale, background, rescale, CLAHE, Sauvola)
│ ├── analysis.py # Particle analysis and pollution level calculation
│ └── plotting.py # Plotting utilities (summary of processing stages)
├── scripts/
│ ├── train_correlation_models.py # Train PM10/PM25 models from CSV calibration data
│ └── train_correlation_models2.py # Train from data/training_data.json (polynomial/SVR, LOOCV)
└── root/
└── requirements.txt # Package dependencies
## Prerequisites
* Python 3.8+
* See `root/requirements.txt` for package dependencies (numpy, scikit-learn, opencv-python, matplotlib, scikit-image).
## Setup
1. **Clone the repository:**
```bash
git clone <your-repository-url>
cd pollution-particle-analyzer
```
2. **Create a virtual environment (recommended):**
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies:**
```bash
pip install -r root/requirements.txt
```
4. **Prepare data:**
* Place your input images for analysis in a directory (e.g., `data/input_images/`).
* If training correlation models, prepare CSV files (e.g., `pm10_calibration.csv`, `pm25_calibration.csv`) in the `data/` directory. Each CSV should have two columns: `paper_sensor_concentration` and `atmotube_concentration`.
## Usage
### 1. Train Correlation Models (if needed)
This step generates the `output/regression_params.json` file used by the main analysis pipeline.
```bash
python scripts/train_correlation_models.py
```
If calibration CSVs are missing, dummy data is created for testing. For production, provide real calibration data in `data/`.
### 2. Run Image Analysis Pipeline
```bash
python -m main.main --image_path data/example_image.jpeg --output_dir output/processed_images --model_type PM25
```
* `--image_path`: Path to the input image.
* `--output_dir`: Directory to save processed images and results. Default: `output`.
* `--model_type`: Type of pollution model (`PM10` or `PM25`). Must match a key in `output/regression_params.json`.