ValueError: the input array must have size 3 along `channel_axis`, got (80, 512)

See original GitHub issue

~\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)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
njay225commented, Jan 12, 2022

I found a solution to this issue. The problem is that in the calculate_features function in brisque.py, two Brisque objects get created.

Within the constructor of the Brique class, the function skimage.color.rgb2gray() gets called.

Back to the calculate_features method, the first Brique object that gets called, the input image is RGB; however, the second Brique object that gets called is already in grayscale. The skimage.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 the Brisque class.

Replace line 45 of `imquality/brisque.py’ with:

# Only convert image to grayscale if RGB
if self.image.shape[-1] == 3:
    self.image = skimage.color.rgb2gray(self.image)
3reactions
HodeiGcommented, Jul 12, 2022

@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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Skimage rgb2gray giving errors, the input array must have ...
A quick fix would be keeping only the first 3 coordinates image_name = 'Blood.jpg' image = imageio.imread(image_name)[:,:,:3] img ...
Read more >
The input array must be have a shape == (.., ..,[ ..,] 3)), got (500 ...
I don't understand why this is happening… Another problem that I remembered now is that when I increase the batch size, this error...
Read more >
(Worker) ValueError: the input array must have size 3 along ...
I am trying to count the signals in a single channel image of a slice of spinal cord tissue. I am using the...
Read more >
How to Fix: All input arrays must have same number of ...
ValueError : all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0...
Read more >
Unconfirmed Errata - O'Reilly Media
Version Location Submitted by ePub Page pg 110 NaN: Missing numerical data Gregory Sherman Safari Books Online Chap 3. Example: Recipe Database Anonymous Printed Page Page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found