Skip to content

A Python and Vivado HLS implementation of the 2D Haar Wavelet Transform for image edge detection. Includes synthesizable C++ code and Python reference, enabling software–hardware comparison.

License

Notifications You must be signed in to change notification settings

Oneiben/haar-wavelet-edge-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haar Wavelet Transform for Edge Detection — Python & Vivado HLS Implementation

A Python and Vivado HLS implementation of the 2D Haar Wavelet Transform for image edge detection. The project bridges software prototyping and hardware design, offering visual and quantitative comparisons between the two approaches.

Subbands

Table of Contents

  1. Overview
  2. What is the Haar Wavelet Transform?
  3. Python Implementation
  4. Vivado HLS Implementation
  5. Experimental Results
  6. Implementation Workflow
  7. Project Structure
  8. Contributing
  9. License

Overview

This repository presents a complete implementation of the 2D Haar Wavelet Transform — both in Python (software) and C++ using Vivado HLS (hardware).
This project aims to compare results between floating-point and integer synthesis versions and visualize differences.

Key Features

  • Full 2D Haar Wavelet Transform (LL, LH, HL, HH)
  • Python + NumPy implementation (from scratch)
  • Synthesizable C++ implementation
  • Floating-point vs Integer performance comparison
  • Visualization and analysis notebooks

What is the Haar Wavelet Transform?

The Haar Wavelet Transform is one of the simplest and most computationally efficient wavelet transforms, widely used in image compression, signal analysis, and edge detection.

Subband Meaning Description
LL Low-Low Approximation — coarse version of the image
LH Low-High Horizontal details — vertical edges
HL High-Low Vertical details — horizontal edges
HH High-High Diagonal details — fine edges

Mathematical Formulation

At its core, the Haar transform computes pairwise averages and differences of pixels.

Haar Wavelet Formula

The same process is applied first across each row (horizontal transform), and then across each column (vertical transform).


Python Implementation

Notebook: notebooks/Haar_Wavelet_Transform.ipynb

Features

  • Pure Numpy implementation of 1D and 2D Haar transforms
  • Visualization of LL, LH, HL, HH components
  • Validation via PyWavelets (pywt)
  • Conversion of the image into pixels.txt for HLS input
  • Comparison between software and HLS results

Vivado HLS Implementation

Core Files

File Description
wavelet.h Constants, type definitions, function prototypes
wavelet_process.cpp Core Haar Transform logic
wavelet_top.cpp Top-level function for synthesis
main.cpp Testbench for simulation and I/O

Supported Features

  • Works on any even-sized image (non-square supported)
  • Synthesizable with Vivado HLS 2019.1+
  • Handles both float and int pixel types
  • AXI-stream compatible for hardware acceleration

Visualization and Analysis

The notebook Visualize_HLS_Results.ipynb compares:

  • HLS Floating-point results
  • HLS Integer results

Comparison Plot


Experimental Results

The following results compare Python software and Vivado HLS hardware implementations:

Implementation Description Result
Python (float) Software baseline using NumPy python-float
HLS (float) Hardware-equivalent floating-point hls-float
HLS (int) Integer arithmetic optimized for synthesis hls-int

Quantitative Comparison

  • Floating-point version maintains higher accuracy but consumes more FPGA resources.
  • Integer version offers lower resource utilization with minimal loss of precision.

Implementation Workflow

Step Description
1. Algorithm Study Compared edge detection techniques (Sobel, Wavelet, etc.) and chose Haar for simplicity & hardware suitability
2. Python Prototype Built from scratch with validation against PyWavelets
3. HLS Translation Converted Python logic to synthesizable C++ and verified through testbench
4. Synthesis & Co-simulation Generated VHDL/Verilog and compared floating vs integer results
5. Visualization Python notebooks used for graphical result comparison

Project Structure

haar-wavelet-edge-detection/
│
├── src/
│   ├── wavelet.h
│   ├── wavelet_process.cpp
│   ├── wavelet_top.cpp
│   └── main.cpp
│
├── notebooks/
│   ├── Haar_Wavelet_Transform.ipynb     
│   └── Visualize_HLS_Results.ipynb      
│
├── data/
│   ├── image.png
│   └── pixels.txt               
│
├── results/
│   ├── Comparison_plot.png
│   ├── Haar_img.png
│   ├── Haar_Wavelet_Transform_Sub-bands.png
│   ├── HLS-float.png
│   ├── HLS-int.png
│   ├── Python-float.png
│   ├── wavelet_float_results.txt
│   └── wavelet_int_results.txt
│
├── .gitignore
├── LICENSE
├── README.md 
└── requirements.txt                

Contributing

Contributions are welcome!
If you have suggestions or improvements, feel free to fork the repository and create a pull request.

Steps to Contribute:

  1. Fork the repository.
  2. Create a new branch:
    git checkout -b feature-name
  3. Commit your changes:
    git commit -m "Description of changes"
  4. Push the changes and open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

A Python and Vivado HLS implementation of the 2D Haar Wavelet Transform for image edge detection. Includes synthesizable C++ code and Python reference, enabling software–hardware comparison.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages