Python-MA4268

National University of Singapore
Department of Mathematics
02/2022 Semester II MA4268 Mathematics in visual data processing Project 1
Goal
Discrete Wavelet Transform (DWT) and its inversion are one essential transform in
digital image processing. The goal of this project is to implement two-dimensional
Haar-wavelet-based DWT and its inverse DWT for 2D images in Python. Recall that
the low-pass filters and 3 wavelet high-pass filers of a Haar wavelet transforms are
given
H =
1
2
24 1 1
1 1
35 ; G1 = 1
2
24 1 1
1 1
35 ; G2 = 1
2
24 1 1
1 1
35 ; G3 = 1
2
24 1 1
1 1
35
Implementation
In this project, the following TWO functions are expected. For simplicity, you can
assume that the image is always of size 2N 2N , N is an integer. For example, images
of size 256 256, 512 512, or 1024 1024. The image can be restricted to gray-scale
image.
haar2d(im,lvl)
Computing 2D discrete Haar wavelet transform of a given ndarray im
Parameters: im: ndarray
An array representing image
lvl: integer
An integer representing the level of wavelet decomposition
Returns: out: ndarray
An array representing Haar wavelet coecients with lvl level.
It has the same shape as im
ihaar2d(coef,lvl)
Computing an image in the form of ndarray from the ndarray coef which represents
its DWT coecients.
Parameters: coef: ndarray
An array representing 2D Haar wavelet coecients
lvl: integer
An integer representing the level of wavelet decomposition
Returns: out: ndarray
An array representing the image reconstructed from its Haar
wavelet coecients.
Forbidden functions
You may NOT allow to call any function of discrete wavelet transform or inverse
wavelet transform from existing packages.
Allowed functions
You are allowed to call the routines ”convolve”, ”convolve2d” or similar functions
in numpy or scipy, as well as down-sampling and up-sampling functions. If you are
unsure about the validity of call some function, please ask in advance.
Remark on implementation
The function ”convolve” or ”convolve2d” in existing package often have di er-
ent setting for boundary extension. When calling the existing function, pay
attention to its boundary treatment.
Pay attention to the starting index of down-sampling and up-sampling to avoid
possible mis-alignment.
Do not use ”matplotlib” for reading/writing images, using the package ”pillow”
for reading/writing images.
Illustration of the implementation. See Figure 1 for an demonstration of the
format of expected wavelet-decomposition.
Image data and experiments
One image is provided: a gray-scale image of size 512 512. You can use it to test
your code, as well as other images that you prefer.
Academic integrity
It is an individual project. You are expected to implement the project on your
own. You may discuss the ideas with your classmates, but the sharing of code is
strictly prohibited. You are not allowed to use any code from online sources or from
other classmates’ projects, which will be checked via some standard code plagiarism
checking system. Any suspicious code identified by the system will lead to further
investigation. Anything that breaks these principles will commit a violation of the
Honor Code, and will be reported to the university for the corresponding action.
Grading policy
(a) input image (b) 3-level wavelet coecients
Figure 1: 3-level Haar wavelet decomposition of images
The grade of the submitted project is based on the following three factors: 1) How
well the submission meets the guidelines of the project; 2) Correctness of the output;
and (3) Computational eciency in terms of running time.
Submissions
You are required to submit the following
1. The python package ”main.py” that contains the functions of haar2d, ihaar2d;
and other supporting functions if any. A reference implementation of main.py is
attached in the zip file. Please modify it accordingly. To facilitate the grading
process, do not modify the IO format of ”main.py”.
Warning: DO NOT submit a single jupyer notebook, the file with extension
.ipynb, that contains everything.
2. A technical report to discuss what you would like to mention about your codes,
if any.
Please package all your files in a single zip file named by your student ID and up-
load the zip file into the directory of ”Assignment1” in the files of the course site in
Luminus, e.g., U1234567.zip. DO NOT email the files to my email address
The deadline for submission is FRIDAY, 11-Mar-2022. Any submission after the
deadline will lead to some penalty on grade.
If you have any question, please contact me by email: matjh@nus.edu.sg for help.