Skip to content

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

License

Notifications You must be signed in to change notification settings

AlessioBugetti/histogram-equalization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CUDA-Based Histogram Equalization

Table of Contents

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

.
├── 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:
git clone https://github.com/AlessioBugetti/histogram-equalization.git
cd histogram-equalization
  1. Install Python dependencies:
pip install -r requirements.txt
  1. Ensure the CUDA environment is set up:
    • Install NVIDIA drivers.
    • Install the CUDA Toolkit.
    • Verify with nvcc --version.

Usage

C++

./histequalizer build
./histequalizer run

Python

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 folder, were sourced from the official European Space Agency (ESA) website dedicated to the Hubble Space Telescope. All credits to NASA/ESA.

License

This project is licensed under the GPL-3.0-only License. See the LICENSE file for more details.

Author

Alessio Bugetti - alessiobugetti98@gmail.com

About

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

Topics

Resources

License

Stars

Watchers

Forks