www.gusucode.com > vision 源码程序 matlab案例代码 > vision/SearchImageSetUsingQueryImageExample.m
%% Search Image Set Using a Query Image % %% % Create an image set. setDir = fullfile(toolboxdir('vision'),'visiondata','imageSets','cups'); imds = imageDatastore(setDir); %% % Index the image set. imageIndex = indexImages(imds) %% % Display the image set using the |montage| function. thumbnailGallery = []; for i = 1:length(imds.Files) I = readimage(imds,i); thumbnail = imresize(I,[300 300]); thumbnailGallery = cat(4,thumbnailGallery,thumbnail); end figure montage(thumbnailGallery); %% % Select a query image. queryImage = readimage(imds,2); figure imshow(queryImage) %% % Search the image set for similar image using query image. The best % result is first. indices = retrieveImages(queryImage,imageIndex) bestMatchIdx = indices(1); %% % Display the best match from the image set. bestMatch = imageIndex.ImageLocation{bestMatchIdx} figure imshow(bestMatch)