File size: 2,205 Bytes
d4035c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function feat = phow(conf, im)
% PHOW  Extract PHOW features
%
%   Author:: Andrea Vedaldi

conf_.color = false ;
conf_.sizes = [10 20] ;
conf_.step  = 5 ;
conf_.fast  = false ;
conf = override(conf_, conf) ;

im = im2double(im) ;

opts = {'windowsize', 1, 'verbose'} ;
if conf.fast, opts{end+1} = 'fast' ; end

if conf.color
  if size(im, 3) == 1, im = cat(3, im, im, im) ; end

  frames = [] ;
  descrs = [] ;
  for si = 1:length(conf.sizes)
    s = conf.sizes(si) ;
    ims = imsmooth(im, sqrt((s/6)^2 - 0)) ;
    hsv = rgb2hsv(ims) ;
    hsv = im2single(hsv) ;

    d_ = [] ;
    for k=1:3
      % This offset causes features of different scales to have the same
      % centers. While not strictly required, it makes the
      % representation much more compact.
      off = 3/2 * max(conf.sizes) + 1 - 3/2 * s ;

      [f, d] = vl_dsift(squeeze(hsv(:,:,k)), ...
                        'step', conf.step, ...
                        'size', s, ...
                        'bounds', [off off +inf +inf], ...
                        'norm', opts{:}) ;

      sel = find(f(3,:) < 0.002) ;
      d(:,sel) = 0 ;

      f = [f(1:2,:) ; 2*s * ones(1, size(f,2))] ;
      d_ = cat(1, d_, d) ;
    end
    frames = cat(2, frames, f) ;
    descrs = cat(2, descrs, d_) ;
  end

else
  if size(im, 3) == 3, im = rgb2gray(im) ; end
  im = im2single(im) ;

  frames = [] ;
  descrs = [] ;
  for si = 1:length(conf.sizes)
    s = conf.sizes(si) ;

    % This offset causes features of different scales to have the same
    % centers. While not strictly required, it makes the
    % representation much more compact.
    off = 3/2 * max(conf.sizes) + 1 - 3/2 * s ;

    ims = imsmooth(im, sqrt(max((s/6)^2 -.25,0))) ;

    [f, d] = vl_dsift(ims, ...
                      'step', conf.step, ...
                      'size', s, ...
                      'bounds', [off off +inf +inf], ...
                      'norm', opts{:}) ;

    sel = find(f(3,:) < 0.005) ;
    d(:,sel) = 0 ;

    %    figure ; hist(f(3,:),100) ;
    %drawnow ;

    f = [f(1:2,:) ; 2*s * ones(1, size(f,2))] ;

    frames = cat(2, frames, f) ;
    descrs = cat(2, descrs, d) ;
  end
end

feat = struct('frames', frames, 'descrs', descrs) ;