njsmith / colorspacious

A powerful, accurate, and easy-to-use Python library for doing colorspace conversions
MIT License
169 stars 16 forks source link

cspace_convert raises IndexError on xyY = [0, 0, 0.5] #19

Open maxnoe opened 5 years ago

maxnoe commented 5 years ago

I wanted to plot the xy gamut so I created a meshgrid from 0 to 1, but colorspacious raises an IndexError for [0, 0, 0.5]:

In [5]: colorspacious.cspace_convert([0.0, 0.0, 0.5], 'xyY1', 'JCh')

IndexError                                Traceback (most recent call last)
<ipython-input-16-75b580b587d2> in <module>
----> 1 colorspacious.cspace_convert([0.0, 0.0, 0.5], 'xyY1', 'JCh')

~/.local/anaconda3/lib/python3.7/site-packages/colorspacious/conversion.py in cspace_convert(arr, start, end)
    230     """
    231     converter = cspace_converter(start, end)
--> 232     return converter(arr)
    233
    234 def check_cspace_convert(source_cspace, target_cspace, gold, **kwargs):

~/.local/anaconda3/lib/python3.7/site-packages/colorspacious/transform_graph.py in __call__(self, x)
    579     def __call__(self, x):
    580         for transform, kwargs in zip(self._transforms, self._kwargses):
--> 581             x = transform(x, **kwargs)
    582         return x
    583

~/.local/anaconda3/lib/python3.7/site-packages/colorspacious/conversion.py in _XYZ100_to_CIECAM02(XYZ100, ciecam02_space)
     84
     85 def _XYZ100_to_CIECAM02(XYZ100, ciecam02_space):
---> 86     return ciecam02_space.XYZ100_to_CIECAM02(XYZ100)
     87
     88 def _CIECAM02_to_XYZ100(CIECAM02, ciecam02_space):

~/.local/anaconda3/lib/python3.7/site-packages/colorspacious/ciecam02.py in XYZ100_to_CIECAM02(self, XYZ100, on_negative_A)
    213         tmp = (hprime - h_i[i]) / e_i[i]
    214         H = H_i[i] + ((100 * tmp)
--> 215                       / (tmp + (h_i[i + 1] - hprime) / e_i[i + 1]))
    216
    217         #### Step 7

IndexError: index 5 is out of bounds for axis 0 with size 5

For rather small values, it raises a different, more telling error:

In [6]: colorspacious.cspace_convert([0.0, 0.00001, 0.5], 'xyY1', 'JCh')
NegativeAError: attempted to convert a tristimulus value whose achromatic signal was negative, and on_negative_A="raise"
maxnoe commented 5 years ago

I can see that XYZ100_to_CIECAM02 has a kwarg on_negative_A, but cspace_convert seems not to expose this.

njsmith commented 5 years ago

Unfortunately I don't really have bandwidth to devote to this project currently. But if you're able to figure out what's going on and submit a plausible PR for what you need, I'll take a look.

On Wed, Aug 14, 2019, 08:26 Maximilian Nöthe notifications@github.com wrote:

I can see that XYZ100_to_CIECAM02 has a kwarg on_negative_A, but cspace_convert seems not to expose this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/njsmith/colorspacious/issues/19?email_source=notifications&email_token=AAEU42ECVDDNUPBBK43AFUTQEQPZZA5CNFSM4ILWDWX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4JFG4Q#issuecomment-521294706, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEU42CDQT3LUMOOS356OFLQEQPZZANCNFSM4ILWDWXQ .

maxnoe commented 5 years ago

The problem is that RGB in l 183 is [nan nan nan]. Is that expected, so [nan nan nan] should also be returned here, or not?