This repository contains a set of Python implementations for video compression and object removal using motion compensation techniques. The work was part of a project for the "Multimedia Systems" course at the University of Piraeus (2022-2023). The project was divided into three tasks, each focusing on a different aspect of video processing: Huffman compression, motion compensation, and object removal.
This project contains the following tasks:
- Task 1: Video Compression Using Huffman Encoding
- Task 2: Motion Compensation for Video Compression
- Task 3: Object Removal from Video Using Motion Compensation
In this task, a video is compressed using Huffman encoding applied to the difference between consecutive video frames. The encoded video is then decoded, resulting in a noisy reconstruction due to the error accumulation in the decoding process.
- Frame difference calculation.
- Huffman encoding of the difference.
- Decoding process with accumulated errors.
- Python 3
- OpenCV:
pip install opencv-python
This task focuses on using motion compensation to compress a video. The video is split into macroblocks, and motion vectors are calculated to represent the movement between frames. A hierarchical search approach is applied to speed up the process.
- Convert frames to grayscale.
- Macroblock division and motion vector calculation.
- Image prediction and error image calculation.
- Motion compensation for encoding and decoding.
- Python 3
- OpenCV:
pip install opencv-python - tqdm:
pip install tqdm
In this task, an object is algorithmically removed from a video by utilizing motion compensation. The frames are split into macroblocks, and motion vectors are adjusted to exclude the moving object.
- Select the first frame with minimal motion.
- Apply motion compensation across frames to exclude the moving object.
- Reconstruct the video with the object removed.
- Python 3
- OpenCV:
pip install opencv-python - Numpy:
pip install numpy
encoder1ii.py: Encoder for motion compensation video compression (Task 2).decoder1ii.py: Decoder for motion compensation video compression (Task 2).function.py: Utility functions for motion compensation (Task 2).Thema1i.py: Encoder for Huffman compression (Task 1).Thema2.py: Encoder for object removal (Task 3).
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install required libraries:
pip install opencv-python numpy tqdm
-
Run the respective Python scripts for each task:
- Task 1:
python3 Thema1i.py - Task 2:
python3 encode1_2.pyandpython3 decode1_2.py - Task 3:
python3 Thema2.py
- Task 1:
Example of an input video and its encoded/decoded versions:
Original Video:
Encoded Video:
Decoded Video:
Example of an input video and its encoded/decoded versions:
Original Video:
Encoded Video:
Decoded Video:
Example of an input video with an object and the resulting video after object removal:
Before Object Removal:
After Object Removal:
- Multimedia Systems - Algorithms, Standards, and Applications by Parag Havaldar, Gerard Medioni
- OpenCV Documentation: https://docs.opencv.org/3.4/d6/d00/tutorial_py_root.html
- Numpy Documentation: https://numpy.org/doc
- tqdm Documentation: https://tqdm.github.io/
This project is licensed under the MIT License.







