Closed mycarta closed 8 years ago
I think the problem is that matplotlib
expects float arrays to be [0, 1] and integer arrays to be [0, 255], and converting to and from JCh gives you a float array on [0, 255]. Try doing np.round(rgb_J).astype(int)
and see if that helps? or just sticking with sRGB1 should also work :-)
(Note that you can reproduce the problem by just doing img = img.astype(float); plt.imshow(img)
without using colorspacious at all.)
Thanks for the tips.
Unfortunately using rgb_JJ = np.around(rgb_J).astype(int)
did not change the outcome. And similarly, when I tried img = img.astype(float); plt.imshow(img)
(which as you suggests, reproduces the problem), followed by img = np.round(img).astype(int); plt.imshow(img)
I also do not get back my original image.
I think I will stick with sRGB1. };-)
Maybe it's .astype(np.uint8)
that matplotlib is looking for? In any case, sounds like you've found a solution and there's nothing for colorspacious to do :-)
I get some odd result when converting a png image of some data with Jet colormap:
from sRGB255 to JCh and back:
The result looks instead normal when converting the input to 0-1 range and converting from sRGB1 to JCh and back:
I've loaded a complete example at this GitHub location: https://github.com/mycarta/PerceptualColormaps/blob/master/test_color_conversions_rgb-2-JCh-2-rgb_and_rgb-2-LCh-2-rgb.ipynb