This project implements an adaptive preprocessing pipeline for grayscale medical images. It is designed as a reusable conditioning step prior to classical machine learning or deep learning models in medical imaging applications.
The pipeline focuses on denoising and contrast enhancement while avoiding unnecessary noise amplification through objective, data-driven decision criteria.
Given a noisy medical image and its corresponding clean reference image, the pipeline:
- Loads images in grayscale.
- Applies adaptive denoising (median or Gaussian) based on noise characteristics.
- Applies CLAHE as an optional contrast enhancement step.
- Evaluates image quality using objective metrics.
- Automatically decides whether CLAHE improves the image.
- Saves visual comparisons and exports quantitative results.
- Median filter is applied when extreme intensity values are detected.
- Gaussian filter is applied otherwise.
- CLAHE is applied as a candidate enhancement.
- Its use is accepted or rejected based on objective metrics.
- PSNR (when a reference image is available)
- Entropy (no-reference information metric)
- Intensity standard deviation (global contrast indicator)
CLAHE is retained only if it improves information content and contrast without significantly degrading fidelity to the reference image.
project-0-medimg-preprocessing/ ├─ src/ │ └─ medimg_preprocess/ │ ├─ io.py │ ├─ dataset.py │ ├─ filters.py │ ├─ contrast.py │ ├─ metrics.py │ └─ pipeline_single.py ├─ run_batch.py ├─ notebooks/ │ └─ exploration.ipynb ├─ data/ │ ├─ noisy/ │ └─ original/ ├─ outputs/ ├─ requirements.txt └─ README.md
bash python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt
python run_batch.py
This script:
- Validates dataset consistency.
- Processes all images in data/noisy/.
- Saves comparison figures in outputs/.
- Generates a summary.csv file with objective metrics and decisions.
PSNR is used only for evaluation purposes when a clean reference image is available. In real clinical scenarios, reference images are usually unavailable, so no-reference metrics (entropy and intensity statistics) are preferred.
- Medical image preprocessing
- Classical machine learning pipelines
- CNN input conditioning
- Educational and research purposes