CS4551 Spring 2020 HW #3 rev.
1
CS4551 Multimedia Software Systems
Homework 3 (10%) – Block-based Motion Compensation
, .
• What to turn in:
o Submit source code with necessary files for “compile and run”.
o Do NOT submit data files.
o You MUST provide a readme.txt file containing all information to help with the grading process.
• If your program produces any compile errors, you will receive 0 automatically no matter how close your
program is to the solution.
• Programming requirements:
o You are not allowed to use any Java built-in image class methods, library, or tools to complete this
homework.
o Do not create one mega-size main class.
o Do not change any given methods of MImage class nor create a new class that duplicates MImage
class. Treat MImage as a part of imported library.
o Test your program with all test data.
o If you do not meet any of the requirements above, you will receive a significant reduction.
Download the test dataset (video frames of 200 PPM images, Walk_001.ppm ~ Walk_200.ppm) from CSNS. Before
programming, check the images using Irfanview.
0. What your program should do
Name your main application CS4551_[YourLastName].java (e.g. CS4551_Doe.java) and expand the given
template program to perform the following tasks.
Receive the input file as command line arguments.
On Command Prompt
java CS4551_Doe
Display the following main menu to the user and receive the user’s input.
Main Menu-----------------------------------
1. Block-based Motion Compensation
2. Fast Motion Compensation
3. Quit
Please enter the task number [1-3]:
After performing a selected task, go back to display the menu again.
CS4551 Spring 2020 HW #3 rev.
2
1. Task 1 – Block-based Motion Compensation (80 pts)
Write a routine(method) that compensates motions between two images (one is the target image and the other
one is the reference image). Receive two images as parameters. Make the routine perform the followings:
• Receive an integer π for the macro block size from the user. π must be 8, 16, or 24.
• Receive an integer π for search window from the user. π must be 2, 4, 8, 12, or 16.
• Divide the target image into a set of π × π macro blocks.
• For each target macro block:
o Estimate one motion vector by finding the best matched macro block (a.k.a. predicted block) in the
reference image using π for the search area size and MSD (Mean Square Difference) for the
matching criteria. When you compute MSD, use Gray values:
Gray = round(0.299 * R + 0.587 * G + 0.114 * B)
o After finding the best matched block, compute the motion vector and the error block
βͺ Compute the motion vector using
π = (ππ₯, ππ¦) = (π‘π₯,π‘π¦) − (ππ₯, ππ¦)
where (π‘π₯,π‘π¦) is the upper left corner location of the target block and (ππ₯, ππ¦) is the upper left
corner location of the best matched block location in the reference frame.
βͺ Compute the error block (a.k.a. residual block) consisting of pixel differences (absolute values)
between the target block and the best matched block (a.k.a. predicted block).
π = |πππ₯ππ_ππ_π‘ππππ_πππππ − ππππππ πππππππ_πππ₯ππ_ππ_πππ‘πβππ_πππππ|
• Outputs
o Display and Save your error (or residual) image. Your error image is a composition of all error
blocks. Scale error values to range [0, 255]. In order to do so, compute ππΌππππππ and ππ΄ππππππ
and map values from [ππΌππππππ, ππ΄ππππππ] to [0, 255] using
πππππππΈππππ =
π − ππΌππππππ
ππ΄ππππππ − ππΌππππππ
× 255
o Save the estimated motion vectors to the “mv.txt”. It should have motion vectors of all target blocks.
Refer to the, refer sample mv.txt file.
CS4551 Spring 2020 HW #3 rev.
3
• Extra credit (20 pts) Implement matching in the half-pixel accuracy:
o Use the best matched block at full-pel position as the starting point, shown as the red dot in the
figure below.
o Check the neighboring candidate blocks in half-pel positions, which are shown as the blue diamonds.
o Select the block with the least MSD among the 8 half-pel blocks and one best full-pel block as the
final matched block in the half-pel block-based motion compensation.
2. Task 2 – Fast Motion Compensation (20 pts)
Implement logarithmic search for matching. Provide an additional menu option for this. Display and save motion
vectors and a residual image. Also, display the number of matches performed given π.
Sample results will be posted on CSNS.