Skip to content

Anjan-2006/Histogram-equalization

Repository files navigation

Histogram Equalization: GPU vs CPU Benchmark

A performance comparison tool for GPU-accelerated versus CPU-based histogram equalization on video frames.

Overview

This project benchmarks CUDA-accelerated histogram equalization against CPU processing. It measures FPS, memory usage, and temperature to demonstrate GPU acceleration benefits for image processing tasks.

What is Histogram Equalization?

Histogram equalization improves image contrast by redistributing pixel intensities across the full 0-255 range. It transforms low-contrast images by stretching confined histograms to use the entire intensity spectrum.

How it works:

  1. Calculate image histogram
  2. Compute cumulative distribution function (CDF)
  3. Map old intensity values to new stretched values
  4. Apply transformation to image

Quick Start

Install Dependencies

pip install opencv-contrib-python numpy matplotlib seaborn psutil pynvml

Run Benchmark

python main.py

Place your input video as input1.mp4 in the project directory.

View Results

  • reports/benchmark_dashboard.png - Performance comparison dashboard
  • reports/benchmark_report.txt - Detailed statistics
  • output_gpu/gpu_output.mp4 - GPU processed output
  • output_cpu/cpu_output.mp4 - CPU processed output

Project Files

gpu_benchmark/
├── main.py              # Main entry point
├── gpu_process.py       # GPU histogram equalization pipeline
├── cpu_process.py       # CPU histogram equalization pipeline
├── report_generator.py  # Dashboard and report generation
├── histoexplain.py      # CLAHE examples and theory
├── histo.ipynb          # Jupyter notebook with visualizations
└── input1.mp4           # Your input video

GPU Pipeline

  1. Upload frame to GPU memory
  2. Apply Gaussian blur (GPU-accelerated)
  3. Apply histogram equalization (CUDA kernel)
  4. Download result to CPU
  5. Track VRAM and temperature
  6. Write to output video

CPU Pipeline

  1. Read frame from video
  2. Apply Gaussian blur (CPU)
  3. Apply histogram equalization (CPU)
  4. Track RAM usage
  5. Write to output video

Dashboard Output

The benchmark generates a 6-panel dashboard:

  1. GPU Compute Time - Total processing time in seconds
  2. FPS Comparison - GPU vs CPU frame rates
  3. Memory Timeline - VRAM and RAM usage per frame
  4. Speedup Factor - Overall GPU acceleration multiplier
  5. Temperature Timeline - GPU and CPU temperature during processing
  6. Before/After - Visual comparison of histogram equalization effect

Sample Report

GPU:
  Frame Count:        1000 frames
  Compute Time:       5.234 seconds
  FPS:                191.07 frames/sec
  Peak VRAM Usage:    2048 MB

CPU:
  Frame Count:        1000 frames
  Compute Time:       26.891 seconds
  FPS:                37.19 frames/sec
  Peak RAM Usage:     512 MB

Speedup:
  GPU is 5.14× faster than CPU

CLAHE (Contrast Limited Adaptive Histogram Equalization)

CLAHE is an improved version of histogram equalization:

  • Divides image into small tiles (8×8)
  • Applies equalization locally per tile
  • Limits contrast to prevent noise amplification
  • Better for medical imaging and satellite data

See histoexplain.py for CLAHE implementation examples.

Performance Notes

  • Typical speedup: 3-15× depending on GPU model
  • Use high-resolution video (1080p+) for maximum GPU advantage
  • Close other GPU applications before benchmarking
  • Monitor with nvidia-smi during execution

Requirements

  • Python 3.8+
  • NVIDIA GPU with CUDA support (or CPU fallback)
  • 4GB RAM minimum
  • OpenCV, NumPy, Matplotlib, psutil, pynvml

Troubleshooting

CUDA init failed: Install NVIDIA drivers and CUDA toolkit. Verify with nvidia-smi.

Cannot open input video: Ensure input1.mp4 exists. Try different formats (avi, mov).

Low FPS: Use high-resolution video or SSD storage. Close other GPU applications.

License

MIT License

About

This the demonstration of histogram equalization using cuda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors