What am I doing wrong with HoG implementation?
1 view (last 30 days)
Show older comments
I'm trying to implement HoG and I'm not sure what I'm doing wrong when finding the cell's histogram.
function oim = HoG(im)
cellsize = 3;
if(~isa(im,'double'))
im = im2double(im);
end
kernel = [-1 0 1];
%Computing gradients
gx = imfilter(im,kernel);
gy = imfilter(im,kernel');
mag = (gx.^2 + gy.^2).^0.5;
%Finding orientations of the gradients and making it unsigned
ang = (180*atan2(gy,gx))/pi;
ang(ang<0) = ang(ang<0) + 180;
%Finding the orientation histogram of the first cell
tempA = reshape(ang(1:cellsize,1:cellsize),[cellsize*cellsize 1]);
tempM = reshape(mag(1:cellsize,1:cellsize),[cellsize*cellsize 1]);
histC = zeros(9,1);
lowerIndex = floor(tempA./20);
upperIndex = lowerIndex + 1;
upperCenter = (lowerIndex + 1.5)*20;
lowerCenter = upperCenter - 20;
upperIndex(upperIndex == 9) = 0;
%Finding constributions to upper and lower bins
contriU = (tempM.*(upperCenter-tempA)./20);
contriL = (tempM.*(tempA - lowerCenter)./20);
for i = 0:8
histC(i+1,1) = histC(i+1,1) + sum(contriL(lowerIndex == i));
histC(i+1,1) = histC(i+1,1) + sum(contriU(upperIndex == i));
end
oim = histC;
end
The code is written upto Orientation binning part and I'm getting negative values in the histogram.
Thank you.
0 Comments
Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!