quantombone / exemplarsvm

Ensemble of Exemplar-SVMs for Object Detection and Beyond
http://www.cs.cmu.edu/~tmalisie/projects/iccv11/index.html
MIT License
430 stars 155 forks source link

HOGPicture speedup #61

Open rosenfeldamir opened 12 years ago

rosenfeldamir commented 12 years ago

Hi, I've re-implemented HOGPicture to be much faster, using a single matrix multiplication. I think this should be in the main branch, and I don't know what would happen if I simply fork the project as is the default behavior; So check it out - it's really useful (just copy & paste instead of the original code...)


function im = HOGpicture(w, bs) %NOTE(TJM): I fixed a visualization bug which would sometimes show %funky artifacts because pedro's version shows only the orientations %facing one way. On synthetic images of squares this could be %seen. The simple fix is to scan over 18 orientations not 9 when %creating the histogram pics.

% Modified to vectorized version by Amir Rosenfeld, July 31st, 2012

if ~exist('bs','var') bs = 20; end % HOGpicture(w, bs) % Make picture of positive HOG weights.

% construct a "glyph" for each orientaion s = size(w); w(w<0) = 0; 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

bim = cat(3,bim,bim); bim_ = reshape(bim,[],18);

B = im2col( zeros(bs_s(1), bss(2)),[bs bs],'distinct'); w = reshape(w(:,:,1:18),[],18); im = col2im(bim_w',[bs bs],[bs_s(1), bs*s(2)],'distinct');

end

quantombone commented 12 years ago

Sweet, Let me check this out, and I will push this into the main branch once I make sure it doesn't break anything! Will let you know once the change is made or if I have any questions