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.
- Overview
- What is the Haar Wavelet Transform?
- Python Implementation
- Vivado HLS Implementation
- Experimental Results
- Implementation Workflow
- Project Structure
- Contributing
- License
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.
- 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
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 |
At its core, the Haar transform computes pairwise averages and differences of pixels.
The same process is applied first across each row (horizontal transform), and then across each column (vertical transform).
Notebook: notebooks/Haar_Wavelet_Transform.ipynb
- Pure
Numpyimplementation of 1D and 2D Haar transforms - Visualization of LL, LH, HL, HH components
- Validation via PyWavelets (
pywt) - Conversion of the image into
pixels.txtfor HLS input - Comparison between software and HLS results
| 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 |
- Works on any even-sized image (non-square supported)
- Synthesizable with Vivado HLS 2019.1+
- Handles both
floatandintpixel types - AXI-stream compatible for hardware acceleration
The notebook Visualize_HLS_Results.ipynb compares:
- HLS Floating-point results
- HLS Integer results
The following results compare Python software and Vivado HLS hardware implementations:
| Implementation | Description | Result |
|---|---|---|
| Python (float) | Software baseline using NumPy | ![]() |
| HLS (float) | Hardware-equivalent floating-point | ![]() |
| HLS (int) | Integer arithmetic optimized for synthesis | ![]() |
- Floating-point version maintains higher accuracy but consumes more FPGA resources.
- Integer version offers lower resource utilization with minimal loss of precision.
| 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 |
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
Contributions are welcome!
If you have suggestions or improvements, feel free to fork the repository and create a pull request.
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Description of changes" - Push the changes and open a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.




