scikits-image/scikits-image — pull request #244 by pcampr (2012-08-09 11:07:32+00:00)
Title: fix hog.py - orientation calculation and visualization

skimage.feature.hog has 2 bugs in

1) orientation calculation

current implementation

```py
orientation = arctan2(gy, (gx + 1e-15)) * (180 / pi) + 90
```

returns orientation in interval (-90, 270), because arctan2 returns angles in (-180, 180)... my proposed fix is:

```py
orientation = arctan2(gy, (gx + 1e-15)) * (180 / pi) % 180
```

2) visualization

```py
rr, cc = draw.bresenham(centre[0] - dx, centre[1] - dy,
centre[0] + dx, centre[1] + dy)
```

bresenham() expects parameters in "y,x" order, correct code is:

```py
rr, cc = draw.bresenham(centre[0] - dy, centre[1] - dx,
centre[0] + dy, centre[1] + dx)
```

I tested both on this usage case:

(hog, hog_img) = skimage.feature.hog(img, visualise=True, normalise=True, orientations=8, cells_per_block=(3, 3))

my testing image:
http://pavel.campr.cz/public/scikits-image-hog-fix/src.png

master code - result image with HoG visualization:
http://pavel.campr.cz/public/scikits-image-hog-fix/master_hog_visualise.png
http://pavel.campr.cz/public/scikits-image-hog-fix/master_hog_visualise_with_src.png

my proposed fix - result image with HoG visualization:
http://pavel.campr.cz/public/scikits-image-hog-fix/fix2_hog_visualise.png
http://pavel.campr.cz/public/scikits-image-hog-fix/fix2_hog_visualise_with_src.png

when compared, e.g. on the head, some orientations are currently lost, because orientations are in interval (-90, 270) , but processing is done on (0, 180) only... the rest of angles is lost and not counted into histograms