Hi coursera people,
I'm thrilled to take the course "Fundamentals of Digital Image and Video Processing". Matlab programming assignments have just started. The question 7 of week 2 involves some coding, which we are expected to write to get the right answers.
Here's the question :
Here's my approach :
I'm thrilled to take the course "Fundamentals of Digital Image and Video Processing". Matlab programming assignments have just started. The question 7 of week 2 involves some coding, which we are expected to write to get the right answers.
Here's the question :
In this problem you will implement spatial-domain low-pass
filtering using MATLAB, and evaluate the difference between the filtered image
and the original image using two quantitative metrics called Mean Squared Error
(MSE) and Peak Signal-to-Noise Ratio (PSNR). Given two N1×N2 images x(n1,n2) and y(n1,n2) ,
the MSE is computed as MSE=1N1N2∑N1n1=1∑N2n2=1[x(n1,n2)−y(n1,n2)]2 .
The PSNR is defined as PSNR=10log10(MAX2IMSE) , where MAXI is
the maximum possible pixel value of the images. For the 8-bit gray-scale images
considered in this problem, MAXI=255 . Follow
the instructions below to finish this problem. (1) Download the original image
from here.
The original image is a 256×256 8-bit gray-scale image.
(2) Convert the original image from type 'uint8' (8-bit integer) to 'double'
(real number). (3) Create a 3×3 low-pass
filter with all coefficients equal to 1/9, i.e., create a 3×3 MATLAB
array with all elements equal to 1/9. (4) Low-pass filter the original image
(converted to type 'double') with the filter created in step (3). This can be
done using the built-in MATLAB function "imfilter". The function
"imfilter" takes three arguments and returns one output. The first
argument is the original image (converted to type 'double'); the second
argument is the low-pass filter created in step (3); and the third argument is
a string specifying the boundary filtering option. For this problem, use
'replicate' (including the single quotes) for the third argument. The output of
the function "imfilter" is the filtered image. (5) Compute and record
the PSNR value between the original image (converted to type 'double') and the
filtered image by using the formulae given above. (6) Repeat steps (3) through
(5) using a 5×5 low-pass filter with all
coefficients equal to 1/25. Enter the PSNR values you have obtained from your
experiments (The PSNR corresponding to 3×3 filter
first, followed by the PSNR corresponding to 5×5 filter).
Make sure you order the answers correctly and separate them by a space. Enter
the numbers to 2 decimal points.
Here's my approach :
I = imread('C:\Users\****\Desktop\digital-images-week2_quizzes-lena.gif');
% read the image
I2 = im2double(I); % convert the uint8 image to double
B = [1/9, 1/9, 1/9; 1/9, 1/9, 1/9; 1/9, 1/9, 1/9]; % create the 3x3 array
C = imfilter(I2, B, 'replicate'); % apply the filter
MSE = mean(mean((I2 - C).^2,2)); % get the MSE
MaxI=1;% the maximum possible pixel value of the images.
PSNR1=10*log10((MaxI^2)/MSE); % get the PSNR
PSNR1 % print the PSNR
B1 = [1/25, 1/25, 1/25, 1/25, 1/25; 1/25, 1/25, 1/25, 1/25, 1/25; 1/25,
1/25, 1/25, 1/25, 1/25; 1/25, 1/25, 1/25, 1/25, 1/25; 1/25, 1/25, 1/25,
1/25, 1/25];
C1 = imfilter(I2, B1, 'replicate');
MSE1 = mean(mean((I2 - C1).^2,2));
PSNR2=10*log10((MaxI^2)/MSE1);
PSNR2
hi vivek,
ReplyDeletenice to see you program. but i have seen that in couse , maxi=255 know. why did you took 1.
Dear Praveena Chag,
ReplyDeleteMAXI is the maximum fluctuation in the input image data type. For example, if the input image has a double-precision floating-point data type, then MAXI is 1. If it has an 8-bit unsigned integer data type, MAXI is 255, etc.
Source : http://www.mathworks.in/help/vision/ref/psnr.html
nice work ;)
ReplyDeleteHi Vivek,
ReplyDeleteThank you. Have you done Homework 3 Matlab program
Thanks Sofia :)
ReplyDeleteHi Praveena Chag,
ReplyDeleteI'm working on it. Will post it in sometime.
Hi all,
ReplyDeletePosted the week 3 solution. Bug me if you have any other queries...
hello again :)
ReplyDeleteI would like to ask you about the last question of week 4. I found the upper-left corner of the block, but the MAE number is wrong. Could this be possible;;;
I use this code:
MAE= mean(mean(abs(A2 - A1),2));
or
ab=0;
for x=1:32
for y=1:32
e= A2(x,y) - A1(x,y);
absolute = abs(e);
ab=ab+absolute;
end
end
MAE= ab/1024
and I have the same result...I don't know what else to do...
Thanks for your week 4 solutions...
ReplyDeleteThanks a lot for week2 solutions
ReplyDeleteThanks for share it. Best Digital Marketing Services
ReplyDeletethank you so much from bottom of my heart, i was stuck by this question and searching how can i solve it. i really appreciate it :)
ReplyDelete