Advertisement
Guest User

zfactor_imgdata

a guest
Oct 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from PIL import Image
  2. from numpy import array
  3.  
  4. im = Image.open('spectrum.png') # your image here
  5. width = im.width
  6. height = im.height
  7. colorchannels = 3
  8.  
  9. rgb_im = im.convert('RGB')
  10.  
  11. # data is 1-d list of [r,g,b] value sets
  12. data = list(rgb_im.getdata())
  13.  
  14. # reshape data into height x width x colorchannels
  15. samples = array(data).reshape(height,width,colorchannels)
  16.  
  17. # samples[0] is the first row, left to right
  18. # samples[height-1] is the last row
  19. # samples[0][0] is the first pixel [r,g,b] upper left corner
  20. # samples[height-1][width-1] is the last pixel lower right corner
  21.  
  22. #leftbound = width/2
  23. #topbound = height/2
  24. #boundwidth = 100
  25. #boundheight = 100
  26. # to take [r,g,b] measurements from an area
  27. # of known height, width, left, and top boundaries;
  28. # set the variables and iterate
  29. #   from
  30. #     samples[topbound][leftbound]
  31. #   to
  32. #     samples[topbound+boundheight][samples[leftbound+boundwidth]
  33. # using something like this:
  34.  
  35. #for y in range(boundheight):
  36. #    for x in range(boundwidth):
  37. #        # do something with
  38. #        #   samples[topbound+y][leftbound+x]
  39. #        # to go left-right top-bottom in the boundary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement