8

I am running the scikit-image Histogram of Gradients example

The example code is as follows:

import matplotlib.pyplot as plt

from skimage.feature import hog
from skimage import data, color, exposure


image = color.rgb2gray(data.astronaut())

fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),
                    cells_per_block=(1, 1), visualize=True)

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)

ax1.axis('off')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Input image')
ax1.set_adjustable('box-forced')

# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02))

ax2.axis('off')
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients')
ax1.set_adjustable('box-forced')
plt.show()

Put simply, it does not work and reports the following error:

    fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True)
TypeError: hog() got an unexpected keyword argument 'visualize'

I can view the astronaut image by commenting out the above section, so that is not the problem. Does anyone know why it is failing?

SeanJ
  • 1,203
  • 2
  • 19
  • 39

1 Answers1

12

It is a very small error but the spelling for your keyword argument visualize is wrong. It should be

fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),
                cells_per_block=(1, 1), visualise=True)

Refer here for more information.

Lakshya Kejriwal
  • 1,340
  • 4
  • 17
  • 27
  • 2
    Thanks! The sckit-image website is wrong. For posterity : https://web.archive.org/web/20171001204310/http://scikit-image.org/docs/dev/auto_examples/features_detection/plot_hog.html – SeanJ Oct 01 '17 at 20:43
  • 5
    The docs aren't wrong---they're just for a different version of skimage than you are using, where the issue has been fixed. The argument was originally named `visualise`, is now `visualize`, but both are accepted for the next two versions until we can deprecate `visualise` through our standard deprecation cycle. – Stefan van der Walt Oct 02 '17 at 00:27
  • @StefanvanderWalt: Now only `visualize` is accepted, the other form returns `hog() got an unexpected keyword argument 'visualise'` – mins Jan 16 '21 at 18:44
  • 1
    That's correct, @mins ­— as mentioned in the above comment, we went through a deprecation cycle. See the 0.16 release notes: https://scikit-image.org/docs/0.16.x/release_notes_and_installation.html#api-changes – Stefan van der Walt Jan 19 '21 at 04:00