Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from numpy import array
- im = Image.open('spectrum.png') # your image here
- width = im.width
- height = im.height
- colorchannels = 3
- rgb_im = im.convert('RGB')
- # data is 1-d list of [r,g,b] value sets
- data = list(rgb_im.getdata())
- # reshape data into height x width x colorchannels
- samples = array(data).reshape(height,width,colorchannels)
- # samples[0] is the first row, left to right
- # samples[height-1] is the last row
- # samples[0][0] is the first pixel [r,g,b] upper left corner
- # samples[height-1][width-1] is the last pixel lower right corner
- #leftbound = width/2
- #topbound = height/2
- #boundwidth = 100
- #boundheight = 100
- # to take [r,g,b] measurements from an area
- # of known height, width, left, and top boundaries;
- # set the variables and iterate
- # from
- # samples[topbound][leftbound]
- # to
- # samples[topbound+boundheight][samples[leftbound+boundwidth]
- # using something like this:
- #for y in range(boundheight):
- # for x in range(boundwidth):
- # # do something with
- # # samples[topbound+y][leftbound+x]
- # # to go left-right top-bottom in the boundary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement