% Test Pattern  (Grating)
clear;
W=512; %‰¡•�
H=512; %�c•�
I1=zeros(H,W);
 
I_center=128;
I_mod=128;


f_start=0; % �Å’á‹óŠÔŽü”g�”
f_stop=50; % �Å�‚‹óŠÔŽü”g�” cycle/W
f_w=f_stop-f_start;

for x=1:W;
    for y=1:H;
        r=sqrt(((x-1)/W)^2+((y-1)/H)^2);
        I1(y,x)=I_center+I_mod*cos((2*pi*f_start+pi*f_w*r^2))+randn*100;
    end
end
figure(1)
imagesc(I1,[0,256]);colormap(gray)


for loop =1:3;
if loop==1;
% Filter(A)
filter=(1/9)*[1 1 1; 1 1 1; 1 1 1];

else
    if loop==2;
% Filter(B)
filter=(1/10)*[1 1 1; 1 2 1; 1 1 1];
else
        % Filter(C)
        filter=(1/16)*[1 2 1; 2 4 2; 1 2 1];
    end
end
% Filtering
I2=zeros(H,W);
for x=2:W-1;
    for y=2:H-1;
        M=I1(x-1: x+1, y-1:y+1);
        F=M.*filter;
        I2(y,x)=sum(F(:));
    end
end
figure
subplot(1,1,1); imagesc(I2,[0 256]); colormap(gray)
end

 
