Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lhhGit committed Jun 11, 2013
1 parent 5a187ff commit 0fdca49
Show file tree
Hide file tree
Showing 2,168 changed files with 7,474 additions and 144 deletions.
Binary file added ..jpg
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
*.asv
*.mat
SR_testData/*
inputSet/*
eccentricity/*
ScreenShots/*
Dataset/*
original/*
*.txt
Binary file added LL.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions Search.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
function [ p5,p10,p20, recall ] = Search( input_index, displayResult, cate_count)
%SEARCH Summary of this function goes here
% Detailed explanation goes here
p5 = 0;p10=0;p20=0;
directory = 'SR_testData\\MPEGdata';
filelist = dir(fullfile(directory, '*.mat'));

filenames = cell(length(filelist),1);
for i=1:length(filenames)
filenames(i) = {filelist(i).name};
end

[sorted,~] = sort_nat(filenames);
matrixlist = cell(length(sorted),1);
for j = 1:length(sorted)
file = sorted(j);
css_struct = load([directory ,'\\' , file{1}],'saved');
matrixlist{j} = css_struct.saved;
end

%comment this line if input_index is set outside
%input_index = 10;

CSS_I = matrixlist{input_index};

len = length(matrixlist);
costList = zeros(len,1);
for k = 1:len
cost = matchingAlgo(CSS_I, matrixlist{k});
costList(k) = cost;
end

[Y,I] = sort(costList);

%take the top 20 as the query result
count = 20;
resultY = Y(1:count,:);
resultI = I(1:count,:);

for i=1:length(resultY)
value = resultY(i);
index = resultI(i);
file = sorted(index);
disp([file{1},' cost: ',num2str(value)]);
end

inputcssfile = sorted(input_index);
inputcssfilename = inputcssfile{1};
%display first top-20 elements
if(displayResult)
rows = 5;
cols = 5;

img_dir = 'original';
subplot(rows,cols,3);
inputimgname = strrep(inputcssfilename, '.txt.mat','');
imshow(255*imread([img_dir,'\\',inputimgname]));
title('input image');

for i=1:length(resultY)
index = resultI(i);
file = sorted(index);
cssname = file{1};
imgname = strrep(cssname, '.txt.mat','');
subplot(rows,cols,i + 5);
imshow(255*imread([img_dir,'\\',imgname]));
end
end

%calculate count in this class
sum = 0;
count = 0;
for i = 1:length(cate_count)
sum = sum + cate_count(i);
if(sum < input_index)
continue
else
count = cate_count(i);
break;
end
end

%calculate precision
p5 = 0;
p10 = 0;
p20 = 0;
hyphen_idx = find(inputcssfilename == '-');
input_catename = inputcssfilename(1:hyphen_idx-1);
match_count = 0;
for i = 1:20
index = resultI(i);
file = sorted(index);
name = file{1};
hyphen_idx = find(name == '-');
cate_name = name(1:hyphen_idx-1);
if( strcmp(input_catename, cate_name) )
match_count = match_count + 1;
end

if(i == 5)
p5 = 1.0*match_count/min(5, count);
end

if(i == 10)
p10 = 1.0*match_count/min(10, count);
end

if(i == 20)
p20 = 1.0*match_count/min(20, count);
end
end

%calculate recall
same_class_index = input_index:input_index + count - 1;
ranks = zeros(length(same_class_index),1);

for i = 1:length(ranks)
ranks(i) = find(I == same_class_index(i));
end
recall = max(ranks);

end

106 changes: 106 additions & 0 deletions SearchCustom.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
function [ p5,p10,p20, recall ] = SearchCustom( CSS_I, inputcssfilename, displayResult, input_index, count)
%SEARCH Summary of this function goes here
% Detailed explanation goes here
p5 = 0;p10=0;p20=0;
directory = 'SR_testData\\MPEGdata';
filelist = dir(fullfile(directory, '*.mat'));

filenames = cell(length(filelist),1);
for i=1:length(filenames)
filenames(i) = {filelist(i).name};
end

[sorted,~] = sort_nat(filenames);
matrixlist = cell(length(sorted),1);
for j = 1:length(sorted)
file = sorted(j);
css_struct = load([directory ,'\\' , file{1}],'saved');
matrixlist{j} = css_struct.saved;
end

%comment this line if input_index is set outside
%input_index = 10;


len = length(matrixlist);
costList = zeros(len,1);
for k = 1:len
cost = matchingAlgo(CSS_I, matrixlist{k});
costList(k) = cost;
end

[Y,I] = sort(costList);

%take the top 20 as the query result
count = 20;
resultY = Y(1:count,:);
resultI = I(1:count,:);

for i=1:length(resultY)
value = resultY(i);
index = resultI(i);
file = sorted(index);
disp([file{1},' cost: ',num2str(value)]);
end

%display first top-20 elements
if(displayResult)
rows = 5;
cols = 5;

img_dir = 'original';
subplot(rows,cols,3);
inputimgname = strrep(inputcssfilename, '.txt.mat','');
imshow(255*imread([img_dir,'\\',inputimgname]));
title('input image');

for i=1:length(resultY)
index = resultI(i);
file = sorted(index);
cssname = file{1};
imgname = strrep(cssname, '.txt.mat','');
subplot(rows,cols,i + 5);
imshow(255*imread([img_dir,'\\',imgname]));
end
end

%calculate precision
p5 = 0;
p10 = 0;
p20 = 0;
hyphen_idx = find(inputcssfilename == '-');
input_catename = inputcssfilename(1:hyphen_idx-1);
match_count = 0;
for i = 1:20
index = resultI(i);
file = sorted(index);
name = file{1};
hyphen_idx = find(name == '-');
cate_name = name(1:hyphen_idx-1);
if( strcmp(input_catename, cate_name) )
match_count = match_count + 1;
end

if(i == 5)
p5 = 1.0*match_count/min(5, count);
end

if(i == 10)
p10 = 1.0*match_count/min(10, count);
end

if(i == 20)
p20 = 1.0*match_count/min(20, count);
end
end

%calculate recall
same_class_index = input_index:input_index + count - 1;
ranks = zeros(length(same_class_index),1);

for i = 1:length(ranks)
ranks(i) = find(I == same_class_index(i));
end
recall = max(ranks);

end
126 changes: 126 additions & 0 deletions SearchSubset.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
function [ p5,p10,p20, recall ] = SearchSubset( input_index, displayResult, cate_count)
%SEARCH Summary of this function goes here
% Detailed explanation goes here
directory = 'SR_testData\\MPEGSubset';
filelist = dir(fullfile(directory, '*.mat'));

filenames = cell(length(filelist),1);
for i=1:length(filenames)
filenames(i) = {filelist(i).name};
end

[sorted,~] = sort_nat(filenames);
matrixlist = cell(length(sorted),1);
for j = 1:length(sorted)
file = sorted(j);
css_struct = load([directory ,'\\' , file{1}],'saved');
matrixlist{j} = css_struct.saved;
end

%comment this line if input_index is set outside
%input_index = 10;

CSS_I = matrixlist{input_index};

len = length(matrixlist);
costList = zeros(len,1);
for k = 1:len
cost = matchingAlgo(CSS_I, matrixlist{k});
costList(k) = cost;
end

[Y,I] = sort(costList);

%take the top 20 as the query result
count = 20;
resultY = Y(1:count,:);
resultI = I(1:count,:);

for i=1:length(resultY)
value = resultY(i);
index = resultI(i);
file = sorted(index);
disp([file{1},' cost: ',num2str(value)]);
end

inputcssfile = sorted(input_index);
inputcssfilename = inputcssfile{1};
%display first top-20 elements
if(displayResult)
rows = 5;
cols = 5;

img_dir = 'original';
subplot(rows,cols,3);
inputimgname = strrep(inputcssfilename, '.txt.mat','');
imshow(255*imread([img_dir,'\\',inputimgname]));
title('input image');

for i=1:length(resultY)
index = resultI(i);
file = sorted(index);
cssname = file{1};
imgname = strrep(cssname, '.txt.mat','');
subplot(rows,cols,i + 5);
imshow(255*imread([img_dir,'\\',imgname]));
end
end

%calculate count in this class
Msum = 0;
count = 0;
start_index = 1;
for i = 1:length(cate_count)
Msum = Msum + cate_count(i);
if(Msum < input_index)
continue
else
count = cate_count(i);
if(i > 1)
start_index= sum(cate_count(1:i-1)) + 1;
end
break;
end
end

%calculate precision
p5 = 0;
p10 = 0;
p20 = 0;
hyphen_idx = find(inputcssfilename == '-');
input_catename = inputcssfilename(1:hyphen_idx-1);
match_count = 0;
for i = 1:20
index = resultI(i);
file = sorted(index);
name = file{1};
hyphen_idx = find(name == '-');
cate_name = name(1:hyphen_idx-1);
if( strcmp(input_catename, cate_name) )
match_count = match_count + 1;
end

if(i == 5)
p5 = 1.0*match_count/min(5, count);
end

if(i == 10)
p10 = 1.0*match_count/min(10, count);
end

if(i == 20)
p20 = 1.0*match_count/min(20, count);
end
end

%calculate recall
same_class_index = start_index:start_index + count - 1;
ranks = zeros(length(same_class_index),1);

for i = 1:length(ranks)
ranks(i) = find(I == same_class_index(i));
end
recall = max(ranks);

end

Loading

0 comments on commit 0fdca49

Please sign in to comment.