% This code generates 128-bit hamming code ' BS ' for SIFT features%128-d% ' BS ': binary signature%% Bug fixed by Liang Z
Heng on 01/26/2015. %% Load Previous data Feat_file = ' 100000.siftgeo '; % folder of holidays features%holidays feature word_file = ' 100000_word.mat '; % Holidays Visual Word%visual_word:3*1125 double P = importdata (' Projection_matrix_128bits.mat ');% load Projection Matri
X Map Matrix%p:128*128 Double%mat How the file is calculated. Thres = ImportData (' Thres_20k_128bits.mat ');% load median matrix median matrices%thres:128*20000 double A matrix for converting 0 1 strings into 0-255 uint8 data% Convert 01 string-> 0~255% binary to uint8 decimal% uint8 data nbits = 128; %nbits:number of Bits for SIFT feature m = 2.^ (0:7); %m = [1 2 4 8 ... 128]% (0:7) is a vector [0, 1, 2, 3, 4, 5, 6, 7] m = m; % [1 2 4 8 ... 128] For i = 2:nbits/8%2~128/8% 2~16% 15 times, the final matrix size is <16, (8*16) > that is <16, 128>% Diagonal series, add one line at a time, increase size (M, 2) = 8 columns, one M in diagonal direction, and 0 m = Blkdiag (M, m) in other parts; %block diagonal concatenation of matrix input argUments End bin2compactbin = M; % for each image, calculate the "he" signatures of its features compute feature of he% signature [data, meta] = Siftgeo_read (feat_file); % load Features%feat_file = ' 100000.siftgeo '; data:n*128 data = Data '; After the% transpose, data:128*n% rootsift sum_val = SUM (data); %sum_val:1*128% 1, sum for i = 1:128 data (i,:) = data (i,:)./sum_val;% 2,./point except end data = single (sqrt (data)); %3, root side, and convert to single type Visual_word = ImportData (word_file); % load visual word%word_file = ' 100000_word.mat '; %visual_word:3*1125% corresponds to descriptors visual words nsift = Size (Visual_word, 2); %nsift = 1125, 1125 sift Keypoints,size (Visual_word, 1) is MA (kNN), size (Visual_word, 2) is sift descriptors number of%% feature Proj Ection and binarization% feature maps and two-valued temp_data = P*data;
% projected feature%data is a rootsift feature of% P = ImportData (' Projection_matrix_128bits.mat '); KNN = 3; % of the visual words assigned to each SIFT feature%visual Word is index, assigned to the visual SIFT feature = Ze for each words hamming_data Ros (128, NSIFT*KNN);% NoTE, multiple assignment is implied here. KNN = 3. % Note MA = KNN = 3, i.e. each feature corresponds to 3 visual words, hamming_data:128* (NSIFT*KNN) if ~isempty (visual_word)% non-empty for i = 1:knn% 1~3 Vw_index = Visual_word (i,:);%visual_word:3*1125, take each row i,vw_index:1*1125 Thresh = Thres (:, Vw_index); %thres = ImportData (' Thres_20k_128bits.mat '); thres:128*20000, intercept the thres matrix, the newly obtained thres:128*1125 IDX = I:3: ((nsift-1) *3+i); %nsift is the number of rootsfit, 1125, I:3: (1124*3+i) Hamming_data (:, IDX) = Temp_data-thresh; % projected data minus median matrix end hamming_data (Hamming_data > 0) = 1;
The parts of%hamming_data > 0 are set to 1, the remainder is 0 hamming_data (hamming_data <=0) = 0; % bs:binary Signature bs = Uint8 (Bin2compactbin*hamming_data);
% convert strings into uint8 data%bin2compactbin = M;
Else%visual_word is an empty bs = []; End% Save file.
BS is used as the binary signature of SIFT features write_file = ' 100000_he.txt '; FID = fopen (write_file, ' w '); % Create 100000_he.txt file fwrite (fiD, BS, ' uint8 ');
% binary signature is written to 100000_he.txt fclose (FID);