how to match an image descriptor to all descriptor in database

3 views (last 30 days)
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 :
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;
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.

Answers (1)

Nalini Vishnoi
Nalini Vishnoi on 1 Oct 2014
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:


Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!