What RGB color is this? (quick Q)

Thomas A Caswell tcaswell at uchicago.edu
Tue Dec 31 19:59:38 EST 2013


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
On Dec 31, 2013 1:01 PM, "Adam Hughes" <hughesadam87 at gmail.com> wrote:

> 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...
>
>
> On Tue, Dec 31, 2013 at 6:15 AM, Stéfan van der Walt <stefan at sun.ac.za>wrote:
>
>> 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
>>
>> --
>> 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+unsubscribe at googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> 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 at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20131231/ef211e84/attachment.html>


More information about the scikit-image mailing list