Here is the code that I am trying to run:
import cv2
from matplotlib import pyplot as plt
import scipy.ndimage as ndimage
img = cv2.imread('lena.png', 0)
img = ndimage.gaussian_filter(img, sigma=(5, 5, 0), order=0)
plt.imshow(img, cmap='gray', interpolation='bicubic')
plt.show()
I am getting the following error:
RuntimeError: sequence argument must have length equal to input rank
The complete stack trace is:
Traceback (most recent call last):
File "/Users/guest/stackoverflow.py", line 6, in <module>
img = ndimage.gaussian_filter(img, sigma=(5, 5, 0), order=0)
File "/Users/guest/anaconda/envs/MyEnv/lib/python3.5/site-packages/scipy/ndimage/filters.py", line 346, in gaussian_filter
sigmas = _ni_support._normalize_sequence(sigma, input.ndim)
File "/Users/sguest/anaconda/envs/MyEnv/lib/python3.5/site-packages/scipy/ndimage/_ni_support.py", line 65, in _normalize_sequence
raise RuntimeError(err)
RuntimeError: sequence argument must have length equal to input rank
Here is the image I am trying to process: leng.png
According to the stack trace, the error "sequence argument must have length equal to input rank" is thrown by the line img = ndimage.gaussian_filter(img, sigma=(5, 5, 0), order=0)
sigma is a sequence argument, and you're expected to give one value per image dimension (this is the "input rank" mentioned in the error message).
Apparently, the statement img = cv2.imread('lena.png', 0) returns a 2D array (the 0 argument tells imread to convert the image to grey-value). Thus, gaussian_filter needs 2 values for sigma, not 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With