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

https://github.com/alessiobugetti/histogram-equalization

Implements sequential and parallel histogram equalization in C++ and Python, utilizing CUDA for parallel computation on GPU
https://github.com/alessiobugetti/histogram-equalization

Last synced: 3 months ago
JSON representation

Implements sequential and parallel histogram equalization in C++ and Python, utilizing CUDA for parallel computation on GPU

Awesome Lists containing this project

README

        

# CUDA-Based Histogram Equalization

## Table of Contents
- [Overview](#overview)
- [Repository Structure](#repository-structure)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
- [C++](#c)
- [Python](#python)
- [Cuda Kernels](#cuda-kernels)
- [Included Kernels](#included-kernels)
- [Performance](#performance)
- [Credits](#credits)
- [License](#license)
- [Author](#author)

## Overview
This project implements histogram equalization for grayscale images using CUDA. It leverages GPU parallel processing to achieve high performance, particularly for large datasets or computationally intensive tasks.
The algorithm incorporates different parallel prefix sum (scan) algorithms:
- Kogge-Stone
- Kogge-Stone with Double Buffer
- Brent-Kung

## Overview
Histogram equalization is a method in image processing of contrast adjustment using the image's histogram.

Before Histogram Equalization:

Image before Histogram Equalization

Corresponding histogram (red) and cumulative histogram (black):

Corresponding histogram

After Histogram Equalization:

Image after Histogram Equalization

Corresponding histogram (red) and cumulative histogram (black):

Equalized histogram

## Repository Structure

```plaintext
.
├── python/
│ └── main.py # Python script for invoking CUDA kernels and managing the workflow
├── c++/
│ ├── main.cu # CUDA source file containing the implementation of kernels
│ └── kernel.cu # CUDA kernel definitions
├── data/ # Directory for input images
└── histequalizer # Script for compiling the project and running benchmarks
```

## Prerequisites

- CUDA-capable NVIDIA GPU
- CUDA Toolkit
- OpenCV
- C++ compiler
- CMake
- Python 3.x (for Python interface)
- Python Libraries:
- numpy
- opencv-python
- pycuda

## Installation
1. Clone the repository:

```sh
git clone https://github.com/AlessioBugetti/histogram-equalization.git
cd histogram-equalization
```
2. Install Python dependencies:

```sh
pip install -r requirements.txt
```
3. Ensure the CUDA environment is set up:
- Install NVIDIA drivers.
- Install the CUDA Toolkit.
- Verify with ```nvcc --version```.

## Usage

### C++
```sh
./histequalizer build
./histequalizer run
```

### Python
```sh
python main.py
```

## Cuda Kernels

### Included Kernels:

- `CalculateHistogram`: Computes the histogram for the input image.
- `KoggeStoneScan`: Performs parallel prefix sum using the Kogge-Stone algorithm.
- `KoggeStoneScanDoubleBuffer`: Performs parallel prefix sum using the Kogge-Stone algorithm with double buffer.
- `BrentKungScan`: Performs parallel prefix sum using the Brent-Kung algorithm.
- `NormalizeCdf`: Normalizes the CDF for intensity adjustment.
- `EqualizeHistogram`: Applies the equalized histogram to the input image.

## Performance
The implementation includes benchmarking capabilities that measure:
- Sequential CPU execution time
- CUDA execution time for each scan algorithm.
- Speedup ratios compared to CPU implementation.
- Measurements are averaged over multiple iterations to ensure reliable results.

## Credits
The images used, placed in the [`data`](data/) folder, were sourced from the official European Space Agency (ESA) website dedicated to the Hubble Space Telescope. All credits to [NASA](http://www.nasa.gov/)/[ESA](http://www.esa.int/).

## License
This project is licensed under the GPL-3.0-only License. See the [`LICENSE`](LICENSE) file for more details.

## Author
Alessio Bugetti - [email protected]