Tuesday, June 3, 2014

Fundamentals of Digital Image and Video Processing - Week 9 Solutions

Hi Coursera people,

I have to admit that the initial part of this week was very highly mathematical and I couldn't understand the videos. I was expecting the assignment to be equally tough. But to my surprise, the assignment was a straightforward implementation of a built-in Matlab function!

Here goes the Question number 7 of Week 9 :

In this problem you will get hands-on experience in JPEG image compression. Follow the instructions below to complete this problem. (1) Download the original 8-bit grayscale image here, and load it into a MATLAB array. (2) Perform JPEG compression by using the MATLAB function "imwrite". For the purpose of this problem, you need to specify 5 input arguments. The first argument is the MATLAB array containing the input image; the second argument is a string specifying the output file name; the third argument is 'jpg' (including the single quotes); the fourth argument is the string 'quality' (including the single quotes); and the last argument is a number that specifies the quality level used for compression. The quality level is an integer between 0 and 100. For this step, set the quality level to be 75 (the defaut value). After the function "imwrite" is invoked, a new JPEG image will be created in the location that was specified by you. (3) Load
the newly created JPEG image into a MATLAB array. Compute the PSNR between the JPEG compressed image and the original image. Note that the image loaded into MATLAB is of type 'uint8' (i.e., 8-bit integer). In order to compute the PSNR, you need to convert these arrays into 'double'. (4) Repeat steps (2) and (3) with the quality level set at 10. Enter the PSNR values corresponding to the JPEG images at quality level 75 and 10, respectively. Enter the numbers to 2 decimal points.

Here is my attempt at the code :

Original = imread('D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\Cameraman256.bmp');
Original_double = im2double(Original);
imwrite(Original,'D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\Converted.jpg','jpg','quality',75);
Converted = imread('D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\Converted.jpg');
Converted_double = im2double(Converted);
MSE1= mean(mean((Original_double - Converted_double).^2,2));
MaxI=1;
PSNR1=10*log10((MaxI^2)/MSE1);
imwrite(Original,'D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\ConvertedLowQual.jpg','jpg','quality',10);
ConvertedLowQual = imread('D:\private\MS related\~Coursera courses\Image and Video processing\Week 9\ConvertedLowQual.jpg');
ConvertedLowQual_double = im2double(ConvertedLowQual);
MSE2 = mean(mean((Original_double - ConvertedLowQual_double).^2,2)); % get the MSE
PSNR2=10*log10((MaxI^2)/MSE2);
PSNR1
PSNR2

-Cheers,
Vijay.

4 comments:

  1. have u tried week 11 quiz?

    ReplyDelete
  2. Hi PS123,

    I'm yet to try even Week 10's quiz. I'll probably do it over the weekend and post both solutions really soon. I'm currently caught up in a project at work and its keeping me pretty busy!

    ReplyDelete
  3. This information is really impressive. For getting more Best Digital Marketing Services click on the link.

    ReplyDelete
  4. what is the answer after running this code

    ReplyDelete