showWeightVectorHOG.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. function out = showWeightVectorHOG( w, settings )
  2. % function out = showWeightVectorHOG( w, settings )
  3. %
  4. % author: Alexander Freytag
  5. % date : 27-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 and negative components are displayed separately
  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 and negative weights
  34. % compute the visualization
  35. imPos = myHOGpicture( w, widthOfCell, heightOfCell );
  36. imNeg = myHOGpicture( -w, widthOfCell, heightOfCell );
  37. scale = max( [w(:); -w(:)] );
  38. imPos = imPos ./ scale;
  39. imNeg = imNeg ./ scale;
  40. %% ( 2 ) Put pictures together
  41. %
  42. % a bit of padding for nice visualization
  43. buff = 10;
  44. imPos = myPadArray( imPos, [buff buff], 0.5);
  45. imNeg = myPadArray( imNeg, [buff buff], 0.5 );
  46. im = [imPos imNeg];
  47. %% ( 3 ) saturate image information out of [0,1]
  48. im(im < 0) = 0;
  49. im(im > 1) = 1;
  50. % scale to [0,255]
  51. im = im*255;
  52. % convert to uint8 as usually done for images
  53. im = uint8(im);
  54. %% ( 4 ) draw figure or output result
  55. if ( nargout == 0 )
  56. % create new figure
  57. figHandle = figure;
  58. imagesc(im);
  59. colormap gray;
  60. % make images beeing displayed correctly, i.e., not skewed
  61. axis image;
  62. %don't show axis ticks
  63. set(gca,'Visible','off');
  64. if ( b_removeAxis )
  65. set(gca,'Visible','off')
  66. end
  67. if ( b_closeImg )
  68. pause
  69. close ( figHandle );
  70. end
  71. else
  72. out = im;
  73. end
  74. if ( b_saveAsEPS )
  75. print( '-depsc', '-r300' , s_destination );
  76. end
  77. end