Saturday, May 3, 2014

Fundamentals of Digital Image and Video Processing - Week 4 Solutions

Hi coursera people,

This week was very informative and very stretchy! Here is the solution to question number 8 of week 4.

Firstly, here is the question :

In this problem you will perform block matching motion estimation between two consecutive video frames. Follow the instructions below to complete this problem. (1) Download the two video frames from frame_1 and frame_2. The frames/images are of height 288 and width 352. (2) Load the frame with file name "frame_1.jpg" into a 288×352 MATLAB array using function "imread", and then convert the array type from 8-bit integer to real number using function "double" or "cast" (note that the range of intensity values after conversion is between 0 and 255). Denote by I1 the converted MATLAB array. Repeat this step for the frame with file name "frame_2.jpg" and denote the resulting MATLAB array by I2. In this problem, I2 corresponds to the current frame, and I1 corresponds to the previous frame (i.e., the reference frame). (3) Consider the 32×32 target block in I2 that has its upper-left corner at (65,81) and lower-right corner at (96,112). Note this is MATLAB coordinate convention, i.e., the first number between the parenthesis is the row index extending from 1 to 288 and the second number is the column index extending from 1 to 352. This target block is therefore a 32×32 sub-array of I2. (4) Denote the target block by Btarget. Motion estimation via block matching searches for the 32×32 sub-array of I1 that is "most similar" to Btarget. Recall in the video lectures we have introduced various forms of matching criteria, e.g., correlation coefficient, mean-squared-error (MSE), mean-absolute-error (MAE), etc. In this problem, we use MAE as the matching criterion. Given two blocks B1 and B2 both of size M×N, the MAE is defined as MAE(B1,B2)=1M×N∑Mi=1∑Nj=1|B1(i,j)−B2(i,j)|. To find the block in I1 that is most similar to Btarget in the MAE sense, you will need to scan through all the 32×32 blocks in I1, compute the MAE between each of these blocks and Btarget, and find the one that yields the smallest value of MAE. Note in practice motion search is only performed over a certain region of the reference frame, but for the sake of simplicity, we perform motion search over the entire reference frame I1 in this problem. When you find the matched block in I1, enter the following information: (1) the coordinate of the upper-left corner of the matched block in MATLAB convention. This requires two integer numbers; (2) the corresponding MAE value, which is a floating-point number. Enter the last number to two decimal points. As an example for format of answer, suppose the matched block has upper-left corner located at (1,1), and the corresponding MAE is 10.12, then you should enter 1 1 10.12 (the three numbers are separated by spaces).

And, here is my attempt at the solution :

frame_1 = imread('D:\Image processing\Week 4\digital-images-week4_quizzes-frame_1.jpg');
frame_2 = imread('D:\Image processing\Week 4\digital-images-week4_quizzes-frame_2.jpg');
I1 = double(frame_1);
I2 = double(frame_2);
Btarget = I2(65:96,81:112);
for i=1:288
if (i+31 <= 288)
for j=1:352
if (j+31 <= 352)
Btemp = I1(i:i+31,j:j+31);
err = Btarget - Btemp;
absoluteerr = abs(err);
ComputedMAE = mean2(absoluteerr);
MAEArray(i,j) = ComputedMAE;
end
end
end
end
A = min(MAEArray(:))
X = MAEArray;
[p,q] = find(X==min(X(:)))

-Cheers,
Vijay.

12 comments:

  1. Thanks for your week 4 solution...

    ReplyDelete
  2. Could You Tell The Answer To Ques 3 :
    Calculate the Mean Square Error (MSE) between the two given image blocks (enter your answer to at least one decimal point):

    ReplyDelete
    Replies
    1. when will you upload week 5 solutions....

      Delete
  3. hi guys.... when will upload week 5 solutions....

    ReplyDelete
    Replies
    1. WEEK 5 programming

      x = imread('noisy.jpg'); % READ THE GIVEN IMAGE
      I1 = im2double(x); % NORMALIZE REAL VALUED ARRAY
      %title ('Given Image');
      NF1 = medfilt2(x,[3 3]); % 3*3 MEDIAN FILTERING OF THE FIRST IMAGE
      %figure, imshow(NF1); % READ THE IMAGE
      %title ('Filtered Image');
      NF2 = medfilt2(NF1,[3 3]); % 3*3 MEDIAN FILTERING OF THE FIRST IMAGE
      %figure, imshow(NF2);
      FI = imread ('noisy_original.jpg');
      %figure,imshow(FI);
      %subplot (1,4,2),imshow(I1); % DISPLAY NOISY INPUT IMAGE
      %subplot (1,4,3),imshow(NF1); % DISPLAY 1ST PASS FILTERED IMAGE
      %subplot (1,4,1),imshow(FI); % DISPLAY NOISE FREE IMAGE
      %subplot (1,4,4),imshow(NF2);% DISPLAY 2ND PASS FILTERED IMAGE

      MSE1= mean(mean((im2double(FI)- I1).^2)); % MSE BETWEEN NOISY INPUT IMAGE & NOISE FREE IMAGE
      MaxI=1;% the maximum possible pixel value of the images.
      PSNR1 = 10*log10((MaxI^2)/MSE1);% PSNR
      display (PSNR1);
      NF1 = im2double(NF1);
      MSE2 = mean(mean((im2double(FI)-NF1).^2,2));
      % MSE BETWEEN NOISY INPUT IMAGE & NOISE FREE IMAGE,MSE = mean(mean((Final-I2).^2,2))
      MaxI=1;% the maximum possible pixel value of the images.
      PSNR2 = 10*log10((MaxI^2)/MSE2);% PSNR
      display (PSNR2);
      NF2 = im2double(NF2);
      MSE3 = mean(mean((im2double(FI)-NF2).^2,2)); % MSE BETWEEN NOISY INPUT IMAGE & NOISE FREE IMAGE
      MaxI=1;% the maximum possible pixel value of the images.
      PSNR3 = 10*log10((MaxI^2)/MSE3);% PSNR
      display (PSNR3);




      %%%% answers 11.33 27.38 29.65

      Delete
  4. hey Vijay Karthick,

    I have tried HW 5 Q7 , and answer seems to be in negative , have u tried?

    ReplyDelete
  5. Hi PS123,

    I'm yet to try the week 5 assignment. I'll let you know once I have a concrete solution! You can share your code here for debugging.

    ReplyDelete

  6. Blur Photo Editor & Blur image Background Effect on picture has many blurry image tools for blur image editing. Easy to make your photo background DSLR blur effect.

    ReplyDelete