


clear; 
load 'model';
sub = 1; Lrange = 6; % for faster speed, you can remove this line. 

% TESTING IMAGE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
totalScale = 10;  % total number of scales
Sx1 = zeros(1, totalScale); Sy1 = zeros(1, totalScale); 
for(i=1:totalScale)
    J{i} = imresize(double(rgb2gray(imread('womanfind.jpg'))), .40+(i-1)*.03, 'nearest');  % scaled images
    [sx1, sy1] = size(J{i}); 
    Sx1(i) = sx1; Sy1(i) = sy1; % sizes of images
    tss1{i} = zeros(sx1, sy1);  % log-likelihood score map for testing images
    sym1{i} = zeros(sx1, sy1);  % symbolic sketch on testing image
end
mscale = zeros(1, totalScale);  % log-likelihood score over scales
ax = floor(sx/2); ay = floor(sy/2); % half size of bounding box


% VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(['start filtering']);
tic
allfiltered1 = applyfilterfftms(J, allfilter, Sx1(totalScale), Sy1(totalScale));  % filter training images
allmaxed = initialmax(J, allfilter);  % to be changed to local maximum
disp(['filtering time: ' num2str(toc) ' seconds']);

% MEX C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

mex Cfind.c;   % compile C code
disp(['start finding']);
tic
Cfind(totalScale, norient, allfiltered1, allmaxed, h, ax, ay, Mi, Mx, My, Mm, allsymbol(1, :), Lrange, Orange, sub, Totalsketch, Upperbound, tss1, sym1, Sx1, Sy1, mscale, LIK);
disp(['mex-C finding time: ' num2str(toc) ' seconds']);

% RESULTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    


maxscale = max(mscale);   % most likely scale
       figure; 
       subplot(3, 4, 1, 'v6');  imshow(rgb2gray(imread('womanfind.jpg')), []);   % original image
for(i=1:totalScale)       
       subplot(3, 4, i+2, 'v6');          
       imshow(J{i}+sym1{i}*100, []);  % overlaid sketch 
end




