image-quality: ValueError: the input array must have size 3 along `channel_axis`, got (80, 512)
~\Envs\Iris\lib\site-packages\imquality\brisque.py in score(image, kernel_size, sigma) 158 159 def score(image: PIL.Image.Image, kernel_size=7, sigma=7 / 6) -> float: –> 160 scaled_features = calculate_features(image, kernel_size, sigma) 161 return predict(scaled_features)
~\Envs\Iris\lib\site-packages\imquality\brisque.py in calculate_features(image, kernel_size, sigma) 128 129 def calculate_features(image: PIL.Image, kernel_size, sigma) -> numpy.ndarray: –> 130 brisque = Brisque(image, kernel_size=kernel_size, sigma=sigma) 131 # WARNING: The algorithm is very sensitive to rescale 132 # FIXME: this is empirically the best configuration; however, scikit-image warns about bi-quadratic implementation.
~\Envs\Iris\lib\site-packages\imquality\brisque.py in init(self, image, kernel_size, sigma) 43 ): 44 self.image = pil2ndarray(image) —> 45 self.image = skimage.color.rgb2gray(self.image) 46 self.kernel_size = kernel_size 47 self.sigma = sigma
~\Envs\Iris\lib\site-packages\skimage_shared\utils.py in fixed_func(*args, **kwargs) 336 337 if channel_axis is None: –> 338 return func(*args, **kwargs) 339 340 # TODO: convert scalars to a tuple in anticipation of eventually
~\Envs\Iris\lib\site-packages\skimage\color\colorconv.py in rgb2gray(rgb, channel_axis) 873 >>> img_gray = rgb2gray(img) 874 “”" –> 875 rgb = _prepare_colorarray(rgb) 876 coeffs = np.array([0.2125, 0.7154, 0.0721], dtype=rgb.dtype) 877 return rgb @ coeffs
~\Envs\Iris\lib\site-packages\skimage\color\colorconv.py in _prepare_colorarray(arr, force_copy, channel_axis)
138 msg = (f’the input array must have size 3 along channel_axis, ’
139 f’got {arr.shape}')
–> 140 raise ValueError(msg)
141
142 float_dtype = _supported_float_type(arr.dtype)
ValueError: the input array must have size 3 along channel_axis, got (80, 512)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 15 (1 by maintainers)
I found a solution to this issue. The problem is that in the
calculate_featuresfunction inbrisque.py, twoBrisqueobjects get created.Within the constructor of the
Briqueclass, the functionskimage.color.rgb2gray()gets called.Back to the
calculate_featuresmethod, the firstBriqueobject that gets called, the input image is RGB; however, the secondBriqueobject that gets called is already in grayscale. Theskimage.color.rgb2gray()function throws an error that the input is already in grayscale as it expects 3 channels.The solution was to add a condition around the call to
skimage.color.rgb2gray()within theBrisqueclass.Replace line 45 of `imquality/brisque.py’ with:
@ocampor I believe a new pypi package is needed that includes the fix https://github.com/ocampor/image-quality/pull/43. Otherwise the fix won’t be generally available…
@BMaser did you install the dependency directly from github master or did you use pip? I believe the latter won’t work because a new package hasn’t been rebuilt since Feb 2021: https://pypi.org/project/image-quality/#files