Verilog custom processor that low-pass filters and downsamples (factor 2) an image, verified against a Python reference using Sum of Squared Differences (SSD).
Built as part of EN3030 — Circuits and Systems Design at the University of Moratuwa.
input image output image
(PNG / JPG) (downsampled
│ by factor 2)
▼ ▲
┌─────────────┐ ┌─────────────┐ ┌──────────────┐ │
│ Img │ │ Verilog │ │ Img │ │
│ generator │──▶ │ processor │──▶ │ conversion │────┘
│ (Python) │ │ low-pass + │ │ (Python) │
│ │ │ decimate ×2 │ │ │
└─────────────┘ └─────────────┘ └──────────────┘
│
▼
┌──────────────┐
│ SSD error │
│ vs Python │
│ reference │
└──────────────┘
Each stage is a small, focused script — the Verilog RTL is the centrepiece; the Python tooling exists only to feed and drain it, and to verify correctness.
- Filtering — a low-pass kernel runs before decimation to prevent aliasing
- Arithmetic — fixed-point in hardware (small float-vs-fixed differences against the Python reference are expected and measured by SSD)
- Verification — Python computes the canonical downsampled image with the same kernel; SSD between Python and hardware outputs quantifies correctness (lower = better; zero = pixel-identical)
custom-image-downsampling-processor/
├─ Img generator/ # Generate input test images / pixel vectors (Python)
├─ Processor/ # Vivado project + Verilog RTL (SRC/)
├─ Img conversion/ # Convert simulation output back to an image (Python)
├─ Error calculation/ # Compute SSD between hardware and Python reference
├─ Compiler/ # Assembly / hex helpers
├─ LICENSE
└─ README.md
cd "Img generator"
python Img_gen.pyProduces output.txt with pixel data suitable as testbench input.
Vivado (preferred — project files included):
- Open
Processor/Processor.xpr - Run Simulation → Run Behavioral Simulation
- Export the result to a
.txtfile
Icarus Verilog (lightweight alternative):
iverilog -o build/downsampler.vvp Processor/SRC/*.v
vvp build/downsampler.vvp > build/sim_output.txtcd "Img conversion"
python Conversion.pyConverts the simulation dump (imgdata.txt) into a viewable image (img.jpg).
cd "Error calculation"
python "SSD error.py"Outputs SSD = <value>. Lower is better; zero means the hardware matches the Python reference exactly.
- Verilog — Vivado (recommended) or Icarus Verilog
- Python 3.8+ —
numpy,Pillow,matplotlib(pip install numpy pillow matplotlib)
MIT — see anjanamb.github.io for more projects.