function CERW_batch_preprocess(input_dir,output_dir,options)

% only supported extensions are tif and pgm
if isfield(options,'in_extn')
    in_extn = char(options.in_extn);
    if (~isequal(in_extn,'tif') && ~isequal(in_extn,'pgm'))
        error('Input extension must be tif or pgm');
    end
else
    in_extn = 'tif';
end
% only output as pgm files
out_extn = 'pgm';

[input_names,image_names] = get_files(input_dir,strcat('(\w+).',in_extn));
output_names = strcat(image_names,'.',out_extn);
file_count = numel(input_names);

if(file_count > 0)
    if exist(output_dir,'dir') == 0
        mkdir(output_dir);
    end
end

for i = 1:file_count
    input_path = fullfile(input_dir, input_names(i));
    if isequal(in_extn,'tif')
        im_in = imread3(input_path);
    elseif isequal(in_extn,'pgm')
        im_in = pgmread3(input_path);
    end
    im_out = CERW_preprocess_image(im_in,options);
    output_path = fullfile(output_dir,output_names(i));
    pgmwrite3(im_out,output_path);
end

end
