What RGB color is this? (quick Q)

23 views
Skip to first unread message

Adam Hughes

unread,
Dec 31, 2013, 1:37:43 AM12/31/13
to scikit...@googlegroups.com
I noticed recently that matplotlib.colors limits RGB values to a range (0 - 1), while in scikit image, RGB values can be much larger.  For example:

test = np.zeros( (500,500,3) )

test[:,:,0]=50
test[:,:,1]=19
test[:,:,2]=25

imshow(test); 

Produces a teal background.  I was curious how the color teal is derived from this?  I tried normalizing to 255 and and 50 but neither seemed to produce the same teal color.

Thanks.

Adam Hughes

unread,
Dec 31, 2013, 1:54:17 AM12/31/13
to scikit...@googlegroups.com
It's late, so it didn't occur to me that the imshow source-code is probably a good way to figure this one out...

If anyone knows it offhand, that would save me some trouble.  Otherwise, I'll hunt it down tomorrow :)

Stéfan van der Walt

unread,
Dec 31, 2013, 6:15:04 AM12/31/13
to scikit...@googlegroups.com
Hi Adam

On Mon, 30 Dec 2013 22:37:43 -0800, Adam Hughes wrote:
> I noticed recently that matplotlib.colors limits RGB values to a range (0 -
> 1), while in scikit image, RGB values can be much larger. For example:
>
> *test = np.zeros( (500,500,3) )*
>
> *test[:,:,0]=50*
> *test[:,:,1]=19*
> *test[:,:,2]=25*
>
> *imshow(test); *
>
> Produces a teal background. I was curious how the color teal is derived
> from this? I tried normalizing to 255 and and 50 but neither seemed to
> produce the same teal color.

Here's a write-up of the data-type and range representation that scikit-image
uses:

http://scikit-image.org/docs/0.9.x/user_guide/data_types.html

When visualizing data with Matplotlib, note that data is normalized by
default, so you have to specify "vmin" and "vmax" to correctly display your
generated background.

Regards
St�fan

Adam Hughes

unread,
Dec 31, 2013, 2:01:46 PM12/31/13
to scikit...@googlegroups.com
Thanks Stefan.  That helps clarify some of the dtypes to me; however I still have a few confusions in regard to color data.  I should have specified this more in my OP.

I am trying to create a program where all color data is stored as RGB.  This requires a validator that does flexible to_rgb() conversion.  I want the users to have flexibility, so it should accept names like "aqua" as well as RGB tuples.  I realize now that imshow() will do its own conversions, but still don't quite understand exactly what constraints I need to impose on users for all the various use cases.  For example, if a user enters a single integer (say 239), is there a de-facto way to rgb-convert this?  I've tried to exhause the scenarious below; any case with question marks is still unclear to me. 

INPUT TYPE   INPUT EXAMPLE    HANDLER    DESIRED OUTPUT
-----------------------------------------------------------------------------------------------------

hex string         '#0FF000'      ColorConverter.to_rgb()    (.2, .4, .5)
name string      'purple   '      ColorConverter.to_rgb()     (.1, .8, .3)
< 1 float tuple   '    (.5, .2, .4)          PASS                   (.5, .2, .4)
> 1 float/int tuple   (30,  28, 90)       ????                         ????
int                           140          (Digital channel?)          (140, 140, 140)???
float                        39.5               (Error??)                   ???

I read on wiki that a RGB tuple with elements > 1 can be interpreted as a "Digital Channel", so perhaps just leave these as is.  The tough cases for me are really when a user enters a single Int or Float.  Of course, I could just raise an exception if there's no de-facto way to handle this...  


Stéfan

--
You received this message because you are subscribed to a topic in the Google Groups "scikit-image" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scikit-image/a54ehbd1fLk/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to scikit-image...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thomas A Caswell

unread,
Dec 31, 2013, 7:59:38 PM12/31/13
to scikit...@googlegroups.com

There is no canonical mapping between scalar values (1d) and RGB (3d) which is why matplotlib has so many color maps.

If you pass in to imshow a NxMx3 or NxMx4 array it is interpreted as RGB or RGBA values respectively (see http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.imshow) and not color mapped.  If the arrays are float they are assumed to be in the range [0-1], if they are integers they should be uint8. There was some discussion recently on github abut tweaking the validation a bit (issues 2499 and 2632).

Tom

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.

Adam Hughes

unread,
Dec 31, 2013, 8:15:54 PM12/31/13
to scikit...@googlegroups.com
Thanks Thomas.

Yes, I'm starting to see all the headaches that come with flexibility in dtypes and colors.  Thanks for linking, that clears some stuff up for me.
Reply all
Reply to author
Forward
0 new messages