ocampor / image-quality

Image quality is an open source software library for Image Quality Assessment (IQA).
Apache License 2.0
394 stars 85 forks source link

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

Open chinmaysahu opened 2 years ago

chinmaysahu commented 2 years ago

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

giuseppe-toscano commented 2 years ago

I encountered the same problem...

Jackok99 commented 2 years ago

I had same problem for a long time.

Jackok99 commented 2 years ago

ValueError: the input array must have size 3 along channel_axis, got (256, 384)

soheilnavvabi commented 2 years ago

anyone got any solution for this issue?

njay225 commented 2 years ago

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)
nospotfer commented 2 years ago

@ocampor please just merge this already when you have few minutes

xerohackcom commented 2 years ago

Merge it asap please! Serious issue.

BMaser commented 2 years ago

@njay225 ,

The error has not been resolved!

ValueError: the input array must have size 3 along channel_axis, got (336, 164)

HodeiG commented 2 years ago

@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

BMaser commented 2 years ago

@HodeiG : Thanks for the answer. I think as it is mentioned in the document, I simply installed it using Pypi. But I will try to install directly from github.

HodeiG commented 2 years ago

@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 commented 2 years ago

@HodeiG and @ocampor , I installed the the package from the github master, but still I got the same error "the input array must have size 3 along channel_axis"

sciencehope commented 1 year ago

I have got the same error and I don't know how to solve it. ValueError: the input array must have size 3 alongchannel_axis, got (112, 112)

kgonia commented 1 year ago

@BMaser @stic-lab

try with

--upgrade --force-reinstall

pip install --upgrade --force-reinstall -U git+https://github.com/ocampor/image-quality@master

Zircona commented 1 year ago

Has this been fixed please? I'm trying to run the below tutorial, and it's throwing the same errors (even when trying with the github install).

import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
from skimage import color, data, filters, morphology
from skimage.morphology import skeletonize

retina_source = data.retina()
retina = rgb2gray(retina_source) 

t0, t1 = filters. threshold_multiotsu(retina, classes =3)
mask = (retina > t0)

vessels = filters.sato(retina, sigmas = range(1, 10)) * mask
img_gray = rgb2gray(vessels)      

t = 0.015

binary_mask = img_gray > t
binary_mask = morphology.remove_small_objects(binary_mask, 2000)
plt.imshow(binary_mask, cmap = "gray")
plt.show()

skeleton = skeletonize(binary_mask)
pixel_count = int(np.sum(skeleton))

print("The Vascular architecture is", pixel_count, "pixels long")

This outputs:

Traceback (most recent call last): File "/home/user/Code/ex12_3.py", line 23, in img_gray = rgb2gray(vessels) File "/home/user/Code/venv/lib/python3.10/site-packages/skimage/_shared/utils.py", line 316, in fixed_func return func(*args, **kwargs) File "/home/user/Code/venv/lib/python3.10/site-packages/skimage/color/colorconv.py", line 945, in rgb2gray rgb = _prepare_colorarray(rgb) File "/home/user/Code/venv/lib/python3.10/site-packages/skimage/color/colorconv.py", line 146, in _prepare_colorarray raise ValueError(msg) ValueError: the input array must have size 3 along channel_axis, got (1411, 1411)