Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. from PIL import Image
  2. import os
  3.  
  4. img_dir = "./sal1000-2"
  5. area_left = (250,340,350+16,340+37)
  6. area_right = (419,340,419+16,340+37)
  7. left_init = ()
  8. right_init = ()
  9. left = ()
  10. right = ()
  11.  
  12. flag = 0
  13.  
  14.  
  15. for file in sorted(os.listdir(img_dir)):
  16. if file.endswith(".jpg"):
  17. img = Image.open(img_dir+"/"+file)
  18. # CROP THE IMAGE
  19. cropped_left = img.crop(area_left)
  20. cropped_right = img.crop(area_right)
  21. # RESIZE THE IMAGES
  22. resized_left = cropped_left.resize((1,1))
  23. resized_right = cropped_right.resize((1,1))
  24.  
  25. # Keep the initial values from the first image
  26. if flag == 0 :
  27. left_init = resized_left.getpixel((0,0))
  28. right_init = resized_right.getpixel((0,0))
  29. flag = 1
  30. else :
  31. left = resized_left.getpixel((0,0))
  32. right = resized_right.getpixel((0,0))
  33.  
  34. redL = left[0]-left_init[0]
  35. greenL = left[1]-left_init[1]
  36. blueL = left[2]-left_init[2]
  37. redR = right[0]-right_init[0]
  38. greenR = right[1]-right_init[1]
  39. blueR = right[2]-right_init[2]
  40.  
  41. print("LEFT: t", str(greenL-blueL), "t RIGHT: t", str(greenR-blueR), file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement