Wednesday, January 02, 2008

Read Rob Hess' SIFT data into MATLAB

%% read sift features from Rob Hess output
%% compatible with Rob's version version 1.1.1-20070913 (2006)
%% see imgfeatures.c in Rob's code for more details
%%
%% by smartnose@gmail.com, Jan. 2nd 2008
%%
%% INPUTS:
%% fn - full path string to the file to be read
%%
%% OUTPUTS:
%% rs - result structure
%% n: number of features
%% d: dimension of the feature vector (128 by default)
%% sv: scale and feature position vectors, each row indicate
%% y,x,scale, orientation of the feature.
%% fv: feature vectors, each row is a vector


function [rs]=import_rob_sift(fn)
if(~exist(fn,'file'))
error('file does not exist');
end

M=dlmread(fn);%M will be a N*20 matrix, with blank cells filled by 0

rs.n=M(1,1);
rs.d=M(1,2);

SV=zeros(rs.n,4);
FV=zeros(rs.n,rs.d);

ln=ceil(rs.d/20);

for ii=1:rs.n
SV(ii,:)=M((ii-1)*8+2,1:4);
%FV(ii,:)=
FT=[];
for jj=2:ln+1
FT=cat(2,FT,M((ii-1)*8+jj+1,:));
end
FV(ii,:)=FT(1,1:rs.d);
end

rs.sv=SV;
rs.fv=FV;
end

No comments: