clear all;
close all;

[A,MAP] = imread('rodina.pgm','pgm');
dpN = 3/10;
DPfilterSize = floor(size(A,1)*dpN/2);

hpN = 1/10;
HPfilterSize = floor(size(A,1)*hpN/2);

imshow(A);

MAP = [];
for index=1:257
    MAP = [MAP;(index-1)/256 (index-1)/256 (index-1)/256];
end

%Fourierka
figure;
imshow(A);
FA = FFT2(A);
SFA = FFTSHIFT(FA);

figure;
imshow(abs(SFA),MAP);
figure;
imshow(unwrap(angle(SFA)),MAP);

%DP filtracia
DP = zeros(size(A,1),size(A,2));
DP(size(A,1)/2-DPfilterSize:size(A,1)/2+DPfilterSize,size(A,2)/2-DPfilterSize:size(A,2)/2+DPfilterSize)=1;
figure;
imshow(DP);

SFAF = SFA.*DP
FAF = IFFTSHIFT(SFAF);
AF = IFFT2(FAF);
figure;
imshow(abs(AF),MAP);

%HP filtracia
HP = ones(size(A,1),size(A,2));
HP(size(A,1)/2-HPfilterSize+1:size(A,1)/2+HPfilterSize+1,size(A,2)/2-HPfilterSize+1:size(A,2)/2+HPfilterSize+1)=0;
figure;
imshow(HP);

SFAF = SFA.*HP;
AF = IFFT2(SFAF);
figure;
imshow(abs(AF),MAP);

for index1=1:256
    for index2=1:256
        FAshift(index1,index2) = SFA(index1,index2)*exp(-i*(100*2*pi/256)*index2)*exp(-i*(100*2*pi/256)*index1);
    end
end
AF = IFFT2(FAshift);
figure;
imshow(abs(AF),MAP);