GUI programming/arrays in Python -
i need little more elaboration on arrays in gui programming. image processing, given following piece of code example of image processing:
def grayscale(im): height=len(im) width = len(im[0]) row in range(height): col in range(width): average = sum(im[row][col])/3 im[row][col]=[average,average,average] return im
the final line before code returns--what mean? code supposed running through pixel pixel , averaging out rgb values grayscale value--how sum of each pixel/3 average? how code know red, blue, , green values are?
each color in pixel defined variation of 3 components : red, green , blue, oscillating between 0 , 255, creating 16 millions colors (255^3
).
a shade of gray represented 3 identical values red, green , blue.
there several methods achieve grayscale convertion, including quick n' dirty average method (see others here).
since grayscale needs 1 scale (from white black), can average 3 components formula (r + g + b) / 3
make new color value each color component, creating gray shade.
Comments
Post a Comment