×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Pixel values in grayscale images

    Hi!

    This is just something I am trying out. The idea is to get a little familiar with Python and its image processing capabilities before building any application. I am having some doubts on the jpeg compression type. I am using the graphics module.
    Code:
    >>> import graphics
    To start with, I created a (blank) grayscale image and saved it (right away) with the following commands :
    Code:
    >>> im = graphics.Image.new((200,200),"L")
    >>> im.save("D:\\blank.jpg", quality=100, bpp=1, compression="no"
    As expected, this gave me a blank image. However, when I check its pixel values, it doesn't give me a single byte, but gives me a triplet (RGB values?)
    Code:
    >>> im.getpixel((23,123))
    (255,255,255)
    I also tried loading the newly created image into another image and checked the pixel values :
    Code:
    >>> bg = graphics.Image.open("D://blank.jpg")
    >>> bg.getpixel((23,123))
    (255,255,255)
    My question is, if the image is a grayscale image, why is the pixel value a triplet, and not a byte? Shouldn't the output for a grayscale image be something along the lines of :
    Code:
    >>> bg.getpixel((23,123))
    X (where X is a number between 0 and 255)
    Thanks
    Kedar

  2. #2
    Registered User
    Join Date
    May 2008
    Posts
    4

    Re: Pixel values in grayscale images

    getpixel is an undocumented function, which always returns a rgb-triplet.

    A grayscale image has identical values of red, green and blue thus being gray.
    Therefore the resulting (255, 255, 255) is correct as the getpixel function always returns a tuple with red, green and blue values regardless of display mode i.e. bit amount.

    More in this thread.

  3. #3
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Pixel values in grayscale images

    Thanks..

    I guess I accidentally stumbled upon the same method in a totally different way! Lucky me!

    Thanks..

Similar Threads

  1. Replies: 1
    Last Post: 2009-12-03, 10:44
  2. Finding RGB values of a pixel of an image
    By swarna.nokia in forum Mobile Java General
    Replies: 3
    Last Post: 2009-06-15, 10:16
  3. Finding RGB values of a pixel of an J2ME image
    By swarna.nokia in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2009-06-15, 10:11
  4. Incorrect rgb values for jpg images on S40 3rd ed
    By bjudfar in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-05-29, 16:34
  5. displaying pixel values to screen
    By gaurav17281 in forum Symbian User Interface
    Replies: 9
    Last Post: 2005-12-15, 11:13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •