Skip to content

Instantly share code, notes, and snippets.

@schinken
Created April 22, 2012 10:59
Show Gist options
  • Save schinken/2463560 to your computer and use it in GitHub Desktop.
Save schinken/2463560 to your computer and use it in GitHub Desktop.
def mapRange( val, min1, max1, min2, max2 ):
return (val-min1)/(max1-min1) * (max2-min2) + min2
def toGrayscale( rgb, steps = 3.0 ):
r, g, b = rgb
value = float( r + g + b ) / 3.0
value = mapRange( value, 0.0, 255.0, 0.0, steps )
return int( round( value ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment