PIL question for pixel count

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thekid
    New Member
    • Feb 2007
    • 145

    PIL question for pixel count

    Hi, how can I open an image and get the R,G,B values of just the first line?

    Code:
    from PIL import Image
    
    im=Image.open("image.bmp")
    img=im.getcolors()
    print img
    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.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Do you mean that you want the pixels in the first row?
    Code:
    >>> img.size
    (50, 50)
    >>> for i in range(img.size[0]):
    ... 	print img.getpixel((i,0))
    ... 	
    (0, 0, 0)
    (0, 0, 0)
    (0, 0, 0)
    (0, 0, 0)
    (0, 0, 0)
    (36, 27, 26)
    (36, 11, 10)
    (107, 4, 3)
    (158, 6, 5)
    (125, 27, 26)
    (104, 3, 2)
    (127, 4, 2)
    (164, 6, 4)
    (160, 23, 5)
    (171, 29, 6)
    (141, 5, 3)
    (104, 17, 16)
    (128, 4, 3)
    (116, 4, 2)
    (138, 5, 3)
    (133, 14, 6)
    (138, 133, 69)
    (89, 52, 50)
    (87, 82, 77)
    (90, 90, 87)
    (89, 86, 84)
    (92, 89, 89)
    (120, 64, 54)
    (137, 92, 27)
    (138, 5, 2)
    (133, 11, 2)
    (135, 6, 2)
    (131, 5, 2)
    (131, 17, 16)
    (157, 20, 20)
    (145, 15, 13)
    (121, 6, 5)
    (99, 3, 2)
    (123, 4, 2)
    (91, 12, 11)
    (167, 21, 20)
    (43, 1, 0)
    (45, 1, 0)
    (79, 27, 27)
    (19, 19, 19)
    (0, 0, 0)
    (0, 0, 0)
    (0, 0, 0)
    (0, 0, 0)
    (0, 0, 0)
    >>>

    Comment

    • Thekid
      New Member
      • Feb 2007
      • 145

      #3
      Yes, that's what I was looking for thanks.

      Comment

      Working...