Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A 9x9 image is given below. Assume that the spatial coordinates of the upper lef

ID: 2249388 • Letter: A

Question

A 9x9 image is given below. Assume that the spatial coordinates of the upper left corner pixel are (1, 1).

10 6 27 165 10 11 27 165 17

54 23 11 209 54 23 11 209 18

65 115 33 187 65 115 33 187 19

10 0 23 165 108 8 27 165 17

54 23 112 209 4 23 11 9 18

65 115 133 187 65 115 33 187 19

210 46 177 226 0 46 77 226 192

138 145 189 200 138 185 189 200 217

21 45 76 92 210 5 176 92 87

a) Create 1x5 sized kernel of the Gaussian filter with = 1.

b) Find the value of the pixel at (4, 5) after it has been filtered with the Gaussian filter?

c) Find the value of the pixel at (5, 7) if it was filtered using a 3x3 median filter.

d) Find the value of the pixel at (3, 6) if it was filtered using a 3x3 box filter.

e) What would be the pixel value at (7, 8) if gamma correction was applied for = 0.5.

Explanation / Answer

clear all; close all;
%----Given Image----%
A=[10 6 27 165 10 11 27 165 17;
54 23 11 209 54 23 11 209 18;
65 115 33 187 65 115 33 187 19;
10 0 23 165 108 8 27 165 17;
54 23 112 209 4 23 11 9 18;
65 115 133 187 65 115 33 187 19;
210 46 177 226 0 46 77 226 192;
138 145 189 200 138 185 189 200 217;
21 45 76 92 210 5 176 92 87];

imwrite(A, 'image.png');

%-----(a). Create 1x5 sized kernel of the Gaussian filter with = 1 -> So take the range of X as [-2,2] with size 5 and centered at origin----%
sigma=1; x=-2:2;
G=(1/(sqrt(2*pi)*sigma))*exp(-x.*x/(2*sigma^2))


%----(b). The value of pixel (4,5) after filtering with gaussian Filter----%
A_mask=A(4,5-2:5+2);
A_gaussian45=sum(A_mask.*G);
display(['The value of pixel(4,5) after Filtering with Gaussian Filter is ',num2str(A_gaussian45)]);

%---(c). Find the value of the pixel at (5, 7) if it was filtered using a 3x3 median filter---%
%----Median filter is a type of filtering where the resultant pixel value will be the median os all the values covered by the mask, here mask size=3*3---%
A_mask=A(5-1:5+1,7-1:7+1); %Taking all the elements around teh pixel (5,7)
A_mask_vector=[A_mask(1,:) A_mask(2,:) A_mask(3,:)];
A_median57=median(A_mask_vector);
display(['The value of pixel(5,7) after Filtering with 3*3 Median Filter is ',num2str(A_median57)]);


%---d) Find the value of the pixel at (3, 6) if it was filtered using a 3x3 box filter---%
%----A Box Filter is nothing but a Mean Filter, here size=3*3. SO, FIlter=(1/9)[1 1 1;1 1 1;1 1 1]---%
Box_filter=ones(3,3)/sum(sum(ones(3,3)));
A_box_filtered36=sum(sum((A(3-1:3+1,6-1:6+1).*Box_filter)));
display(['The value of pixel(3,6) after Filtering with 3*3 Box Filter is ',num2str(A_box_filtered36)]);


%---e) What would be the pixel value at (7, 8) if gamma correction was applied for = 0.5---%
gammaValue=0.5;
gammaCorrection = 255 * (A/255).^gammaValue;
display(['The value of pixel(7,8) after applying gamma correction with gamma=0.5 is ',num2str(gammaCorrection(7,8))]);

%---PROGRAM ENDS---%

Output:

G =

0.0540 0.2420 0.3989 0.2420 0.0540 --->Gaussian Filter

The value of pixel(4,5) after Filtering with Gaussian Filter is 87.6462
The value of pixel(5,7) after Filtering with 3*3 Median Filter is 27
The value of pixel(3,6) after Filtering with 3*3 Box Filter is 49.3333
The value of pixel(7,8) after applying gamma correction with gamma=0.5 is 240.0625

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote