showWeightVectorHOGPosOnly.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function out = showWeightVectorHOGPosOnly( w, settings )
  2. % function out = showWeightVectorHOGPosOnly( w, settings )
  3. %
  4. % author: Alexander Freytag
  5. % date : 14-02-2014 (dd-mm-yyyy)
  6. %
  7. % BRIEF :
  8. % Given a weight vector w obtained by training a model with DPM HOG features,
  9. % positive components are displayed
  10. %
  11. % INPUT :
  12. % w -- weight vector of model
  13. % settings
  14. % -- (optional), struct with possible fields, e.g.,
  15. % 'b_closeImg', ...
  16. %
  17. % OUTPUT :
  18. % out -- (optional), the resulting image of visualized model
  19. %% ( 0 ) check input
  20. if ( nargin < 2 )
  21. settings = [];
  22. end
  23. b_closeImg = getFieldWithDefault ( settings, 'b_closeImg', false);
  24. b_removeAxis = getFieldWithDefault ( settings, 'b_removeAxis', true);
  25. s_destination = getFieldWithDefault ( settings, 's_destination', '');
  26. if ( isempty (s_destination) )
  27. b_saveAsEPS = false;
  28. else
  29. b_saveAsEPS = true;
  30. end
  31. widthOfCell = getFieldWithDefault( settings, 'widthOfCell', 20 );
  32. heightOfCell = getFieldWithDefault( settings, 'heightOfCell', 20 );
  33. %% ( 1 ) Make pictures of positive weights
  34. wwp = foldHOG(w);
  35. scale = max(wwp(:));
  36. scale = double(255)/scale;
  37. % compute the visualization
  38. im = myHOGpicture(wwp, widthOfCell, heightOfCell );
  39. % scale to [0,255]
  40. im = im*scale;
  41. %
  42. % a bit of padding for nice visualization
  43. buff = 10;
  44. im = myPadArray( im, [buff buff], 200 );
  45. % convert to uint8 as usually done for images
  46. im = uint8(im);
  47. %% ( 4 ) draw figure or output result
  48. if ( nargout == 0 )
  49. % create new figure
  50. figHandle = figure;
  51. imagesc(im);
  52. colormap gray;
  53. % make images beeing displayed correctly, i.e., not skewed
  54. axis image;
  55. %don't show axis ticks
  56. set(gca,'Visible','off');
  57. if ( b_removeAxis )
  58. set(gca,'Visible','off')
  59. end
  60. if ( b_closeImg )
  61. pause
  62. close ( figHandle );
  63. end
  64. else
  65. out = im;
  66. end
  67. if ( b_saveAsEPS )
  68. print( '-depsc', '-r300' , s_destination );
  69. end
  70. end
  71. function f = foldHOG(w)
  72. % f = foldHOG(w)
  73. % Condense HOG features into one orientation histogram.
  74. % Used for displaying a feature.
  75. f=max(w(:,:,1:9),0)+max(w(:,:,10:18),0)+max(w(:,:,19:27),0);
  76. end