主要内容

retrieveImages

搜索图像集为类似的图像

描述

例子

remogids.= retrieveImages (queryImageimageIndex返回图像标识符remogids.对应于里面的图像imageIndex它们在视觉上与查询图像相似。的remogids.按相似匹配的从多到少的顺序返回。

例子

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

例子

remogids.分数映号) = retrieveImages (queryImageimageIndex可选地返回可视的单词queryImage用于搜索类似图像的。

例子

remogids.___) = retrieveImages (queryImageimageIndex名称,值使用一个或多个指定的附加选项名称,值配对参数,使用任何前面的语法。

例子

全部折叠

创建图书封面的图像集。

datadir = fullfile(toolboxdir(“愿景”),'VisionData''书柜');封套= imageDatastore (dataDir);

显示数据集。

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

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

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

imageIndex = IndexImages(Bookcovers);
使用Bag-Of-Features创建倒置的图像索引。------------------------------------------------------- 创建Bag-Of-Features。------------------------- * 选择使用检测器方法特征点的位置。*从选定的特征点位置提取SURF特征。** detectsurfeatures用于检测关键点进行特征提取。*从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 7/100 iterations (~0.58 seconds/iteration)...converged in 7 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 =检索agages(QueryImage,imageIndex);

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

bestMatch = imageid (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'};imd = imageDatastore (imageFiles);

创建一个搜索索引。

imageIndex = IndexImages(IMDS);
使用Bag-Of-Features创建倒置的图像索引。------------------------------------------------------- 创建Bag-Of-Features。------------------------- * 选择使用检测器方法特征点的位置。*从选定的特征点位置提取SURF特征。** detectsurfeatures用于检测关键点进行特征提取。*从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.08 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”'黄色'

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

你也可以使用imrect以交互方式选择ROI的功能。例如,queryroi = getPosition(IMRECT)

找到包含该对象的图像。

imageid = retrieveImages (queryImage imageIndex,'roi',queryroi)
imageid =12x1 uint32列向量1 11 6 12 2 3 8 10 13 14⋮

显示最佳匹配。

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

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

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

指定图像的位置。

datadir = fullfile(toolboxdir(“愿景”),'VisionData''书柜');封套= imageDatastore (dataDir);

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

imageIndex = IndexImages(Bookcovers);
使用Bag-Of-Features创建倒置的图像索引。------------------------------------------------------- 创建Bag-Of-Features。------------------------- * 选择使用检测器方法特征点的位置。*从选定的特征点位置提取SURF特征。** detectsurfeatures用于检测关键点进行特征提取。*从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 7/100 iterations (~0.63 seconds/iteration)...converged in 7 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] =检索agages(QueryImage,imageIndex);

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

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

基于视觉字分配生成一组暂定匹配。由于用于分配视觉单词的硬量化,查询中的每个视觉单词都可以具有多个匹配。

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

显示试探性匹配的点位置。有许多不般配的人。

points1 = querywords.location(intrativeMatches(:,1),:);points2 = bestmatchwords.location(intrativeMatches(:,2),:);图ShowMatchedFeatures(QueryImage,Bestimage,Points1,Points2,“蒙太奇”

图中包含一个轴对象。轴对象包含4个类型图像的对象,线。

删除使用糟糕的视觉词分配estimateGeometricTransform2D功能。保持适合有效几何变换的作业。

[tform, inlierIdx] =...estisimeGeometricTransform2d(点1,点2,仿射的...“MaxNumTrials”,2000);Inlierpoints1 = point1(Inlieridx,:);Inlierpoints2 = point2(inlieridx,:);

通过替代者的百分比重新命名搜索结果。在将几何验证过程应用于顶部时执行此操作N搜索结果。那些嵌线率较高的图像更有可能是相关的。

percentageOfInliers = (inlierPoints1, 1)。/尺寸大小(里,1);图showMatchedFeatures (queryImage bestImage inlierPoints1,...inlierPoints2,“蒙太奇”

图中包含一个轴对象。轴对象包含4个类型图像的对象,线。

应用估计变换。

outputView = imref2d(大小(bestImage));Ir = imwarp(queryImage, tform,'outputview',OutputView);图imshowpair(IR,Bestimage,“蒙太奇”

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

使用evaluateMageretrieval.有助于选择正确搜索参数的功能。

创建一个图像集。

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

索引图像集。

imageIndex = IndexImages(IMDS,'verbose'、假);

调谐图像搜索参数。

imageIndex.matchthreshold = 0.2;imageindex.wordfrequencyRange = [0 1]
imageIndex = ImageDimageIndex具有属性:ImageLocation:{6x1 Cell} Imagewords:[6x1 Vision.internal.visualwords] WordFrequency:[1x1366 Double] Bagoffecate:[1x1 Bagoffeature] ImageId:[1 2 3 4 5 6] MatchThreshold:0.2000 WordFrequencyRange:[0 1]
QueryImage = ReadImage(IMDS,1);indices =检索agages(QueryImage,imageIndex);

输入参数

全部折叠

输入查询图像,指定为-经过-N-By-3 TrueColor图像或-经过-N2-D灰度图像。

数据类型:|双倍的|INT16|uint8.|uint16|逻辑

图像搜索索引,指定为一个invertedimageIndex.对象。的IndexImages.函数创建invertedimageIndex.对象,存储用于图像搜索的数据。

名称-值参数

指定可选的逗号分隔的对名称,值论点。姓名参数名和价值为对应值。姓名必须出现在引号内。可以以任意顺序指定多个名称和值对参数name1,value1,...,namen,valuen

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

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

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

相似性指标用于对指定的图像检索结果进行排名,指定为的余弦“L1”[3]

输出参数

全部折叠

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

相似度指标,作为一个返回N1的向量。的输出包含与检索到的图像对应的分数remogids.输出。使用该分数度规属性和0到1的范围。

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

参考文献

Sivic J.和A. Zisserman。视频谷歌:一种用于视频对象匹配的文本检索方法.ICCV (2003) pg 1470-1477。

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

[3] Gálvez-López, Dorian和Juan D. Tardos。图像序列中快速放置识别的二进制单词袋。计算机工程与应用。

介绍了R2015a