HoG 特征可视化

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 features
for i=1:length(lab);
   lab{i}= strrep(lab{i},'\','');
   func{i}= sprintf('p(%d)',i);
   dgfunc{i}= sprintf('delparam(f,%d)',i);
end
Feats= 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);
    end
catch
    error(message('mbc:xregtransient:InvalidFile'))
end
if nargout==3
   Values= zeros(np,nfactors(f));
end
   

显示函数:

% showHOG(w)
%
% Legacy HOG visualization
function 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 weights
bs = 20;
pos = HOGpicture(w, bs);
neg = HOGpicture(-w, bs);

% Put pictures together and draw
buff = 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;
end

im(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 orientaion
bim1 = 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 glyphs
s = 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
  end
end

scale = max(max(w(:)),max(-w(:)));
im = im / scale;

效果图:



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值