Skip to content

hog: gradient calculations are different from OpenCV  #2809

Closed

Description

@rdabane

Description

I was trying to compare the HOG descriptor generation between scikit-image and OpenCV.

scikit-image/Features/_hog.py:

150: gy, gx = [np.ascontiguousarray(g, dtype=np.double)
for g in np.gradient(image)]

The function np.gradient calculates as :
image

In OpenCV:
https://github.com/opencv/opencv/blob/master/modules/objdetect/src/hog.cpp
Line 456:
dx0 = lut[p2[2]] - lut[p0[2]];

So the gradients are off by a factor of 2.

Activity

  1. stefanv commented on Sep 25, 2017

    @stefanv
    Member

    I'm not sure I understand: the numpy gradient computation seems correct?

  2. rdabane commented on Sep 25, 2017

    @rdabane
    Author

    Assuming that intention is to reproduce functionality from original HoG paper(http://lear.inrialpes.fr/people/triggs/pubs/Dalal-cvpr05.pdf) which suggests following : "Simple 1-D [−1, 0, 1] masks at σ=0 work best."

    Then in this case, the OpenCV implementation looks correct.
    I'm not saying that np.gradient is wrong. I'm saying that using it make the gradient deviate from OpenCV and the HoG paper.

  3. stefanv commented on Sep 25, 2017

    @stefanv
    Member

    I see, thanks for the clarification. OK, so should be fairly easy to fix. And we'll have to compare with OpenCV output to make sure things look right.

    /cc @ivoflipse @Korijn @TimSC

  4. rdabane commented on Sep 25, 2017

    @rdabane
    Author

    Ok. Thanks! Please let me know if I can be of any help.

  5. soupault commented on Sep 26, 2017

    @soupault
    Member

    @rdabane you might be interested in the comparison in #2040, especially, this comment #2040 (comment) .

  6. stefanv commented on Sep 26, 2017

    @stefanv
    Member

    @soupault I think you are, perhaps, in the best position to make a call on this issue.

  7. Korijn commented on Sep 26, 2017

    @Korijn
    Contributor

    Parameterize a choice between the two modes perhaps?

  8. soupault commented on Sep 29, 2017

    @soupault
    Member

    Yes, my bad. It was in line with the paper earlier - cdff825#diff-d8734512e866681c570f51f5d398f882L104. I'd revert the corresponding changes (this would also imply regenerating reference HOG matrices in skimage/data), and update the comparison (#2040 (comment)).
    Parameterization is also a solution, although I think that the API is quite populated already.

  9. added
    ⏩ type: Enhancement
    and removed on Sep 29, 2017
  10. added this to the 0.14 milestone on Sep 29, 2017
  11. stefanv commented on Sep 30, 2017

    @stefanv
    Member

    This feels more like a bug than a bad API---in which case, I think we should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ⏩ type: Enhancement

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions