海明嵌入Hamming Embedding產生Binary Signature之matlab程式碼_海明嵌入

來源:互聯網
上載者:User
% 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 datafeat_file = '100000.siftgeo';  % folder of holidays features %holidays特徵word_file = '100000_word.mat'; % holidays visual word %visual_word:3*1125 doubleP = 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 datanbits = 128; %nbits:number of bits for SIFT featurem = 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 endbin2compactbin = 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*128data = data'; %轉置後,data:128*n % rootSIFTsum_val = sum(data); %sum_val: 1*128 %1、求和for i = 1:128    data(i, :) = data(i, :)./sum_val; %2、 ./ 點除enddata = single(sqrt(data));  %3、根方,並轉為single類型visual_word = importdata(word_file); % load visual word %word_file = '100000_word.mat'; %visual_word:3*1125 %對應descriptors的visual wordsnsift = 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 wordshamming_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 featureswrite_file = '100000_he.txt'; fid = fopen(write_file, 'w'); %建立100000_he.txt檔案fwrite(fid, bs, 'uint8'); %將binary signature寫入100000_he.txtfclose(fid);    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.