HoG 特征可视化

来源:互联网 发布:淘宝店铺在线布局 编辑:程序博客网 时间:2024/06/06 01:12
function [Feats,Defaults,Values]= features(f);% USERLOCAL/FEATURES%  Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc.%   $Revision: 1.2.2.4 $  $Date: 2011/10/01 20:58:22 $lab= labels(f);np = length(lab);lab= lab(:)';func=lab;dgfunc= lab;% parameters as response featuresfor i=1:length(lab);   lab{i}= strrep(lab{i},'\','');   func{i}= sprintf('p(%d)',i);   dgfunc{i}= sprintf('delparam(f,%d)',i);endFeats= struct('Display',lab,...   'Function',func,...   'delG',dgfunc,...   'Name',lab,...   'IsDatum',0,...   'index',num2cell(1:np),...'IsLinear',1);try    % possible userdefined    [rf,dGl]= rfvals(f.userdefined);    [rnames,Defaults]= rfnames(f.userdefined);    if ~isempty(rnames) && (~iscellstr(rnames) || length(rf)~=length(rnames))        error(message('mbc:xregtransient:InvalidFile'))    end    for i= 1:length(rf)        Feats(np+i)= struct('Display',rnames{i},...            'Function',sprintf('rfvals(f,%d)',i),...            'delG',sprintf('delrf(f,%d)',i),...            'Name',rnames{i},...            'IsDatum',0,...            'index',np+i,...            'IsLinear',0);    endcatch    error(message('mbc:xregtransient:InvalidFile'))endif nargout==3   Values= zeros(np,nfactors(f));end   

显示函数:

% showHOG(w)%% Legacy HOG visualizationfunction out = showHOG(w)w = w(:, :, 1:9) + w(:, :, 10:18) + w(:, :, 19:27);w = w / 3;w = repmat(w, [1 1 3]);w = padarray(w, [0 0 5], 'post');% Make pictures of positive and negative weightsbs = 20;pos = HOGpicture(w, bs);neg = HOGpicture(-w, bs);% Put pictures together and drawbuff = 10;if min(w(:)) < 0  pos = padarray(pos, [buff buff], 0.5, 'both');  neg = padarray(neg, [buff buff], 0.5, 'both');  im = [pos neg];else  im = pos;endim(im < 0) = 0;im(im > 1) = 1;if nargout == 0,  imagesc(im);   colormap gray;  axis image;else,  out = im;end% HOGpicture(w)%% Make picture of positive HOG weights.%   im = HOGpicture(w, bs)function im = HOGpicture(w, bs)if ~exist('bs', 'var'),  bs = 20;end% construct a "glyph" for each orientaionbim1 = zeros(bs, bs);bim1(:,round(bs/2):round(bs/2)+1) = 1;bim = zeros([size(bim1) 9]);bim(:,:,1) = bim1;for i = 2:9,  bim(:,:,i) = imrotate(bim1, -(i-1)*20, 'crop');end% make pictures of positive weights bs adding up weighted glyphss = size(w);    w(w < 0) = 0;    im = zeros(bs*s(1), bs*s(2));for i = 1:s(1),  iis = (i-1)*bs+1:i*bs;  for j = 1:s(2),    jjs = (j-1)*bs+1:j*bs;              for k = 1:9,      im(iis,jjs) = im(iis,jjs) + bim(:,:,k) * w(i,j,k+18);    end  endendscale = max(max(w(:)),max(-w(:)));im = im / scale;

效果图:



1 1
原创粉丝点击