In this problem you will get hands on experience with changing the resolution of an image. ie., down-sampling and up-sampling.
The original image is an 8-bit gray scale image of width 479 and height 359 pixels.
Convert the original image from type uint8 to double.
Recall from the lecture that in order to avoid aliasing (eg. jagged edges) when down sampling an image, you will need to first perform low-pass filtering on the original image.
For this step, create a 3x3 low pass filter with all coefficients equal to 1/9.
H1 = \[ \left( \begin{array}{ccc} 1/9 & 1/9 & 1/9 \\ 1/9 & 1/9 & 1/9 \\ 1/9 & 1/9 & 1/9 \\ \end{array} \right) \]
H1=[1/9, 1/9, 1/9; 1/9,1/9, 1/9; 1/9, 1/9, 1/9]
Perform low-pass filtering with this filter using matlab function “imfilter” with replicate as the third argument.
resultLowPass = imfilter(srcDouble,H1,‘replicate’);
Obtain the down-sampled image by removing every other row and column from the filtered image. The resulting image should be width 240 and height 180 pixels. ie. resultDownSample=element(0,0), element(2,2),…
Then you up-sample this low resolution image to the original resolution via spatial domain processing.
Create an all zero Matlab array of width 479 and height 359. For every odd valued i and low valued j set the value equal to (i,j) equal to to value of low-resolution image \((\frac{i+1}{2},\frac{j+1}{2})\)
Create another filter of form
H2 = \[ \left( \begin{array}{ccc} 1/4 & 1/2 & 1/4 \\ 1/2 & 1 & 1/2 \\ 1/4 & 1/2 & 1/4 \\ \end{array} \right) \]
or H2=[1/4, 1/2, 1/4; 1/2, 1, 1/2; 1/4, 1/2, 1/4]
Convolve the result obtained from the previous step with H2 but do not use replicate option.
resultBiLinearInterpolation = imfilter(resultUp,H2);
Compute the PSNR to two decimal points. OMG!
Given two \(N_1\) x \(N_2\) images \(x(n_1, n_2)\) and \(y(n_1, n_2)\)
\(MSE = \frac{1}{N_1 N_2} \sum_{n_1 = 1}^{N_1} \sum_{n_2 = 1}^{N_2} [x(n_1,n_2) - y(n_1,n_2)]^2\)
I tried to find if my stats book had mean standard error with a similar equation. I did not find it, but here is the wikipedia definition which does have some variables from stats, ie. sample. Considering its squared, we have \(\frac{1}{n}\) instead of \(\frac{1}{\sqrt{n}}\)
\(MSE = \frac{1}{N} \sum_{i = 1}^{n} [\hat{Y_i} - Y_i]^2\)
\(\hat{Y_i}\) is preditions or outcomes. Y is true values or input. n is number of samples in this case its the number of pixels. Since this is a 2d, he is using double summartion.
\(PSNR = 10 \log_{10} (\frac{MAX_I^2}{MSE})\)
Where \(MAX_I^2\) is the maximum possible pixel value of the images. For 8-bit gray-scale images this is 255 or 1 depending upon your array.