% CIS 601 Computer Graphics and Image Processing
% Homework 2                    Spring 2007
% Riu Baring
% ==============================================
% query function
% ==============================================

function [img1, img2] = query(img)

% Array pre-allocation
sim = zeros(1, 8);

for i = 1:8
    % Read an image from the database
    dbimg{i} = imresize(imread(sprintf('image%d.jpg', i)), [240 320]);
    
    % Check histogram similarity between img (queried image) and dbimg (an
    % image in the database)
    sim(i) = histogramSimilarity(img, dbimg{i});
end

% Sort the sim values in ascending order
[val ind] = sort(sim);

% Get the first best match image
img1 = dbimg{ind(1)};

% Get the second best match image
img2 = dbimg{ind(2)};
