Remaping 3 dimensional vector to 255 rgb

142 views
Skip to first unread message

Daz

unread,
Jan 24, 2014, 9:41:03 AM1/24/14
to python_in...@googlegroups.com
Heya

I'm trying to remap 3 dimensional vector to values of 0-255 

Can some1 suggest what algorithm I need to use to convert those vector values to more human rgb values?

I know that

0% = (0.0, 0.0, 0.0) - black
25% = (0.044156629592180252, 0.044154495000839233, 0.044151946902275085)
50% = (0.18418028950691223, 0.18418741226196289, 0.18419596552848816)
75% = (0.48274806141853333, 0.48278585076332092, 0.48283094167709351)
100% = (0.99991166591644287, 1.0000128746032715, 1.0001327991485596) - white

Thanks, bye.

damon shelton

unread,
Jan 24, 2014, 11:48:25 AM1/24/14
to python_in...@googlegroups.com
255.0 * each element for each color will give you what those 0-255 rgb values are, but not sure where you got your initial percentages versus values came from.
25% of 1.0 would be (.25, .25, .25)


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fd6b9726-9f39-44dc-84b7-7569856e6522%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Daz

unread,
Jan 24, 2014, 12:03:46 PM1/24/14
to python_in...@googlegroups.com
Heya

Yes I know the basic conversion but that dont match the program.

Basically if I set the color to be 0.25/0.25/0.25 of range value 0-1 

And then read the value that get processed to program it actually is (0.044156629592180252, 0.044154495000839233, 0.044151946902275085) Which makes me think that its being either gamma correct or something else in mean time. 

I thought that I was facing simply vector conversion but it looks like i have to find and reproduce the math for the curved emmm values in order to match the app. Bit annoying for the moment I found work around but I'd still want to know how to reproduce the match - or reverse engineer I guess? 

Thanks for help.

Justin Israel

unread,
Jan 24, 2014, 3:16:45 PM1/24/14
to python_in...@googlegroups.com
Yea at first I was going to suggest a fit function, because it seemed you wanted to remap your float 0-1 values to a new range between 0-255 ( or 20-235, etc). But towards the end of your later reply it does seem like you need to take a LUT into consideration. 
If your float values are already mapped through a LUT, then I would think you can just map them to 0-255 directly. 


On Sat, Jan 25, 2014 at 6:03 AM, Daz <dariu...@gmail.com> wrote:
Heya

Yes I know the basic conversion but that dont match the program.

Basically if I set the color to be 0.25/0.25/0.25 of range value 0-1 

And then read the value that get processed to program it actually is (0.044156629592180252, 0.044154495000839233, 0.044151946902275085) Which makes me think that its being either gamma correct or something else in mean time. 

I thought that I was facing simply vector conversion but it looks like i have to find and reproduce the math for the curved emmm values in order to match the app. Bit annoying for the moment I found work around but I'd still want to know how to reproduce the match - or reverse engineer I guess? 

Thanks for help.

On Friday, 24 January 2014 16:48:25 UTC, damonshelton wrote:
255.0 * each element for each color will give you what those 0-255 rgb values are, but not sure where you got your initial percentages versus values came from.
25% of 1.0 would be (.25, .25, .25)


On Fri, Jan 24, 2014 at 6:41 AM, Daz <dariu...@gmail.com> wrote:
Heya

I'm trying to remap 3 dimensional vector to values of 0-255 

Can some1 suggest what algorithm I need to use to convert those vector values to more human rgb values?

I know that

0% = (0.0, 0.0, 0.0) - black
25% = (0.044156629592180252, 0.044154495000839233, 0.044151946902275085)
50% = (0.18418028950691223, 0.18418741226196289, 0.18419596552848816)
75% = (0.48274806141853333, 0.48278585076332092, 0.48283094167709351)
100% = (0.99991166591644287, 1.0000128746032715, 1.0001327991485596) - white

Thanks, bye.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Justin Israel

unread,
Jan 25, 2014, 1:09:12 AM1/25/14
to python_in...@googlegroups.com
Disclaimer: I know very little numpy
But if you don't have access to a lookup table (LUT) that actually defines your non-linear color mappings, then numpy/scipy has functions for interpolating values along a curve. Someone else can probably make this a lot better, but here is something that is linearly interpolating from your samples:
In [151]: import numpy as np

In [152]: rgb_samples = np.array([(0.0, 0.0, 0.0),
                 (0.044156629592180252, 0.044154495000839233, 0.044151946902275085), 
                 (0.18418028950691223, 0.18418741226196289, 0.18419596552848816), 
                 (0.48274806141853333, 0.48278585076332092, 0.48283094167709351), 
                 (0.99991166591644287, 1.0000128746032715, 1.0001327991485596)])

In [153]: y_sample = np.array([0, 255*.25, 255*.5, 255*.75, 255])

In [154]: np.interp(.33, rgb_samples[:,0], y_sample)
Out[154]: 158.63533146734287

In [155]: np.interp(.33, rgb_samples[:,1], y_sample)
Out[155]: 158.63061312361012

In [156]: np.interp(.33, rgb_samples[:,2], y_sample)
Out[156]: 158.62497845173215

In [157]: float_reds = np.linspace(0., 1., 10)

In [158]: np.interp(float_reds, rgb_samples[:,0], y_sample)
Out[158]: 
array([   0.        ,   94.23304979,  135.62268918,  159.34706267,
        183.07143616,  200.22487316,  213.92137707,  227.61788098,
        241.3143849 ,  255.        ])
It is not going to be as accurate as having the entire LUT, but it will be close.
scipy has a more advanced version called interp1d, which supports different interpolation types, and will return you an interp function you can reuse:
In [163]: import scipy as sp

In [164]: fit_r = sp.interpolate.interp1d(rgb_samples[:,0], y_sample, copy=False)

In [165]: fit_g = sp.interpolate.interp1d(rgb_samples[:,1], y_sample, copy=False)

In [166]: fit_b = sp.interpolate.interp1d(rgb_samples[:,2], y_sample, copy=False)

In [167]: fit_r(.33)
Out[167]: array(158.63533146734287)

In [168]: fit_g(.33)
Out[168]: array(158.63061312361012)

In [169]: fit_b([.33, .45, .785736])
Out[169]: array([ 158.62497845,  184.24153582,  228.5786838 ])

In [170]: fit_b([.33, .45, .785736]).round().astype(int)
Out[170]: array([159, 184, 229])


Reply all
Reply to author
Forward
0 new messages