Most efficient way to get pixelcolors of an image?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • defn noob

    Most efficient way to get pixelcolors of an image?

    i want to process a large number of images and store their respective
    pixels in a matrix.

    what is the mostt efficient way of opening and checking them?
    i doubt pygame is made for this purpose :)

    i guess i could also use tkinter?


    and why cant i print out matrix after getting the pixels? do i have to
    deinit() pygame somehow?

    import pygame
    import sys
    import os

    print os.path.exists( 'C:/users/saftarn/desktop/images/bloba.bmp')

    pygame.init()
    screen = pygame.display. set_mode((800, 600))

    image = pygame.image.lo ad('C:/users/saftarn/desktop/images/bloba.bmp')
    imrect = image.get_rect( )
    imrect = imrect.move(200 , 200)

    matrix = []

    while 1:
    pygame.display. flip()
    screen.fill((25 5,255,255))
    screen.blit(ima ge, imrect)
    pygame.event.wa it()
    event = pygame.event.wa it()

    for x in range(1, 301):
    for y in range(1, 301):
    matrix.append(s creen.get_at((x , y)))

    #print matrix
    if event.type == pygame.QUIT:
    #print matrix
    sys.exit()
  • Larry Bates

    #2
    Re: Most efficient way to get pixelcolors of an image?

    defn noob wrote:
    i want to process a large number of images and store their respective
    pixels in a matrix.
    >
    what is the mostt efficient way of opening and checking them?
    i doubt pygame is made for this purpose :)
    >
    i guess i could also use tkinter?
    >
    >
    and why cant i print out matrix after getting the pixels? do i have to
    deinit() pygame somehow?
    >
    import pygame
    import sys
    import os
    >
    print os.path.exists( 'C:/users/saftarn/desktop/images/bloba.bmp')
    >
    pygame.init()
    screen = pygame.display. set_mode((800, 600))
    >
    image = pygame.image.lo ad('C:/users/saftarn/desktop/images/bloba.bmp')
    imrect = image.get_rect( )
    imrect = imrect.move(200 , 200)
    >
    matrix = []
    >
    while 1:
    pygame.display. flip()
    screen.fill((25 5,255,255))
    screen.blit(ima ge, imrect)
    pygame.event.wa it()
    event = pygame.event.wa it()
    >
    for x in range(1, 301):
    for y in range(1, 301):
    matrix.append(s creen.get_at((x , y)))
    >
    #print matrix
    if event.type == pygame.QUIT:
    #print matrix
    sys.exit()
    Most likely PIL (Pyhton Imaging Library).

    -Larry

    Comment

    • Diez B. Roggisch

      #3
      Re: Most efficient way to get pixelcolors of an image?

      defn noob schrieb:
      i want to process a large number of images and store their respective
      pixels in a matrix.
      >
      what is the mostt efficient way of opening and checking them?
      i doubt pygame is made for this purpose :)
      Au contaraire, it is.



      Diez

      Comment

      • defn noob

        #4
        Re: Most efficient way to get pixelcolors of an image?

        this just shows a GUI that normally shows pictures but it doesnt show
        any picture...


        from PIL import Image

        im = Image.open('C:/Users/saftarn/Desktop/images/giffer.gif')
        im2 = Image.open('C:/Users/saftarn/Desktop/images/blob.jpg')

        im.rotate(45).s how()
        im2.show()


        Comment

        Working...