Re: error in skimage.feature.hog

On Tue, Jul 10, 2012 at 9:31 AM, Damian Eads <dre25@cam.ac.uk> wrote:
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
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
participants (1)
-
Tony Yu