clear
close all

[in_im] = imread('test.png');

input = zeros(150,1);
input(51:100) = tukeywin(50,0);
lin_ph = tukeywin(20,1);
lin_ph = lin_ph/sum(lin_ph);
nonlin_ph = exp(-(1:30)'/30*5);
%nonlin_ph = lin_ph(end/2:end);
nonlin_ph = nonlin_ph/sum(nonlin_ph);
%%
plot(abs(fft(lin_ph,1024)))
hold on
plot(abs(fft(nonlin_ph,1024)),'--')
%%
plot(conv(input,lin_ph,'same'))
hold on
plot(conv(input,nonlin_ph,'same'),'--')
legend('Linear phase','Non-linear phase')
%%
R = double(in_im(:,:,1));
G = double(in_im(:,:,2));
B = double(in_im(:,:,3));

Rlin = conv2(R,lin_ph*lin_ph','same');
Glin = conv2(G,lin_ph*lin_ph','same');
Blin = conv2(B,lin_ph*lin_ph','same');

Rnl = conv2(R,nonlin_ph*nonlin_ph','same');
Gnl = conv2(G,nonlin_ph*nonlin_ph','same');
Bnl = conv2(B,nonlin_ph*nonlin_ph','same');
%%
out_lin = zeros(size(in_im));
out_lin(:,:,1) = uint8( Rlin );
out_lin(:,:,2) = uint8( Glin );
out_lin(:,:,3) = uint8( Blin );
out_lin = uint8(out_lin);

out_nl = zeros(size(in_im));
out_nl(:,:,1) = uint8( Rnl );
out_nl(:,:,2) = uint8( Gnl );
out_nl(:,:,3) = uint8( Bnl );
out_nl = uint8(out_nl);

figure
imshow(out_lin);

figure
imshow(out_nl);