An open API service indexing awesome lists of open source software.

https://github.com/raspberrypi/ai_enhance

Low light image enhancement using zero DCE neural network
https://github.com/raspberrypi/ai_enhance

Last synced: about 2 months ago
JSON representation

Low light image enhancement using zero DCE neural network

Awesome Lists containing this project

README

          

# AI Enhance

Low-light image enhancement using the Zero-DCE (Zero-Reference Deep Curve Estimation) algorithm.

## Overview

This implementation enhances dark or low-light images by learning pixel-wise curve adjustments without requiring paired training data. The algorithm iteratively applies learned enhancement curves to brighten images while preserving natural appearance.

Based on the paper: **"Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement"** by Guo, Li et al. ([arXiv:2001.06826](https://arxiv.org/abs/2001.06826)), though this implementation does add some more explicit control of the target brightness based on the `gain` parameter (see below).

### Zero-DCE Example

| Before | After |
|--------|-------|
| ![Before](before.jpg) | ![After](after.jpg) |

## Installation

Install the required Python packages:

```bash
pip install numpy opencv-python pillow tqdm ai-edge-litert
```

## Usage

```bash
python enhance.py [options]
```

### Required Arguments

- `input` - Path to the input image file
- `output` - Path for the output enhanced image

### Optional Arguments

| Argument | Default | Description |
|----------|---------|-------------|
| `--model` | `dcenet.tflite` | Path to the model file. You may want to consider trying the `dcenet_int8.tflite` quantized model |
| `--gain` | `1.0` | Brightness adjustment factor. Higher values produce brighter output |
| `--local-strength` | `0.25` | Balance between local and global brightness (0.0-1.0). Higher values brighten dark areas more |
| `--patch-size` | `256` | Patch size for processing. Use 0 for full image size. Smaller values reduce memory usage |
| `--batch-size` | `1` | Number of patches to process simultaneously |
| `--num-threads` | `4` | Number of CPU threads for inference |
| `--overlap-pixels` | `16` | Pixel overlap between patches to reduce seam artifacts |
| `--hide-progress` | `false` | Hide the progress bar during processing |
| `--quality` | `95` | JPEG output quality (0-100). Higher values produce larger, higher quality files |
| `--compress-level` | `1` | PNG compression level (0-9). Higher values produce smaller files but take longer |

### Examples

Basic usage:
```bash
python enhance.py dark_photo.jpg enhanced_photo.jpg
```

With increased brightness:
```bash
python enhance.py dark_photo.jpg enhanced_photo.jpg --gain 1.3
```

Low memory usage (smaller patches):
```bash
python enhance.py large_image.jpg output.jpg --patch-size 128
```

Using the int8 quantised model:
```bash
python enhance.py input.jpg output.jpg --model dcenet_int8.tflite
```

## Performance

On a Pi 5 the default `dcenet.tflite` model runs at somewhat less than 1 megapixel per second. The quantised `dcenet_int8.tflite` runs very roughly twice as fast, but produces different results (though not conspicuously so).

Performance will obviously be worse on lower specification Pis, and we don't recommend running the models on anything with less than 1GB of memory.

In practice, the `patch-size` and `batch-size` parameters make little difference to the run time, so the defaults should be acceptable for most use cases.

The models don't have to be run on Pis; you can run them on pretty much any computer.

## License

BSD 2-Clause License. See [LICENSE](LICENSE) for details.