function [D] = calc_bases_distance(A, dim_r)
% save_bases_as_kernels - save bases as filters
%
% A        the bases, with patches as column vectors
% prefix - the prefix of those kernels
%

% This is the side of the window
dim_c = size(A,1)/dim_r;
if dim_c - floor(dim_c)~=0 error('Filter size not interger!'); end;
D = zeros([size(A,2) size(A,2)]);
for i=1:size(A,2),
    fname = [sprintf('%s_%d.ker', prefix,i-1)];
    % This sets the patch
    I = reshape(A(:,i),[dim_r dim_c]);
    for j=1:size(A,2),
     J = reshape(A(:,j),[dim_r dim_c]);
     D(i,j) = sum(sum(abs(I-J)));
     if j < i, 
       for k1 =1:dim_r,
        for k2 = 1:dim_c,
           diff = 0.;
           ci1 = k1;
           for i1=1:dim_r,
             cj1 = k2;
             for j1=1:dim_c,
               diff = diff + (I(i1,j1)-J(ci1,cj1))^2;
               cj1 = cj1+1;
               if cj1 > dim_c,
                 cj1 = 1;
               end;
             end
     end
end
return;


