www.gusucode.com > vision 源码程序 matlab案例代码 > vision/SearchSetImagesForSpecificObjectExample.m
%% Search Image Set for Specific Object Using ROIs % Search an image set for an object using a region of interest (ROI) for the query image. %% % Define a set of images to search. imageFiles = ... {'elephant.jpg', 'cameraman.tif', ... 'peppers.png', 'saturn.png',... 'pears.png', 'stapleRemover.jpg', ... 'football.jpg', 'mandi.tif',... 'kids.tif', 'liftingbody.png', ... 'office_5.jpg', 'gantrycrane.png',... 'moon.tif', 'circuit.tif', ... 'tape.png', 'coins.png'}; imds = imageDatastore(imageFiles); %% % Create a search index. imageIndex = indexImages(imds); %% % Specify a query image and an ROI. The ROI outlines the object, an elephant, for the search. queryImage = imread('clutteredDesk.jpg'); queryROI = [130 175 330 365]; figure imshow(queryImage) rectangle('Position',queryROI,'EdgeColor','yellow') %% % You can also use the |imrect| function to select an ROI interactively. For example, |queryROI = getPosition(imrect)| %% % Find images that contain the object. imageIDs = retrieveImages(queryImage,imageIndex,'ROI',queryROI) %% % Display the best match. bestMatch = imageIDs(1); figure imshow(imageIndex.ImageLocation{bestMatch})