Problems with coordinate ranges when doing conversion from LCH to LAB to RGB
A while ago I wrote a post on my blog with code on how to import in Python a colour palette in an ASCII file and convert it to a Matplotlib colormap: mycarta.wordpress.com/2014/04/25/convert-color-palettes-to-python-matplotlib-colormaps/ Following that post I wrote a tutorial on a geoscience magazine on how to evaluate and compare colormaps using Python: wiki.seg.org/wiki/How_to_evaluate_and_compare_color_maps In the accompanying notebook I show how to convert a 256x3 RGB colormap to a 256x256x3 RGB image, then convert it to CIELAB using scikit-image's rgb2lab, then plot the 256x1 lightness (L) array to evaluate the colormaps perceptually. You can read the relevant extract of the notebook using this nbviewer link: http://nbviewer.ipython.org/urls/dl.dropbox.com/s/54zoax2qesb71wn/evaluate_c... In that case scikit-image worked really well for me. Now I am trying to follow up with a new tutorial and I run into problems with the color space conversions. You can follow what I am trying to do in this other notebook extract: http://nbviewer.ipython.org/urls/dl.dropbox.com/s/noli66nzrlk0676/make_color... The goal of this new tutorial is to show how to build colormaps from scratch using perceptual principles. I design a color palette in LCH (polar version of CIELAB) by keeping Chroma and Lightness fixed and interpolating Hue around the circle, then convert to LAB, then to RGB. As far as I know the code I wrote should work, but the result is a black colormap. I am thinking I got wrong one or more of the ranges for the LCH coordinates. I assumed L between (0,1), Ch between (0,1), and H between (0, 2*pi). Is that wrong, and if that's the case, what are the ranges? Many of them are not stated clearly in the documentation in here: http://scikit-image.org/docs/dev/api/skimage.color.html Is it possible to update the documentation to clearly state all ranges for all colour spaces. Thanks for your help. Matteo
Hey Matteo, I’m not familiar with all the different colour spaces, but from your second notebook you know that L in Lab ranges from 0-100, so I imagine it’s the same in Lch. Similarly for ab -> c. You might want to try 0-100 as your ranges. Various resources on the internet also point to that range, e.g., http://www.colourphil.co.uk/lab_lch_colour_space.shtml . In addition, I think your call to swapaxes to get lch256 in the final notebook might be incorrect. You need to put axis 0, the channels, at the end for our colour conversions to work, so it should be swapaxes(arr, 0, 2). Having said that, you are right that our documentation could be improved, at the very least linking to relevant web documents for each function. I’ll add an issue for this. I hope this helps, and thanks for reporting the issue! Juan. — Sent from Mailbox On Wed, Oct 1, 2014 at 2:29 PM, Matteo <matteo.niccoli@gmail.com> wrote:
A while ago I wrote a post on my blog with code on how to import in Python a colour palette in an ASCII file and convert it to a Matplotlib colormap: mycarta.wordpress.com/2014/04/25/convert-color-palettes-to-python-matplotlib-colormaps/ Following that post I wrote a tutorial on a geoscience magazine on how to evaluate and compare colormaps using Python: wiki.seg.org/wiki/How_to_evaluate_and_compare_color_maps In the accompanying notebook I show how to convert a 256x3 RGB colormap to a 256x256x3 RGB image, then convert it to CIELAB using scikit-image's rgb2lab, then plot the 256x1 lightness (L) array to evaluate the colormaps perceptually. You can read the relevant extract of the notebook using this nbviewer link: http://nbviewer.ipython.org/urls/dl.dropbox.com/s/54zoax2qesb71wn/evaluate_c... In that case scikit-image worked really well for me. Now I am trying to follow up with a new tutorial and I run into problems with the color space conversions. You can follow what I am trying to do in this other notebook extract: http://nbviewer.ipython.org/urls/dl.dropbox.com/s/noli66nzrlk0676/make_color... The goal of this new tutorial is to show how to build colormaps from scratch using perceptual principles. I design a color palette in LCH (polar version of CIELAB) by keeping Chroma and Lightness fixed and interpolating Hue around the circle, then convert to LAB, then to RGB. As far as I know the code I wrote should work, but the result is a black colormap. I am thinking I got wrong one or more of the ranges for the LCH coordinates. I assumed L between (0,1), Ch between (0,1), and H between (0, 2*pi). Is that wrong, and if that's the case, what are the ranges? Many of them are not stated clearly in the documentation in here: http://scikit-image.org/docs/dev/api/skimage.color.html Is it possible to update the documentation to clearly state all ranges for all colour spaces. Thanks for your help. Matteo -- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Hi Juan Thanks so much for your reply. About a and b, to be honest they should be in the range -100, 100 as that's I think how they were defined by CIE. But I will check. I think you are rigth about L, though, that's clearly a slip on my part, odd since in the first notebook it is obvious that the output of L is in the range of 0-100. :) A good test would be to convert a single colour, say red, from RGB to LAB, to LCH, then back to LAB and RGB and check the values at each step. I'll try tomorrow and post my results back for your information. About the swapaxes, are you sure? In the first notebook I use *np.swapaxes(rgb_sp,1,2) *which seems to work. *In [4]:* *rgb_sp=np.array(zip(rsp, gsp ,bsp)) rgb_sp.shape # check the shape of the output array * * Out[4]:* *(256, 3, 256) * *In [5]:* *rgb_spectral=np.swapaxes(rgb_sp,1,2) rgb_spectral.shape # check the shape of the array again * * Out[5]:* *(256, 256, 3)* BUt again, I will check at home and confirm back. Having ranges clearly in the documentation would be great, thanks for that. Other than that, I think scikit-image is awesome, I'm using a number of the image morphology functions and they're great to work with. Cheers, Matteo On Tuesday, September 30, 2014 11:15:57 PM UTC-6, Juan Nunez-Iglesias wrote:
Hey Matteo,
I’m not familiar with all the different colour spaces, but from your second notebook you know that L in Lab ranges from 0-100, so I imagine it’s the same in Lch. Similarly for ab -> c. You might want to try 0-100 as your ranges. Various resources on the internet also point to that range, e.g., http://www.colourphil.co.uk/lab_lch_colour_space.shtml .
In addition, I think your call to swapaxes to get lch256 in the final notebook might be incorrect. You need to put axis 0, the channels, at the end for our colour conversions to work, so it should be swapaxes(arr, 0, 2).
Having said that, you are right that our documentation could be improved, at the very least linking to relevant web documents for each function. I’ll add an issue for this.
I hope this helps, and thanks for reporting the issue!
Juan.
— Sent from Mailbox <https://www.dropbox.com/mailbox>
On Wed, Oct 1, 2014 at 2:29 PM, Matteo <matteo....@gmail.com <javascript:>
wrote:
A while ago I wrote a post on my blog with code on how to import in Python a colour palette in an ASCII file and convert it to a Matplotlib colormap:
mycarta.wordpress.com/2014/04/25/convert-color-palettes-to-python-matplotlib-colormaps/
Following that post I wrote a tutorial on a geoscience magazine on how to evaluate and compare colormaps using Python: wiki.seg.org/wiki/How_to_evaluate_and_compare_color_maps
In the accompanying notebook I show how to convert a 256x3 RGB colormap to a 256x256x3 RGB image, then convert it to CIELAB using scikit-image's rgb2lab, then plot the 256x1 lightness (L) array to evaluate the colormaps perceptually. You can read the relevant extract of the notebook using this nbviewer link:
http://nbviewer.ipython.org/urls/dl.dropbox.com/s/54zoax2qesb71wn/evaluate_c... In that case scikit-image worked really well for me.
Now I am trying to follow up with a new tutorial and I run into problems with the color space conversions. You can follow what I am trying to do in this other notebook extract:
http://nbviewer.ipython.org/urls/dl.dropbox.com/s/noli66nzrlk0676/make_color...
The goal of this new tutorial is to show how to build colormaps from scratch using perceptual principles. I design a color palette in LCH (polar version of CIELAB) by keeping Chroma and Lightness fixed and interpolating Hue around the circle, then convert to LAB, then to RGB. As far as I know the code I wrote should work, but the result is a black colormap. I am thinking I got wrong one or more of the ranges for the LCH coordinates. I assumed L between (0,1), Ch between (0,1), and H between (0, 2*pi). Is that wrong, and if that's the case, what are the ranges? Many of them are not stated clearly in the documentation in here: http://scikit-image.org/docs/dev/api/skimage.color.html
Is it possible to update the documentation to clearly state all ranges for all colour spaces.
Thanks for your help. Matteo
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com <javascript:>. For more options, visit https://groups.google.com/d/optout.
Hi Matteo On 2014-10-01 20:56:09, Matteo <matteo.niccoli@gmail.com> wrote:
A good test would be to convert a single colour, say red, from RGB to LAB, to LCH, then back to LAB and RGB and check the values at each step. I'll try tomorrow and post my results back for your information.
Did you have any luck with that? Also, if you come up with any good test cases that point out deficiencies in the code, we'd be happy to include them in the test suite. Thanks for the link to the article--it's very enjoyable to learn more about color map perception in such a vividly illustrated way. Regards Stéfan
Hi Stefan (and Juan) I run this test last night. Nothing fancy, essentially I created a 16x16x3 RGB azure image (RGB 0,153,255 or 0,0.6,1) and took it for a walk from RGB to LAB to LCH then back to LAB and RGB again. http://nbviewer.ipython.org/urls/dl.dropbox.com/s/44b9udiqz4npp0b/color_spac... Feel free to use this if you like as an example of color conversion. I will be adding it to my GitHub anyway https://github.com/mycarta As you can see the loop of transformations closes precisely. When I tried with pure red (RGB 1,0,0 or 255,0,0) the final RGB values are all e-16 numbers, some negative. Not sure if that qualifies as deficiencies. Certainly it points to me to the need to include documenntation on the coordinate ranges as Juan observed.
From this I conclude that: r,g, and b are in the range (0 1) L is in the range (0 100) as Juan pointed out (already evident from my
color evaluation notebook), however a and b must be in the range (-100 100) since a is small but positive and b is large but negative (as expected) in my example chrima c must be in the range (0 100) because it is the distance from the polar axis so it can't be negative h is in the range (0 2pi) as specified already in the documentation
I hope this is useful. I'l lbe checking my original example with the new ranges tonigth. Cheers Matteo On Thursday, October 2, 2014 4:02:54 PM UTC-6, Stefan van der Walt wrote:
Hi Matteo
On 2014-10-01 20:56:09, Matteo <matteo....@gmail.com <javascript:>> wrote:
A good test would be to convert a single colour, say red, from RGB to LAB, to LCH, then back to LAB and RGB and check the values at each step. I'll try tomorrow and post my results back for your information.
Did you have any luck with that? Also, if you come up with any good test cases that point out deficiencies in the code, we'd be happy to include them in the test suite.
Thanks for the link to the article--it's very enjoyable to learn more about color map perception in such a vividly illustrated way.
Regards Stéfan
I moved the notebook with the color conversion tests from RGB to LAB to LCH then back to LAB and to RGB to a stable location <https://github.com/mycarta/PerceptualColormaps/blob/master/color_space_conversion-test_scikit-image.ipynb> on GitHub. On Friday, October 3, 2014 at 8:13:54 AM UTC-6, Matteo wrote:
Hi Stefan (and Juan)
I run this test last night. Nothing fancy, essentially I created a 16x16x3 RGB azure image (RGB 0,153,255 or 0,0.6,1) and took it for a walk from RGB to LAB to LCH then back to LAB and RGB again.
http://nbviewer.ipython.org/urls/dl.dropbox.com/s/44b9udiqz4npp0b/color_spac... Feel free to use this if you like as an example of color conversion. I will be adding it to my GitHub anyway https://github.com/mycarta
As you can see the loop of transformations closes precisely. When I tried with pure red (RGB 1,0,0 or 255,0,0) the final RGB values are all e-16 numbers, some negative. Not sure if that qualifies as deficiencies. Certainly it points to me to the need to include documenntation on the coordinate ranges as Juan observed.
From this I conclude that: r,g, and b are in the range (0 1) L is in the range (0 100) as Juan pointed out (already evident from my color evaluation notebook), however a and b must be in the range (-100 100) since a is small but positive and b is large but negative (as expected) in my example chrima c must be in the range (0 100) because it is the distance from the polar axis so it can't be negative h is in the range (0 2pi) as specified already in the documentation
I hope this is useful. I'l lbe checking my original example with the new ranges tonigth. Cheers Matteo
On Thursday, October 2, 2014 4:02:54 PM UTC-6, Stefan van der Walt wrote:
Hi Matteo
On 2014-10-01 20:56:09, Matteo <matteo....@gmail.com> wrote:
A good test would be to convert a single colour, say red, from RGB to LAB, to LCH, then back to LAB and RGB and check the values at each step. I'll try tomorrow and post my results back for your information.
Did you have any luck with that? Also, if you come up with any good test cases that point out deficiencies in the code, we'd be happy to include them in the test suite.
Thanks for the link to the article--it's very enjoyable to learn more about color map perception in such a vividly illustrated way.
Regards Stéfan
participants (3)
-
Juan Nunez-Iglesias
-
Matteo
-
Stefan van der Walt