Assignment
Assignment
First of all, we can see, from the requirement that, need to develop a prototype model of
video conversion. Convert from SD video to HD video. So, we need to increase the width and
height by a factor of 2.
Here to increase the video resolution I’ve used openCV library.
As I have used the diffusion model over here to update the video let’s have brief idea on
what is work mechanism of diffusion model.
Assume that we there is one pixel in the video having the size of Height= a, width= b and
diagonal = z. when we are trying to increase the resolution by the factor of 2. That means the
height and width pixel will also be increased by the factor of 2. Now to full fill the blank areas
of each and every pixel we are using diffusion type model.
As I already mentioned that the first one pixel is having a diagonal of z unit. Now this
diagonal of unit z will work as a radius of circle and it will start to move from X axis to Y axis.
The extra additional area it covers by moving right to left or left to right thus the single pixel
will be diffused to that extra part also and it will cover that. All the pixels will work in the
same algorithm and they will cover the blank areas to its right side and left side.
In the case of video processing this diffusion model will work multiple times for upsampling
and extending the video length or increasing the frame rate. If we assume for the first time
that the video has diffused and it is denoted by Xa then for the next time when it will run
again to cover up the rest blank part it uses the same frame and continues the work on the
same algorithm but the condition is (Xb is the video diffusion for the 2nd time on the same
frame) probability of Xb given Xa.
So, first after importing the required libraries, capture the whole video and read it frame by
frame.
Next define the video resolution we are wanting to fetch in the output.
For any single frame in video we have the image or frame size 255.
After using the diffusion model frame to frame when we have the proper pixel then again
the frames are rejoined to make it video and first when we taken the frames from the video
then noise of the video then after rescaling it when we have the final video then readd the
noise again
Then having the final video output
Code for this-----------(I have used the google colab to run this program)
import cv2
import numpy as np
from skimage import io, filters
from skimage.restoration import denoise_tv_chambolle
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# Create a mask for the blank areas on the left and right sides
mask = np.zeros((hd_height, hd_width), dtype=np.uint8)
mask[:, :width] = 255
mask[:, -width:] = 255
cap.release()
out.release()
cv2.destroyAllWindows()