knnsearch error while finding similar images
Show older comments
Hello guys;
I am new to matlab. I am going to make a program that finds similar images. but in the knnsearch i am getting an error. here is my code.
directory1 = fullfile('./buildings');
images1 = dir(fullfile(directory1,'*.jpg'));
names1 = {images1.name}';
directory2 = fullfile('./forest');
images2 = dir(fullfile(directory2,'*.jpg'));
names2 = {images2.name}';
directory3 = fullfile('./sunset');
images3 = dir(fullfile(directory3,'*.jpg'));
names3 = {images3.name}';
buildings=cell(numel(names1),1);
forest=cell(numel(names2),1);
sunset=cell(numel(names3),1);
buildingsHOG=cell(numel(names1)/2,1);
forestHOG=cell(numel(names2)/2,1);
sunsetHOG=cell(numel(names3)/2,1);
buildingsHOGTest=cell(numel(names1)/2,1);
forestHOGTest=cell(numel(names2)/2,1);
sunsetHOGTest=cell(numel(names3)/2,1);
for k=1: numel(names)
buildings{k} = imread(fullfile(directory1,names1{k}));
forest{k} = imread(fullfile(directory2,names2{k}));
sunset{k} = imread(fullfile(directory3,names3{k}));
if k<=15
buildingsHOG{k}=HOG(buildings{k});
forestHOG{k}=HOG(forest{k});
sunsetHOG{k}=HOG(sunset{k});
else
buildingsHOGTest{k-15}=HOG(buildings{k});
forestHOGTest{k-15}=HOG(forest{k});
sunsetHOGTest{k-15}=HOG(sunset{k});
end
end
buildingsResults=cell(numel(names1)/2,7);
forestResults=cell(numel(names2)/2,7);
sunsetResults=cell(numel(names3)/2,7);
for k=1: (numel(names)/2)
buildingsResults{k}=knnsearch(buildingsHOG,buildingsHOGTest,'k',5);
end
and this is the error:
Error using double
Conversion to double from cell is not possible.
Error in KDTreeSearcher (line 215)
X = double(X);
Error in createns (line 163)
O = KDTreeSearcher(X,'distance',distMetric,'bucketSize',bSize, args{:});
Error in knnsearch (line 140)
O=createns(X,args{:},'nsmethod', nsmethod,'bucketSize',bSize);
Error in application2exercise3 (line 45)
buildingsResults{k}=knnsearch(buildingsHOG,buildingsHOGTest,'k',5);
Best Regards.
Answers (1)
Sean de Wolski
on 18 Oct 2012
Edited: Sean de Wolski
on 18 Oct 2012
So either BuildingsHOG or buildingsHOGTest is a cell array (or they both are) and it should be a double.
Perhaps you want to extract one of their elements?
BuildingHog{1} %extract first cell
Categories
Find more on Display Image 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!