%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Averaging demo

S = zeros(100,100);

S(40:60,40:60) = 1;

imagesc(S)

N = .1*randn(100,100);

imagesc(N)

I = S+N;

imagesc(I)

A = fspecial('average', 3)

O = conv2(A,I);

imagesc(O)

A = fspecial('average', 9)

O = conv2(A,I);

imagesc(O)

% Filtering and structure

G = fspecial('gaussian', 9, .5);

imagesc(conv2(G,I))

G = fspecial('gaussian', 9, 1.5);

imagesc(conv2(G,I))

G = fspecial('gaussian', 9, 3);

imagesc(conv2(G,I))

G = fspecial('gaussian', 18, 6);

imagesc(conv2(G,I))

G = fspecial('gaussian', 36, 12);

imagesc(conv2(G,I))

G = fspecial('gaussian', 9, .5);

imagesc(conv2(G,dogbw))

G = fspecial('gaussian', 9, 1.5);

imagesc(conv2(G,dogbw))

G = fspecial('gaussian', 9, 3);

imagesc(conv2(G,dogbw))

G = fspecial('gaussian', 18, 6);

imagesc(conv2(G,dogbw))

G = fspecial('gaussian', 36, 12);

imagesc(conv2(G,dogbw))

% Subsampling

A = zeros(100,100);

for i = 40:41 for j = 10:90 A(i,j) = 1; end, end

B = imrotate(A, 30);

imagesc(B)

imagesc(B(1:4:100,1:4:100))

G = fspecial('gaussian', 9, 3);

C = conv2(G,B);

imagesc(C)

imagesc(C(1:4:100,1:4:100))