% 2d signaly - obrazky 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x = imread('FIG/lena_cb.tif'); 
subplot(121); imagesc(x); colormap(gray); axis image; axis off
subplot(122); imagesc(x); colormap(gray); axis image; axis off
print -deps -loose FIG/ll.eps
% nee, je lepsi tisknout po jednom !
imagesc(x); colormap(gray); axis image; axis off
print -deps -loose FIG/ll.eps


% hratky s frekvencemi:
% black 
x = zeros(256,256); imagesc(x); axis image; axis off
print -deps -loose FIG/black.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,X(m+1,n+1)); axis image; 
print -deps -loose FIG/Sblack.eps

% white 
x = ones(256,256); image(64*x); axis image; axis off
print -deps -loose FIG/white.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,X(m+1,n+1)); axis image; 
print -deps -loose FIG/Swhite.eps

% ted kosiny
k = repmat((0:255)',1,256); l = repmat((0:255),256,1);
K = 256; L = 256; M=256; N=256; 

% kos vodorovne - druha odmocnina je lepsi nez log ... 
n = 0:255; N = 256; f=1/N;
x = 1/2+1/2*cos(2*pi*f*l); imagesc(z);axis image; axis off
print -deps -loose FIG/f1.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,sqrt(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Sf1.eps

% jeste jeden 
n = 0:255; N = 256; f=2/N;
x = 1/2+1/2*cos(2*pi*f*l); imagesc(x);axis image; axis off
print -deps -loose FIG/f2.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,sqrt(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Sf2.eps

%%% ted kos svisle:
%  druha odmocnina je lepsi nez log ... 
n = 0:255; N = 256; g=1/N;
x = 1/2+1/2*cos(2*pi*g*k); imagesc(x);axis image; axis off
print -deps -loose FIG/g1.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,sqrt(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Sg1.eps
  
% jeste s 4-nas frekv:  druha odmocnina je lepsi nez log ... 
n = 0:255; N = 256; g=4/N;
x = 1/2+1/2*cos(2*pi*g*k); imagesc(x);axis image; axis off
print -deps -loose FIG/g4.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,sqrt(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Sg4.eps
  

% co takhle obdelnik ? 
x = zeros(256,256); x(1:256,65:192) = 1;
imagesc(x);axis image; axis off
print -deps -loose FIG/obd.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,sqrt(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Sobd.eps

% a ctverec !!!  - tady to chvce log !
x = zeros(256,256); x(65:192,65:192) = 1;
imagesc(x);axis image; axis off
print -deps -loose FIG/ctverec.eps
X = fft2(x); m=0:9; n=0:9; imagesc(m,n,log(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Sctverec.eps

%%%%%%%% lena  - spec 
x = imread('FIG/lena_cb.tif'); z = double(x)/256;
imagesc(x); colormap(gray); axis image; axis off
%print -deps -loose FIG/orig.eps
X = fft2(x); m=0:127; n=0:127; imagesc(m,n,log(abs(X(m+1,n+1)))); axis image; 
print -deps -loose FIG/Slena.eps

%%%%%%%%%


%%%%%%%%% filtrovani Lena - DP, pak HP
x = imread('FIG/lena_cb.tif'); z = double(x)/256;
imagesc(x); colormap(gray); axis image; axis off
print -deps -loose FIG/orig.eps

zn = z+0.1*randn(512,512); 
imagesc(zn); colormap(gray); axis image; axis off
print -deps -loose FIG/noise.eps

% DP - musim vzit matici 10x10, jinak to neni videt ... 
m = ones(10,10); %[1 1 1; 1 1 1; 1 1 1];
dp = filter2(m,zn); 
imagesc(dp); colormap(gray); axis image; axis off
print -deps -loose FIG/dp.eps

% HP - ten podle Pavla... hm hm, moc se mi nelibi ... 
m =[0 -1 0; -1 5 -1; 0 -1 0];
hp = filter2(m,z); 
imagesc(hp); colormap(gray); axis image; axis off
print -deps -loose FIG/hp.eps

% det. vert contours 
m =[1 0 -1; 2 0 -2; 1 0 -1];
hpvert = filter2(m,z); vis = abs(hpvert); 
imagesc(log(vis+1)); colormap(gray); axis image; axis off
print -deps -loose FIG/hpvert.eps

% det. hor contours 
m =[1 0 -1; 2 0 -2; 1 0 -1]';
hphor = filter2(m,z); vis = abs(hphor); 
imagesc(log(vis+1)); colormap(gray); axis image; axis off
print -deps -loose FIG/hphor.eps

% oba dohromady ...
cont = abs(hphor) + abs(hpvert); 
imagesc(log(cont+1)); colormap(gray); axis image; axis off
print -deps -loose FIG/horvert.eps


% medianovy 10x10 ... zatim nee ... 

med = medfilt2(zn,[5 5]); 
imagesc(med); colormap(gray); axis image; axis off
print -deps -loose FIG/med.eps

%%%%%%% kvantovani %%%%%%
x = imread('FIG/lena_cb.tif'); z = double(x)/256;
imagesc(x); colormap(gray); axis image; axis off

zq = round(z * 4) / 4; 
imagesc(zq); colormap(gray); axis image; axis off
print -deps -loose FIG/quant.eps

