Error parsing some images
Here is the code replicating the issue:
import imquality.brisque as brisque
import urllib
import PIL.Image
import urllib.request
img = PIL.Image.open(urllib.request.urlopen("https://s3-media0.fl.yelpcdn.com/bphoto/0ecA6_IY0Lt4UTZss9lk8A/258s.jpg"))
brisque.score(img)
/data/home/proserpi/.local/lib/python3.7/site-packages/imquality/brisque.py:45: FutureWarning: The behavior of rgb2gray will change in scikit-image 0.19. Currently, rgb2gray allows 2D grayscale image to be passed as inputs and leaves them unmodified as outputs. Starting from version 0.19, 2D arrays will be treated as 1D images with 3 channels.
self.image = skimage.color.rgb2gray(self.image)
Traceback (most recent call last):
File "
#38
AssertionError Traceback (most recent call last)
/opt/conda/lib/python3.7/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)
/opt/conda/lib/python3.7/site-packages/imquality/brisque.py in calculate_features(image, kernel_size, sigma) 143 ) 144 downscaled_brisque = Brisque(downscaled_image, kernel_size=kernel_size, sigma=sigma) --> 145 features = numpy.concatenate([brisque.features, downscaled_brisque.features]) 146 scaled_features = scale_features(features) 147 return scaled_features
/opt/conda/lib/python3.7/site-packages/imquality/brisque.py in features(self) 90 def features(self): 91 return numpy.concatenate( ---> 92 [self.calculate_features(mscn_type) for mscn_type in MscnType] 93 ) 94
/opt/conda/lib/python3.7/site-packages/imquality/brisque.py in
/opt/conda/lib/python3.7/site-packages/imquality/brisque.py in calculate_features(self, mscn_type) 104 105 def calculate_features(self, mscn_type: MscnType): --> 106 agg = AsymmetricGeneralizedGaussian(self.get_coefficients(mscn_type)).fit() 107 if mscn_type == MscnType.mscn: 108 var = numpy.mean(
/opt/conda/lib/python3.7/site-packages/imquality/statistics.py in fit(self, x0) 123 124 def fit(self, x0: float = 0.2) -> "AsymmetricGeneralizedGaussian": --> 125 self._alpha = self.estimate_alpha(x0) 126 return self 127
/opt/conda/lib/python3.7/site-packages/imquality/statistics.py in estimate_alpha(self, x0) 115 try: 116 solution = find_root(lambda alpha: self.phi(alpha) - self.R_hat, x0) --> 117 assert solution.success 118 return solution.x.item() 119 except ValueError:
AssertionError:
I have got the same error for mnist gray scale images. Kindly suggest the fix
This isn't a solution, but it may prove slightly helpful. The OptimizeResult returned back from the scipy root function provides a message attribute to explain why the solution was not successful. I modified the assertion line to assert solution.success, solution.message and get the following message:
AssertionError: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.
I also noticed that this seems to only happen for extremely low-quality images, which means it may be safe for users to use an extremely high default score for cases where the optimization fails.