Grasshopper

algorithmic modeling for Rhino

if i give a image sample RGB picture, what is the final number it gives to length?

Hi, I have given  a colorful picture to "image sample" and give the output to lenght of SDL line drawing component, then calculate the length of the curve.

the confusing thing is , what is the relatationship between the length and the RGB number?

how do 255,161,161 become 1.066804?

Thank you.

Views: 912

Replies to This Discussion

When you auto-convert a Colour to a Vector, it will remap the RGB channels onto XYZ coordinates. So first of all you lose the information in the Alpha channel, it's gone forever. The mapping of RGB (which are integers between 0 and 255 each) to XYZ which could be any floating point values, is as follows:

Dim factor As Double = 1.0 / 127.5
x = (colour.R * factor) - 1.0
y = (colour.G * factor) - 1.0
z = (colour.B * factor) - 1.0

So if a colour channel has the lowest value of 0, the corresponding coordinate will be -1.0. If the channel has the highest value of 255, the coordinate will be +1.0. In the case of [255,161,161] it does:

Dim factor As Double = 1.0 / 127.5
x = (255 * factor) - 1.0 which equals 1.0
y = (161 * factor) - 1.0 which equals 0.262745 (rounded to 6 decimal places)
z = (161 * factor) - 1.0 which equals 0.262745

 

So the length of the vector with these xyz coordinates is:

SquareRoot of (1.0² + 0.262745² + 0.262745²) which equals 1.066803 (rounded again)

 

It also follows the largest possible length of a vector created this way is the Square root of 3, which roughly equals 1.732050

 

This conversion works both ways incidentally, so as long as you convert unitized vectors into colours you'll always get a non-clipped result.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Thank you for so detailed tutorial! very clear, thank you

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service