主要内容

retrieveImages

搜索图像集中的相似图像

描述

例子

imageid= retrieveImages (queryImageimageIndex返回图像标识符。imageid与里面的图像相对应imageIndex在视觉上与查询图像相似。的imageid按排序顺序返回,从相似度最高的匹配到相似度最低的匹配。

例子

imageid分数= retrieveImages(queryImageimageIndex可选地返回用于对图像检索结果排序的相似性分数。的分数输出包含从0到1的对应分数。

例子

imageid分数imageWords= retrieveImages(queryImageimageIndex可选地返回可视单词queryImage用来搜索相似的图像。

例子

imageid___= retrieveImages(queryImageimageIndex名称,值使用一个或多个指定的其他选项名称,值对参数,使用前面的任何语法。

例子

全部折叠

创建一个图书封面的图像集。

dataDir = fullfile(toolboxdir(“愿景”),“visiondata”“封套”);bookCovers = imageDatastore(dataDir);

显示数据集。

thumbnailGallery = [];i = 1:length(bookCovers. files) i = readimage(bookCovers,i);thumbnail = imresize(I,[300 300]);thumbnailGallery = cat(4,thumbnailGallery,thumbnail);结束图蒙太奇(thumbnailGallery);

图中包含一个轴对象。axis对象包含一个image类型的对象。

索引图像集。这一步可能需要几分钟。

imageIndex = indexImages(bookCovers);
使用Bag-Of-Features创建反向图像索引。------------------------------------------------------- 创建Bag-Of-Features。------------------------- * 选择使用检测器方法特征点的位置。*从选定的特征点位置提取SURF特征。** detectSURFFeatures用于检测关键点进行特征提取。*从58张图像中提取特征…完成。提取29216个特征。*保留每个类别中80%的最强功能。*平衡所有图像类别的特征数量,以改善聚类。**图像类别1的最强特征数量最少:23373。 ** Using the strongest 23373 features from each of the other image categories. * Creating a 20000 word visual vocabulary. * Number of levels: 1 * Branching factor: 20000 * Number of clustering steps: 1 * [Step 1/1] Clustering vocabulary level 1. * Number of features : 23373 * Number of clusters : 20000 * Initializing cluster centers...100.00%. * Clustering...completed 10/100 iterations (~0.96 seconds/iteration)...converged in 10 iterations. * Finished creating Bag-Of-Features Encoding images using Bag-Of-Features. -------------------------------------- * Encoding 58 images...done. Finished creating the image index.

选择并显示查询图像。

queryDir = fullfile(dataDir,“查询”, filesep);queryImage = imread([queryDir .“query3.jpg”]);imageIDs =检索图像(queryImage,imageIndex);

并排显示查询图像及其最佳匹配。

bestMatch = imageIDs(1);bestImage = imread(imageIndex.ImageLocation{bestMatch});图imshowpair (queryImage bestImage,“蒙太奇”

图中包含一个轴对象。axis对象包含一个image类型的对象。

使用查询图像的感兴趣区域(ROI)在图像集中搜索对象。

定义一组要搜索的图像。

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);

创建一个搜索索引。

imageIndex = indexImages(imds);
使用Bag-Of-Features创建反向图像索引。------------------------------------------------------- 创建Bag-Of-Features。------------------------- * 选择使用检测器方法特征点的位置。*从选定的特征点位置提取SURF特征。** detectSURFFeatures用于检测关键点进行特征提取。*从16张图像中提取特征…完成。提取了3680个特征。*保留每个类别中80%的最强功能。*平衡所有图像类别的特征数量,以改善聚类。**图像类别1的最强特征数量最少:2944个。 ** Using the strongest 2944 features from each of the other image categories. * Creating a 2944 word visual vocabulary. * Number of levels: 1 * Branching factor: 2944 * Number of clustering steps: 1 * [Step 1/1] Clustering vocabulary level 1. * Number of features : 2944 * Number of clusters : 2944 * Initializing cluster centers...100.00%. * Clustering...completed 1/100 iterations (~0.05 seconds/iteration)...converged in 1 iterations. * Finished creating Bag-Of-Features Encoding images using Bag-Of-Features. -------------------------------------- * Encoding 16 images...done. Finished creating the image index.

指定一个查询映像和一个ROI。ROI勾勒出搜索的对象,即大象。

queryImage = imread(“clutteredDesk.jpg”);queryROI = [130 175 330 365];图imshow(queryImage)“位置”queryROI,“EdgeColor”“黄色”

图中包含一个轴对象。axis对象包含2个图像、矩形类型的对象。

你也可以使用imrect功能,交互选择ROI。例如,queryROI = getPosition(imrect)

找到包含该对象的图像。

imageIDs =检索图像(queryImage,imageIndex,“投资回报”queryROI)
imageid =13x1 uint32列向量1 11 6 12 13 3 2 8 14 10

显示最佳匹配。

bestMatch = imageIDs(1);图imshow (imageIndex.ImageLocation {bestMatch})

图中包含一个轴对象。axis对象包含一个image类型的对象。

使用视觉词的位置来验证最佳搜索结果。若要根据几何信息重新排列搜索结果,请对顶部重复此过程N搜索结果。

指定图像的位置。

dataDir = fullfile(toolboxdir(“愿景”),“visiondata”“封套”);bookCovers = imageDatastore(dataDir);

索引图像集。这个过程可能需要几分钟。

imageIndex = indexImages(bookCovers);
使用Bag-Of-Features创建反向图像索引。------------------------------------------------------- 创建Bag-Of-Features。------------------------- * 选择使用检测器方法特征点的位置。*从选定的特征点位置提取SURF特征。** detectSURFFeatures用于检测关键点进行特征提取。*从58张图像中提取特征…完成。提取29216个特征。*保留每个类别中80%的最强功能。*平衡所有图像类别的特征数量,以改善聚类。**图像类别1的最强特征数量最少:23373。 ** Using the strongest 23373 features from each of the other image categories. * Creating a 20000 word visual vocabulary. * Number of levels: 1 * Branching factor: 20000 * Number of clustering steps: 1 * [Step 1/1] Clustering vocabulary level 1. * Number of features : 23373 * Number of clusters : 20000 * Initializing cluster centers...100.00%. * Clustering...completed 10/100 iterations (~2.63 seconds/iteration)...converged in 10 iterations. * Finished creating Bag-Of-Features Encoding images using Bag-Of-Features. -------------------------------------- * Encoding 58 images...done. Finished creating the image index.

选择并显示查询图像。

queryDir = fullfile(dataDir,“查询”, filesep);queryImage = imread([queryDir .“query3.jpg”]);图imshow (queryImage)

图中包含一个轴对象。axis对象包含一个image类型的对象。

检索最佳匹配。的queryWords输出包含查询图像的可视化单词位置信息。使用此信息来验证搜索结果。

[imageIDs, ~, queryWords] =检索图像(queryImage,imageIndex);

通过从图像索引中提取视觉词,找到与查询图像的最佳匹配。图像索引包含索引中所有图像的视觉单词信息。

bestMatch = imageIDs(1);bestImage = imread(imageIndex.ImageLocation{bestMatch});bestMatchWords = imageIndex.ImageWords(bestMatch);

根据可视化的单词分配生成一组暂定匹配。查询中的每个可视化单词都可以有多个匹配项,这是由于用于分配可视化单词的硬量化。

queryWordsIndex = querywords . worddex;bestMatchWordIndex = bestMatchWords.WordIndex;tentativeMatches = [];i = 1: nummel (queryWordsIndex . worddex) idx = find(queryWordsIndex(i) == bestmatchworddex);匹配= [repmat(i, numel(idx), 1) idx];tentativeMatches = [tentativeMatches;匹配);结束

显示暂定匹配的点位置。有很多糟糕的匹配。

points1 = queryWords.Location(tentativeMatches(:,1),:);points2 = bestMatchWords.Location(tentativeMatches(:,2),:);里,图showMatchedFeatures (queryImage bestImage points2,“蒙太奇”

图中包含一个轴对象。axis对象包含image、line等类型的4个对象。一行或多行仅使用标记显示其值

删除使用的糟糕的视觉单词分配estimateGeometricTransform2D函数。保留符合有效几何变换的赋值。

[tform, inlierIdx] =estimateGeometricTransform2D (points2里,仿射的“MaxNumTrials”, 2000);inlierPoints1 = points1(inlierIdx,:);inlierPoints2 = points2(inlierIdx,:);

根据内线的百分比重新排列搜索结果。当几何验证程序应用于顶部时,这样做吗N搜索结果。那些内线百分比较高的图像更有可能是相关的。

percentageOfInliers = size(inlierpoints1,1)./size(points1,1);图showMatchedFeatures (queryImage bestImage inlierPoints1,inlierPoints2,“蒙太奇”

图中包含一个轴对象。axis对象包含image、line等类型的4个对象。一行或多行仅使用标记显示其值

应用估计的转换。

outputView = imref2d(size(bestImage));Ir = imwarp(queryImage, tform,“OutputView”, outputView);图imshowpair(红外、bestImage“蒙太奇”

图中包含一个轴对象。axis对象包含一个image类型的对象。

使用evaluateImageRetrieval函数帮助选择适当的搜索参数。

创建一个映像集。

setDir = fullfile(toolboxdir(“愿景”),“visiondata”“imageSets”“杯子”);imds = imageDatastore(setDir,“IncludeSubfolders”,真的,“LabelSource”“foldernames”);

索引图像集。

imageIndex = indexImages(imds,“详细”、假);

调优图像搜索参数。

imageIndex。米atchThreshold = 0.2; imageIndex.WordFrequencyRange = [0 1]
imageIndex = invertedImageIndex with properties: ImageLocation: {6x1 cell} ImageWords: [6x1 vision.internal.visualWords] WordFrequency: [1x1366 double] BagOfFeatures: [1x1 BagOfFeatures] ImageID: [1 2 3 4 5 6] MatchThreshold: 0.2000 WordFrequencyRange: [0 1]
queryImage = readimage(imds, 1);indexes =检索图像(queryImage,imageIndex);

输入参数

全部折叠

输入查询图像,指定为——- - - - - -N-by-3真彩色图像或——- - - - - -N二维灰度图像。

数据类型:||int16|uint8|uint16|逻辑

图像搜索索引,指定为invertedImageIndex对象。的indexImages函数创建invertedImageIndex对象,该对象存储用于图像搜索的数据。

名称-值参数

指定可选参数对为Name1 = Value1,…,以=家,在那里的名字参数名称和价值对应的值。名称-值参数必须出现在其他参数之后,但对的顺序无关紧要。

在R2021a之前,使用逗号分隔每个名称和值,并将其括起来的名字在报价。

例子:“NumResults”25设置“NumResults”财产25

要返回的最大结果数,指定为逗号分隔的对,由'NumResults和一个数值。将此值设置为返回尽可能多的匹配图像。

查询图像搜索区域,指定为逗号分隔的对,由'ROI'和an [xy宽度高度)向量。

用于对图像检索结果排序的相似度度量,指定为的余弦“L1”[3]

输出参数

全部折叠

检索到的图像的排序索引,返回为1的向量。图像id按顺序返回,从相似度最高的匹配图像到相似度最低的匹配图像。

相似度度量,返回为N1的向量。类中检索到的图像对应的分数imageid输出。分数计算使用度规属性和从0到1的范围。

对象,用于存储可视化单词赋值,返回为visualWords对象。对象存储的可视单词赋值queryImage以及它们在图像中的位置。

参考文献

[1]西维克,J. A.泽瑟曼。视频谷歌:一种用于视频对象匹配的文本检索方法.ICCV (2003) pg 1470-1477。

[2]菲尔宾,J., O. Chum, M. Isard, J. Sivic和A. Zisserman。具有大词汇量和快速空间匹配的对象检索.CVPR(2007)。

[3] Gálvez-López,多里安和胡安·d·塔多斯。用于图像序列中快速位置识别的二进制单词袋。IEEE机器人学报28.5(2012):1188-1197。

扩展功能

C/ c++代码生成
使用MATLAB®Coder™生成C和c++代码。

版本历史

在R2015a中引入