how to match an image descriptor to all descriptor in database
3 次查看(过去 30 天)
显示 更早的评论
i want to match my selected image (descriptor) with the database (descriptors) i created. so this is my code to match the selected descriptor with ONLY 1 descriptor in the database :
clc
clear all
close all
[file, path] = uigetfile('*.jpg','Choose Image');
im = imread([path file]);
gray = rgb2gray(im);
[desc] = Descriptor(gray);
dataset1 = load('dataset1.mat');
datasets = dataset1.dataset{1};
Cosine = pdist2(desc, datasets, 'cosine');
CosineSim = [Cosine];
CosIndex = zeros(30,2);
for i = 1:30
[k, ind] = min(Cosine(i,:));
CosIndex(i,1) = k;
CosIndex(i,2) = ind;
Cosine(:,ind) = ones(30,1)*1000;
end
i want the result to be 'CosIndex' for every match with the dataset. in the code above i use 'datasets = dataset1.dataset{1};' just to try one match between two descriptor.
i've tried to use loop and cell 'or 'CosIndex' as many as the dataset but the result is only in the last cell, maybe my loop is error (sorry i already delete the code).
can anyone help me the most efficient way (maybe using cell) to do that?
thank you.
0 个评论
回答(1 个)
Nalini Vishnoi
2014-10-1
You can use 'cellfun' to apply a function to each cell in the cell array. Here is some code tailored to your application:
datasets = dataset1.dataset; % reading all the descriptors in a cell array
Cosine = cellfun(@(x) pdist2(desc,x), datasets, 'cosine'); % using cellfun to apply pdist2 to all the cells in the cell array
You can find more documentation of 'cellfun' on the following link: http://www.mathworks.com/help/matlab/ref/cellfun.html
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!