bag_of_words.m

来自「phow is the code for extracting pyramid 」· M 代码 · 共 34 行

M
34
字号
function wf = bag_of_words(fv,pos,C,Y,X,par)
V = size(C,2);
nPunts = size(fv,2);    
        
%%% Set distance matrix to all be large values
distance = Inf * ones(nPunts,size(C,2));
    
%%% Loop over all centers and all points and get L2 norm btw. the two.
for p = 1:nPunts
    for c = 1:size(C,2)
            distance(p,c) = norm(C(:,c) - double(fv(:,p)));
    end
end    
    
%%% Now find the closest center for each point
[tmp,words] = min(distance,[],2);
words = words';
wf = zeros(Y,X,par.nRegions);

for i=1:size(words,2)
    j=1;
    en=0;
    while j<=par.nRegions && ~en
        if wf(pos(2,i),pos(1,i),j) == 0
            wf(pos(2,i),pos(1,i),j) = words(1,i); 
            en = 1;
        else 
            j=j+1;
        end
    end
end
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?