By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

PIL question for pixel count

Thekid
100+
P: 145
Hi, how can I open an image and get the R,G,B values of just the first line?

Expand|Select|Wrap|Line Numbers
  1. from PIL import Image
  2.  
  3. im=Image.open("image.bmp")
  4. img=im.getcolors()
  5. print img
  6.  
  7.  
I've tried im.getdata() , im.histogram, etc.... but again, what I'm looking for is more of R,G,B pixel counts for just the 1st line in the image.
Mar 30 '09 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Do you mean that you want the pixels in the first row?
Expand|Select|Wrap|Line Numbers
  1. >>> img.size
  2. (50, 50)
  3. >>> for i in range(img.size[0]):
  4. ...     print img.getpixel((i,0))
  5. ...     
  6. (0, 0, 0)
  7. (0, 0, 0)
  8. (0, 0, 0)
  9. (0, 0, 0)
  10. (0, 0, 0)
  11. (36, 27, 26)
  12. (36, 11, 10)
  13. (107, 4, 3)
  14. (158, 6, 5)
  15. (125, 27, 26)
  16. (104, 3, 2)
  17. (127, 4, 2)
  18. (164, 6, 4)
  19. (160, 23, 5)
  20. (171, 29, 6)
  21. (141, 5, 3)
  22. (104, 17, 16)
  23. (128, 4, 3)
  24. (116, 4, 2)
  25. (138, 5, 3)
  26. (133, 14, 6)
  27. (138, 133, 69)
  28. (89, 52, 50)
  29. (87, 82, 77)
  30. (90, 90, 87)
  31. (89, 86, 84)
  32. (92, 89, 89)
  33. (120, 64, 54)
  34. (137, 92, 27)
  35. (138, 5, 2)
  36. (133, 11, 2)
  37. (135, 6, 2)
  38. (131, 5, 2)
  39. (131, 17, 16)
  40. (157, 20, 20)
  41. (145, 15, 13)
  42. (121, 6, 5)
  43. (99, 3, 2)
  44. (123, 4, 2)
  45. (91, 12, 11)
  46. (167, 21, 20)
  47. (43, 1, 0)
  48. (45, 1, 0)
  49. (79, 27, 27)
  50. (19, 19, 19)
  51. (0, 0, 0)
  52. (0, 0, 0)
  53. (0, 0, 0)
  54. (0, 0, 0)
  55. (0, 0, 0)
  56. >>> 
Mar 31 '09 #2

Thekid
100+
P: 145
Yes, that's what I was looking for thanks.
Mar 31 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.