retrieveImages
搜索图像相似的图像
语法
描述
返回图像标识符imageid
= retrieveImages (queryImage
,imageIndex
)imageid
对应于图像中imageIndex
视觉相似查询的形象。的imageid
返回排名顺序,从最至少相似匹配。
(
选择返回相似度得分用于图像检索结果排序。的imageid
,分数
)= retrieveImages (queryImage
,imageIndex
)分数
输出包含相应的分数从0到1。
(
选择返回视觉单词imageid
,分数
,imageWords
)= retrieveImages (queryImage
,imageIndex
)queryImage
用于搜索类似的图片。
(
使用指定的一个或多个额外的选项imageid
,___)= retrieveImages (queryImage
,imageIndex
,名称,值
)名称,值
对参数,使用任何前面的语法。
例子
搜索图像设置使用查询图像
创建一个图像的书籍封面。
dataDir = fullfile (toolboxdir (“愿景”),“visiondata”,“封套”);封套= imageDatastore (dataDir);
显示的数据集。
thumbnailGallery = [];为i = 1:长度(bookCovers.Files)我= readimage(封套,我);缩略图= imresize(我,(300 300));thumbnailGallery =猫(4 thumbnailGallery缩略图);结束图蒙太奇(thumbnailGallery);
索引图像集。这个步骤可能需要几分钟。
imageIndex = indexImages(封套);
创建一个使用Bag-Of-Features反向图像索引。- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -创建Bag-Of-Features。- - - - - - - - - - - - - - - - - - - - - - - - - *使用检测器方法选择特征点位置。*从所选特征点提取冲浪功能位置。* * 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 7/100 iterations (~0.70 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”]);imageid = retrieveImages (queryImage imageIndex);
显示查询图像及其最佳匹配,并排。
bestMatch = imageid (1);bestImage = imread (imageIndex.ImageLocation {bestMatch});图imshowpair (queryImage bestImage,“蒙太奇”)
搜索使用roi图像设置为特定的对象
搜索一组图像对象使用一个感兴趣的区域(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 (imd);
创建一个使用Bag-Of-Features反向图像索引。- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -创建Bag-Of-Features。- - - - - - - - - - - - - - - - - - - - - - - - - *使用检测器方法选择特征点位置。*从所选特征点提取冲浪功能位置。* * 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.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”,“黄色”)
您还可以使用imrect
函数来选择一个ROI交互。例如,queryROI = getPosition (imrect)
找到包含对象的图像。
imageid = retrieveImages (queryImage imageIndex,“投资回报”queryROI)
imageid =12 x1 uint32列向量1 11 6 12 2 3 8 10 13 14⋮
显示最匹配。
bestMatch = imageid (1);图imshow (imageIndex.ImageLocation {bestMatch})
几何验证使用estimateGeometricTransform2D
函数
使用视觉单词的位置来验证最佳的搜索结果。重新排列搜索结果根据几何信息,重复这个过程N搜索结果。
指定图像的位置。
dataDir = fullfile (toolboxdir (“愿景”),“visiondata”,“封套”);封套= imageDatastore (dataDir);
索引图像集。这个过程可能需要几分钟。
imageIndex = indexImages(封套);
创建一个使用Bag-Of-Features反向图像索引。- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -创建Bag-Of-Features。- - - - - - - - - - - - - - - - - - - - - - - - - *使用检测器方法选择特征点位置。*从所选特征点提取冲浪功能位置。* * 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 7/100 iterations (~0.72 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)
检索的最佳匹配。的queryWords
输出包含查询图像的视觉单词的位置信息。使用此信息来验证搜索结果。
[imageid, ~, queryWords] = retrieveImages (queryImage imageIndex);
找到最佳匹配的查询图像从图像中提取的视觉词汇索引。图像索引包含所有图片的视觉词信息的索引。
bestMatch = imageid (1);bestImage = imread (imageIndex.ImageLocation {bestMatch});bestMatchWords = imageIndex.ImageWords (bestMatch);
基于视觉单词生成一组初步匹配作业。每一个视觉单词查询中可以有多个匹配由于很难量化使用分配视觉单词。
queryWordsIndex = queryWords.WordIndex;bestMatchWordIndex = bestMatchWords.WordIndex;tentativeMatches = [];为i = 1:元素个数(queryWords.WordIndex) idx =找到(queryWordsIndex (i) = = bestMatchWordIndex);匹配= [repmat(我,元素个数(idx), 1) idx);tentativeMatches = [tentativeMatches;匹配);结束
显示了初步匹配点位置。有许多可怜的匹配。
里= queryWords.Location (tentativeMatches (: 1):);points2 = bestMatchWords.Location (tentativeMatches (:, 2):);里,图showMatchedFeatures (queryImage bestImage points2,“蒙太奇”)
消除贫穷的视觉单词作业使用estimateGeometricTransform2D
函数。请作业,配合有效的几何变换。
[tform, inlierIdx] =…estimateGeometricTransform2D (points2里,仿射的,…“MaxNumTrials”,2000);inlierPoints1 =里(inlierIdx:);inlierPoints2 = points2 (inlierIdx:);
为搜索结果排名的内围层的百分比。这样做时,几何验证应用程序N搜索结果。这些图像与一个更高比例的内围层更可能是相关的。
percentageOfInliers = (inlierPoints1, 1)。/尺寸大小(里,1);图showMatchedFeatures (queryImage bestImage inlierPoints1,…inlierPoints2,“蒙太奇”)
应用估计变换。
outputView = imref2d(大小(bestImage));Ir = imwarp (queryImage tform,“OutputView”,outputView);图imshowpair(红外、bestImage“蒙太奇”)
修改图片搜索的搜索参数
使用evaluateImageRetrieval
函数来帮助选择合适的搜索参数。
创建一个图像集。
setDir = fullfile (toolboxdir (“愿景”),“visiondata”,“imageSets”,“杯子”);imd = imageDatastore (setDir,“IncludeSubfolders”,真的,“LabelSource”,“foldernames”);
索引图像集。
imageIndex = indexImages (imd,“详细”、假);
优化图片搜索参数。
imageIndex。米atchThreshold = 0.2; imageIndex.WordFrequencyRange = [0 1]
imageIndex = invertedImageIndex属性:ImageLocation: {6} x1细胞ImageWords: x1 vision.internal.visualWords [6] WordFrequency: [1 x1366双]BagOfFeatures: [1 x1 BagOfFeatures] ImageID: (1 2 3 4 5 6) MatchThreshold: 0.2000 WordFrequencyRange: [0 1]
queryImage = readimage (imd, 1);指数= retrieveImages (queryImage imageIndex);
输入参数
queryImage
- - - - - -输入查询图像
米——- - - - - -N3真彩图像|米——- - - - - -N二维灰度图像
输入查询图像,指定为一个米——- - - - - -N3真彩图像或一个米——- - - - - -N二维灰度图像。
数据类型:单
|双
|int16
|uint8
|uint16
|逻辑
imageIndex
- - - - - -图片搜索索引
invertedImageIndex
对象
图片搜索指数,作为指定invertedImageIndex
对象。的indexImages
函数创建invertedImageIndex
对象,该对象用于存储数据的图像搜索。
名称-值参数
指定可选的双参数作为Name1 = Value1,…,以=家
,在那里的名字
参数名称和吗价值
相应的价值。名称-值参数必须出现在其他参数,但对的顺序无关紧要。
R2021a之前,用逗号来分隔每一个名称和值,并附上的名字
在报价。
例子:“NumResults”
,25
设置“NumResults”
财产25
NumResults
- - - - - -最大数量的结果
20.
(默认)|数值
返回的结果的最大数量,指定为逗号分隔两人组成的“NumResults
“和一个数值。将这个值设置为正
返回尽可能多的匹配图像。
ROI
- - - - - -查询图片搜索区域
[1 1大小(queryImage, 2)大小(queryImage 1)]
(默认)|(xy宽度高度)向量
查询图片搜索区域,指定为逗号分隔两人组成的“ROI
“和一个xy宽度高度)向量。
度规
- - - - - -相似性度量
的余弦
(默认)|“L1”
相似性度量用于图像检索结果排名,指定为的余弦
或“L1”
[3]。
输出参数
imageid
,排名指数检索图像
米1的向量
排名指数检索图像,作为一个返回米1的向量。图像id返回排名顺序,从最至少相似匹配图像。
imageWords
——对象用于存储视觉单词的作业
visualWords
对象
对象存储视觉单词的作业,作为一个返回visualWords
对象。对象存储的视觉单词的作业queryImage
在这一形象及其位置。
引用
[1]Sivic, j . a . Zisserman。谷歌视频:一个文本对象匹配的视频检索方法。ICCV pg (2003) 1470 - 1477。
[2]Philbin, J。,O. Chum, M. Isard, J. Sivic, and A. Zisserman.对象与大型词汇表和快速检索空间匹配。CVPR (2007)。
[3]Galvez-Lopez,多里安人,胡安·d·缓慢的。袋的二进制字快速识别在图像序列。IEEE机器人28.5 (2012):1188 - 1197。
版本历史
MATLAB命令
你点击一个链接对应MATLAB命令:
运行该命令通过输入MATLAB命令窗口。Web浏览器不支持MATLAB命令。万博1manbetx
你也可以从下面的列表中选择一个网站:
表现最好的网站怎么走吗
选择中国网站(中文或英文)最佳站点的性能。其他MathWorks国家网站不优化的访问你的位置。