function IAS_create_kernel_jpgs(dir)
% IAS_create_kernel_jpgs - create 5x5 kernel windows as jpgs
%  * from fspecial:
%      average
%      disk
%      gaussian (with sigma = [0.5:0.1:3])
%      log (with sigma = [0.5:0.1:3])
%  * Fourier basis windows
%      u = [1:4]
%      v = [1:4]
%  * Gabor kernels
%      wavelengths (pixels/cycle): [2:5]
%      orientations (degrees): [0:359]
% On input:
%     dir (string): name of directory for kernel images
% On output:
%     writes 5x5 jpgs to directory
% Call:
%     IAS_create_kernel_jpgs('kernels');
% Author:
%     T. Henderson
%     UU
%     Spring 2025
%

H = 5;   % kernel size

sigma = [0.5:0.1:3];
num_sigma = length(sigma);

u = [1:4];
num_u = length(u);
v = [1:4];
num_v = length(v);

wavelengths = [2:5];
num_wavelengths = length(wavelengths);
orientations = [0:359];
num_orientations = length(orientations);

count = 0;

% fspecial kernels
count = count + 1;
K = fspecial("average",H);
fname = [dir,'\K',int2str(count),'.jpg'];
imwrite(K,fname);

count = count + 1;
K = fspecial("disk",H);
fname = [dir,'\K',int2str(count),'.jpg'];
imwrite(K,fname);

for k = 1:num_sigma
    s = sigma(k);
    count = count + 1;
    K = fspecial('gaussian',H,s);
    fname = [dir,'\K',int2str(count),'.jpg'];
    imwrite(K,fname);
end

for k = 1:num_sigma
    s = sigma(k);
    count = count + 1;
    K = fspecial('log',H,s);
    fname = [dir,'\K',int2str(count),'.jpg'];
    imwrite(K,fname);
end

% Fourier Transform kernels

for k1 = 1:num_u
    u1 = u(k1);
    for k2 = 1:num_v
        v1 = v(k2);
        count = count + 1;
        K = CS6640_basis_FT(u1,v1,H,H);
        fname = [dir,'\K',int2str(count),'.jpg'];
        imwrite(K,fname);
    end
end 

% Gabor kernels

g = gabor(wavelengths,orientations);
num_g = length(g);

for k = 1:num_g
    count = count + 1;
    K = g(k).SpatialKernel;
    fname = [dir,'\K',int2str(count),'.jpg'];
    imwrite(K,fname);
end 

tch = 0;
