Tuesday, 15 January 2013

python - Generate a gradient from extrema of a float Image -



python - Generate a gradient from extrema of a float Image -

as title states, need generate gradient lowest value highest value of given float image. shall serve legend image.

my thought create image , fill every pixel of value within range of extrema. still not pro in python, help nice. got far:

im = image.open('path_to.tiff') extrw=im.getextrema() grad = image.new('f', (10, 100)) pix = grad.load() in range(grad.size[0]): # every pixel: j in range(grad.size[1]): pixels[i,j] = (some_float)

as can see need somehow utilize extrema float values accordingly pixels create gradient. nice, if remain in pil library.

thank you!

after research found linear function. had to set minimum, maximum , length mathematical form : y=m*x+b

with help of kollegue figured: y(the pixel value)= ((minvalue-maxvalue)/h(heigth of image))*index_of_pixel+maxvalue. in code form:

extw=im.getextrema() grad_b = 10 grad = image.new('f', (grad_b, im_h)) pix = grad.load() in range(grad.size[0]): # every pixel: j in range(grad.size[1]): pix[i,j] = (extw[0]-extw[1]/im_h)*j+extw[1]

python python-imaging-library

No comments:

Post a Comment