do i need to create new rgbimage class

jimgardener at gmail.com jimgardener at gmail.com
Sat Dec 29 10:42:44 EST 2007


hi
am a beginner in python and PIL  .I need to read an RGB 8 bit image
(am using jpeg )and pack the rgb color values into a double value so i
can store the image as a list of pixelvalues.From my application i
should be able to call rgbimage1.getpixellist() to retrieve the double
values of an image.
Do i need to create a new class for this?I made something like

class myrgbimage:
      def  __init__(self,filename):

      def _readimage(self):
          im=Image.open(filename)
          self._readImage(filename)
          self._wd,self._ht=im.size
          for y in range(self._ht):
               for x in range(self._wd):
                     r,g,b=im.getpixel((x,y))
                     pval=self.rgbTodoubleval((r,g,b))
                     self._pixellist.append(pval)

      def rgbTodoubleval(self,(r,g,b)):
          alpha=255
          pixelvalue=(alpha<<24)|(r<<16 )|( g<<8) | b
          return pixelvalue

the way i am currently using this is to create instances using
filenames and then retrieving the list of pixelvalues in the image.
like
for z in imagefilenamelist:
      myimage=myrgbimage(z)
       imagelist.append(z)

so later on i can take each instance and get its width,height and
pixellist and work with them..anyway the code takes too much time and
I wish to know if i can get these 'packed pixelvalues'  straight away
without using the above class

jim



More information about the Python-list mailing list