error in skimage.feature.hog

247 views
Skip to first unread message

Damian Eads

unread,
Jul 10, 2012, 9:31:33 AM7/10/12
to scikit...@googlegroups.com
Hi,

I'm very impressed with the progress made on scikits since its
inception in 2009. I checked out the latest skimage from Git and tried
running the HoG code on a non-square image, but it returns an error.
Moreover, if I don't convert from RGB to gray, I get a shape mismatch
error. In the latter case, a more user-friendly error message would
be more informative. Alternatively, you can either convert it to
grayscale or compute a gradient image for each channel and for each
pixel use the largest.

Here is how to reproduce the error:

In [1]: import skimage.color

In [2]: import skimage.data
** Message: pygobject_register_sinkfunc is deprecated (GstObject)

In [3]: import skimage.feature

In [4]: I=skimage.data.imread("motorbikes041.png") # see attached

In [5]: I2=skimage.color.rgb2gray(I)

In [6]: print I2.shape, I2.dtype
(150, 200) float64

In [7]: skimage.feature.hog(I2)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

/data/repo/scikits-image/skimage/<ipython console> in <module>()

/usr/local/lib/python2.6/dist-packages/scikits_image-0.7dev-py2.6-linux-i686.egg/skimage/feature/hog.pyc
in hog(image, orientations, pixels_per_cell, cells_per_block,
visualise, normalise)
121
122 orientation_histogram[:, :, i] = uniform_filter(temp_mag,
--> 123 size=(cy, cx))[cy / 2::cy, cx / 2::cx]
124
125 # now for each cell, compute the histogram


ValueError: shape mismatch: objects cannot be broadcast to a single shape

--------------

However, if I select a square subarray, it works fine.

In [8]: x=skimage.feature.hog(I2[:128,:128])

Thanks,

Damian


--
Damian Eads, PhD
Research Associate, Machine Intelligence Laboratory
Engineering Department, University of Cambridge
Trumpington Street, Cambridge, CB2 1PZ, ENGLAND

Web: http://mi.eng.cam.ac.uk/~dre25
motorbikes041.png

Tony Yu

unread,
Jul 10, 2012, 9:47:21 AM7/10/12
to scikit...@googlegroups.com
Actually, I get a different error:

    ValueError: could not broadcast input array from shape (19,25) into shape (18,25)

In this case, it's not a problem with non-square images, but something to do with how images are sampled. Your 150 x 200 image gives the error above, but a 148 x 200 image works fine. I won't have time to look at this right now, but this behavior might be a clue for someone else who does have time.

As for the color/grayscale issue, I've been thinking that it would be good to have an `@grayscale` function decorator that checks whether an image is rgb/rgba and either raises an error or warns & converts. I haven't gotten around to implementing it yet, but it should be fairly simple.

Cheers,
-Tony 

Stéfan van der Walt

unread,
Jul 10, 2012, 5:38:06 PM7/10/12
to scikit...@googlegroups.com
On Tue, Jul 10, 2012 at 6:47 AM, Tony Yu <tsy...@gmail.com> wrote:
>> Here is how to reproduce the error:

Damian, I'm also tied up until Thursday, but I'll have a look at it ASAP.

> As for the color/grayscale issue, I've been thinking that it would be good
> to have an `@grayscale` function decorator that checks whether an image is
> rgb/rgba and either raises an error or warns & converts. I haven't gotten
> around to implementing it yet, but it should be fairly simple.

Great idea... The easier we can make it to build robust pipelines, the
better! The conversion routines have already come a long way, but I
am very much in favour of more such enhancements.

Stéfan

Brian Holt

unread,
Jul 10, 2012, 5:45:22 PM7/10/12
to scikit...@googlegroups.com

I've had a quick look and I can reproduce the bug. It seems to be a discrepancy between integer division to compute the number of cells and then subsampling the array which gives a different dimensions. Hopefully I'll have a better idea tomorrow.

On Jul 10, 2012 10:38 PM, "Stéfan van der Walt" <ste...@sun.ac.za> wrote:
>
> On Tue, Jul 10, 2012 at 6:47 AM, Tony Yu <tsy...@gmail.com> wrote:

> >> Here is how to reproduce the error:
>

> Damian, I'm also tied up until Thursday, but I'll have a look at it ASAP.
>

> > As for the color/grayscale issue, I've been thinking that it would be good
> > to have an `@grayscale` function decorator that checks whether an image is
> > rgb/rgba and either raises an error or warns & converts. I haven't gotten
> > around to implementing it yet, but it should be fairly simple.
>

Damian Eads

unread,
Jul 11, 2012, 10:20:44 AM7/11/12
to scikit...@googlegroups.com
Thank you for looking into the bug. On another note, it'd be great if
there was an option to turn off the flattening of the histogram.

Damian

Brian Holt

unread,
Jul 11, 2012, 10:37:12 AM7/11/12
to scikit...@googlegroups.com
Hi Damian,

Here is a link to the pull request I've created to fix the bug https://github.com/scikits-image/scikits-image/pull/213

You make a good point about the form of the resulting vector.  I would be quite happy to return a hierarchical (unraveled) ndarray and make it the responsibility of the user to ravel it if they so wish.  Comments from others?

Brian

Brian Holt

unread,
Jul 23, 2012, 6:24:27 AM7/23/12
to scikit...@googlegroups.com
Any other comments on this PR? I think its ready to merge.

Brian
Reply all
Reply to author
Forward
0 new messages