Some Image and Video Processing: Motion Estimation with Block-Matching in Videos, Noisy and Motion-blurred Image Restoration with Inverse Filter in Python and OpenCV

The following problems appeared in the exercises in the coursera course Image Processing (by Northwestern University). The following descriptions of the problems are taken directly from the exercises’ descriptions.

1. Analysis of an Image quality after applying an nxn Low Pass Filter (LPF) for different n

The next figure shows the problem statement. Although it was originally implemented in MATLAB, in this article a python implementation is going to be described.

ex1.png

The following figure shows how the images get more and more blurred after the application of the nxn LPF as n increases.

im1

The following figure shows how the quality of the transformed image decreases when compared to the original image, when an nxn LPF is applied and how the quality (measured in terms of PSNR) degrades as n (LPF kernel width) increases.

im2.png

2. Changing Resolution of an Image with Down/Up-Sampling

The following figure describes the problem:

ex2.png

The following steps are needed to be followed:

  1. Smooth the original image with a 3×3 LPF (box1) kernel.
  2. Downsample (choose pixels corresponding to every odd rows and columns)
  3. Upsample the image (double the width and height)
  4. Use the kernel and use it for convolution with the upsampled image to obtain the final image.

Although in the original implementation MATLAB was used, but the following results come from a python implementation.

sampling3.png

As we go on increasing the kernel size, the quality fo the final image obtained by down/up sampling the original image decreases as n increases, as shown in the following figure.

im3.png

3. Motion Estimation in Videos using Block matching between consecutive video frames

The following figure describes the problem:

ex3.png

For example we are provided with the input image with known location of an object (face marked with a rectangle) as shown below.

 digital-images-week4_quizzes-frame_1_with_block.jpg

Now we are provided with another image which is the next frame extracted from the same video but with the face unmarked) as shown below. The problem is that we have to locate the face in this next frame and mark it using simple block matching technique (and thereby estimate the motion).

digital-images-week4_quizzes-frame_2.jpg

As shown below, using just the simple block matching, we can mark the face in the very next frame.

digital-images-week4_quizzes-frame_2_with_block.jpg

Now let’s play with the following two videos. The first one is the video of some students working on a university corridor, as shown below (obtained from youtube), extract some consecutive frames, mark a face in one image and use that image to mark all thew faces om the remaining frames that are consecutive to each other, thereby mark the entire video and estimate the motion using the simple block matching technique only.

 in.gif

The following figure shows the frame with the face marked, now we shall use this image and block matching technique to estimate the motion of the student in the video, by marking his face in all the consecutive frames and reconstructing the video, as shown below..block_001.png

out.gif
The second video is the video of the Google CEO Mr. Pichai talking, as shown below (obtained from youtube), again extract some consecutive frames, mark his face in one image and use that image to mark all the faces in the remaining frames that are consecutive to each other, thereby mark the entire video and estimate the motion using the simple block matching technique only.
 in.gif
The following figure shows the frame with the face marked, now we shall use this image and block matching technique to estimate the motion of the Google CEO in the video, by marking his face in all the consecutive frames and reconstructing the video, as shown below.
block_001.png
out.gif
The most interesting thing above is that we have not used any sophisticated image features such as HOG / SIFT, still it did a pretty descent job with simple block matching.

4. Using Median Fiter to remove salt and paper noise from an image

The following figure describes the problem:

ex4.png

The following figure shows the original image, the noisy image and images obtained after applying the median filter of different sizes (nxn, for different values of n):

im4.png

As can be seen from the following figure, the optimal median filter size is 5×5, which generates the highest quality output, when compared to the original image.

im5.png

Using Inverse Filter to Restore noisy images with Motion Blurs

The following figure shows the description of the problem:

ex5.png

The following figure shows the theory behind the inverse filters in the (frequency) spectral domain.

im6.png

The following are the steps for the restoring an image with motion blurs  and noise-corruption using the Inverse Filter:

  1. Generate restoration filter in the frequency domain (with Fast Fourier Transform) from frequency response of motion blur and using the threshold T.
  2. Get the spectrum of blurred and noisy-corrupted image (the input to restoration).
  3. Compute spectrum of restored image by convolving the restoration filter with the blurred noisy image in the frequency domain.
  4. Genrate the restored image from its spectrum (with inverse Fourier Transform).

The following figures show the inverse filter is applied with different threshold value T (starting from 0.1 to 0.9 in that order) to restore the noisy / blurred image.

inverse_filter_0.1.png
inverse_filter_0.2.png
inverse_filter_0.3.png
inverse_filter_0.4.png
inverse_filter_0.5.png
inverse_filter_0.6.png
inverse_filter_0.7.png
inverse_filter_0.8.png
inverse_filter_0.9.png

The following figure shows how the Restored PSNR and the ISNR varies with different values if the threshold T.

im8.png
Advertisements

2 thoughts on “Some Image and Video Processing: Motion Estimation with Block-Matching in Videos, Noisy and Motion-blurred Image Restoration with Inverse Filter in Python and OpenCV

  1. Pingback: Sandipan Dey: Some Image Processing: Motion Estimation with Block-Matching in Videos, Noisy Image Restoration with Inverse Filter with Python and OpenCV | Adrian Tudor Web Designer and Programmer

  2. Pingback: Sandipan Dey: Some Image and Video Processing: Motion Estimation with Block-Matching in Videos, Noisy and Motion-blurred Image Restoration with Inverse Filter in Python and OpenCV | Adrian Tudor Web Designer and Programmer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s