Hamming Embedding 내장 Binary Signature의 matlab 프로그램 코드 생성

% This code generates 128-bit hamming code "bs" for SIFT features %128-D % "bs": binary signature
%
% Bug fixed by Liang Zheng on 01/26/2015. 

%% load previous data
feat_file = '100000.siftgeo';  % folder of holidays features %holidays  
word_file = '100000_word.mat'; % holidays visual word %visual_word:3*1125 double
P = importdata('projection_matrix_128bits.mat');% load projection matrix %     %P:128*128 double %mat        ??
thres = importdata('thres_20k_128bits.mat');% load median matrix      %thres:128*20000 double

% a matrix for converting 01 strings into 0-255 uint8 data %  01 -> 0~255 %       uint8    
% uint8 data
nbits = 128; %nbits:number of bits for SIFT feature
m = 2.^(0:7); %m = [1 2 4 8 ... 128] % (0:7)     [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 ,           <16,(8*16)> <16, 128>
  %      ,      ,  size(m, 2)=8 ,           m,      0
  M = blkdiag (M, m); %Block diagonal concatenation of matrix input arguments 
end
bin2compactbin = M;

% for each image, calculate the HE signatures of its features      HE
% signature
[data, meta] = siftgeo_read(feat_file); % load features %feat_file = '100000.siftgeo';  data: n*128
data = data'; %   ,data:128*n 

% rootSIFT
sum_val = sum(data); %sum_val: 1*128 %1、  
for i = 1:128
    data(i, :) = data(i, :)./sum_val; %2、 ./   
end
data = single(sqrt(data));  %3、  ,   single  

visual_word = importdata(word_file); % load visual word %word_file = '100000_word.mat'; %visual_word:3*1125 %  descriptors visual words
nsift = size(visual_word, 2);  %nsift = 1125, 1125 sift keypoints,size(visual_word, 1) MA(kNN),size(visual_word, 2) sift descriptors   

%% feature projection and binarization %        
temp_data = P*data; % projected feature %data RootSIFT   %% P = importdata('projection_matrix_128bits.mat');
kNN = 3; % number of visual words assigned to each SIFT feature %visual word  index,    SIFT feature visual words
hamming_data = zeros(128, nsift*kNN);% note, multiple assignment is implied here. kNN = 3. %   MA = kNN = 3,   feature  3 visual words, hamming_data:128*(nsift*kNN)
if ~isempty(visual_word) %  
    for i = 1:kNN %1~3
        vw_index = visual_word(i, :); %visual_word:3*1125,     i,vw_index: 1*1125

        thresh = thres(:,vw_index); %thres = importdata('thres_20k_128bits.mat'); thres:128*20000,  thres  ,    thres:128*1125
        IDX = i:3:((nsift-1)*3+i);  %nsift 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; %hamming_data > 0     1,      0
    hamming_data(hamming_data <=0 ) = 0;
	% bs: binary signature
    bs = uint8 (bin2compactbin*hamming_data); % convert 01 strings into uint8 data  %bin2compactbin = M;
else %visual_word  
    bs = [];
end

% save file. bs is used as the binary signature of SIFT features
write_file = '100000_he.txt'; 
fid = fopen(write_file, 'w'); %  100000_he.txt  
fwrite(fid, bs, 'uint8'); % binary signature  100000_he.txt
fclose(fid);



    

좋은 웹페이지 즐겨찾기