computeOptimalCellNumber.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function i_numCells = computeOptimalCellNumber ( blocks, i_binSize )
  2. % function i_numCells = computeOptimalCellNumber ( blocks, i_binSize )
  3. %
  4. % author: Alexander Freytag
  5. % date: 02-03-2014 ( dd-mm-yyyy )
  6. %
  7. % pick mode of aspect ratios
  8. h = [blocks(:).y2]' - [blocks(:).y1]' + 1;
  9. w = [blocks(:).x2]' - [blocks(:).x1]' + 1;
  10. xx = -2:.02:2;
  11. filter = exp(-[-100:100].^2/400);
  12. aspects = hist(log(double(h)./double(w)), xx);
  13. aspects = convn(aspects, filter, 'same');
  14. [peak, I] = max(aspects);
  15. aspect = exp(xx(I));
  16. % pick 20 percentile area
  17. mean(h);
  18. mean(w);
  19. areas = sort(h.*w);
  20. % nasty hack to constrain HoG feature support areas to be not too big or
  21. % too small, even if our input data would tell us otherwise
  22. area = areas(max(floor(length(areas) * 0.2),1));
  23. area = max(min(area, 7000), 5000);
  24. % how many pixels shall a cell cover in x and y direction?
  25. sbin = i_binSize;
  26. % pick dimensions according to data suggestions
  27. w = sqrt(double(area)/aspect);
  28. h = w*aspect;
  29. % resulting number of cells in x direction
  30. sizeX = round(h/sbin);
  31. % resulting number of cells in y direction
  32. sizeY = round(w/sbin);
  33. i_numCells = [sizeX sizeY];
  34. i_numCells = max(i_numCells,1);
  35. end