www.gusucode.com > vision 源码程序 matlab案例代码 > vision/EvaluateImageRetrievalResultsExample.m
%% Evaluate Image Retrieval Results %% % Define a set of images. dataDir = fullfile(toolboxdir('vision'),'visiondata','bookCovers'); bookCovers = imageDatastore(dataDir); %% % Display the set of images. thumbnailGallery = []; for i = 1:length(bookCovers.Files) img = readimage(bookCovers,i); thumbnail = imresize(img,[300 300]); thumbnailGallery = cat(4,thumbnailGallery,thumbnail); end figure montage(thumbnailGallery); %% % Index the images. This will take a few minutes. imageIndex = indexImages(bookCovers); %% % Select and display the query image. queryDir = fullfile(dataDir,'queries',filesep); query = imread([queryDir 'query2.jpg']); figure imshow(query) %% % Evaluation requires knowing the expected results. Here, the query % image is known to be the 3rd book in the imageIndex. expectedID = 3; %% % Find and report the average precision score. [averagePrecision,actualIDs] = evaluateImageRetrieval(query,... imageIndex,expectedID); fprintf('Average Precision: %f\n\n',averagePrecision) %% % Show the query and best match side-by-side. bestMatch = actualIDs(1); bestImage = imread(imageIndex.ImageLocation{bestMatch}); figure imshowpair(query,bestImage,'montage')