How to get each pixel value from a picture file!

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

    How to get each pixel value from a picture file!

    I want to change some pixel value in the picture file. how to do it?

    If I read the file in binary mode, a bit == a pixel ?

    Thanks

  • Steve Holden

    #2
    Re: How to get each pixel value from a picture file!

    Lucas wrote:
    I want to change some pixel value in the picture file. how to do it?
    >
    The most popular way is probably the Python Image Library, known to its
    friends as PIL:

    Complete Python PIL/Pillow image processing guide. Learn how to resize, edit, crop, and convert images using Python with practical examples.


    You will see from

    The python image module in Python Image Library (PIL). Understand the Image module in Python, including image loading, editing, transformations, and common use cases for developers.


    that images have .getpixel() and .putpixel() methods that will allow you
    to read and set individual pixels if you want. Be aware that the
    forthcoming release will give faster access using something called
    "pixel access objects", about which I know nothing.
    If I read the file in binary mode, a bit == a pixel ?
    >
    Only for monochrome images, of course. Greyscale and color images have
    more bits per pixel, and some formats use a palette mapping to allow
    high color-fidelity with fewer bits per pixel (GIF is one such format).

    Download PIL and play with it. I'm sure you'll have a lot of fun, and
    you can do a surprising amount of processing just noodling around in an
    interactive interpreter session.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • Lucas

      #3
      Re: How to get each pixel value from a picture file!

      Thank you for your answer.

      I have some new questions:

      1) the value of return from getpixel() is a RGB number?
      print im.getpixel((44 ,55)) ----(160,160,160)

      2) I want to put a number into the picture for encryption(repl ace least
      significant bit (LSB) of image intensity with message bit).

      If i use putpixel((44,55 ),0) , the number 0 will be changed RGB
      value or others.?

      3) pix = im.load()
      print pix[44,55]
      pix[44, 55] = value
      my python cannt identify "[x,y]" ??

      Steve Holden wrote:
      Lucas wrote:
      I want to change some pixel value in the picture file. how to do it?
      The most popular way is probably the Python Image Library, known to its
      friends as PIL:
      >
      Complete Python PIL/Pillow image processing guide. Learn how to resize, edit, crop, and convert images using Python with practical examples.

      >
      You will see from
      >
      The python image module in Python Image Library (PIL). Understand the Image module in Python, including image loading, editing, transformations, and common use cases for developers.

      >
      that images have .getpixel() and .putpixel() methods that will allow you
      to read and set individual pixels if you want. Be aware that the
      forthcoming release will give faster access using something called
      "pixel access objects", about which I know nothing.
      >
      If I read the file in binary mode, a bit == a pixel ?
      Only for monochrome images, of course. Greyscale and color images have
      more bits per pixel, and some formats use a palette mapping to allow
      high color-fidelity with fewer bits per pixel (GIF is one such format).
      >
      Download PIL and play with it. I'm sure you'll have a lot of fun, and
      you can do a surprising amount of processing just noodling around in an
      interactive interpreter session.
      >
      regards
      Steve
      --
      Steve Holden +44 150 684 7255 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://holdenweb.blogspot.com
      Recent Ramblings http://del.icio.us/steve.holden

      Comment

      • Steve Holden

        #4
        Re: How to get each pixel value from a picture file!

        Lucas wrote:
        Thank you for your answer.
        >
        I have some new questions:
        >
        1) the value of return from getpixel() is a RGB number?
        print im.getpixel((44 ,55)) ----(160,160,160)
        >
        Yes, that's an RGB tuple.
        2) I want to put a number into the picture for encryption(repl ace least
        significant bit (LSB) of image intensity with message bit).
        >
        If i use putpixel((44,55 ),0) , the number 0 will be changed RGB
        value or others.?
        >
        I think you'd need to use

        putpixel((44, 55), (0, 0, 0))

        but it's easy enough to try out interactively ...
        3) pix = im.load()
        print pix[44,55]
        pix[44, 55] = value
        my python cannt identify "[x,y]" ??
        >
        Now what makes you think that an image can be addressed that way? I'd be
        quite surprised if yo got anything other than a TypeError doing that.

        regards
        Steve
        --
        Steve Holden +44 150 684 7255 +1 800 494 3119
        Holden Web LLC/Ltd http://www.holdenweb.com
        Skype: holdenweb http://holdenweb.blogspot.com
        Recent Ramblings http://del.icio.us/steve.holden

        Comment

        • Lucas

          #5
          Re: How to get each pixel value from a picture file!

          :)

          1)I just copy the tutorial to run "print pix[44,55]". I really dont
          know why they wrote that?!


          2) i think putpixel((44, 55), (0, 0, 0)) and putpixel((44,55 ),0) is
          same.

          thank you again. I think I have solved my problem.

          Steve Holden wrote:
          Lucas wrote:
          Thank you for your answer.

          I have some new questions:

          1) the value of return from getpixel() is a RGB number?
          print im.getpixel((44 ,55)) ----(160,160,160)
          Yes, that's an RGB tuple.
          >
          2) I want to put a number into the picture for encryption(repl ace least
          significant bit (LSB) of image intensity with message bit).

          If i use putpixel((44,55 ),0) , the number 0 will be changed RGB
          value or others.?
          I think you'd need to use
          >
          putpixel((44, 55), (0, 0, 0))
          >
          but it's easy enough to try out interactively ...
          >
          3) pix = im.load()
          print pix[44,55]
          pix[44, 55] = value
          my python cannt identify "[x,y]" ??
          >
          Now what makes you think that an image can be addressed that way? I'd be
          quite surprised if yo got anything other than a TypeError doing that.
          >
          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC/Ltd http://www.holdenweb.com
          Skype: holdenweb http://holdenweb.blogspot.com
          Recent Ramblings http://del.icio.us/steve.holden

          Comment

          • Leif K-Brooks

            #6
            Re: How to get each pixel value from a picture file!

            Lucas wrote:
            1)I just copy the tutorial to run "print pix[44,55]". I really dont
            know why they wrote that?!
            What tutorial? Where does it say that?

            Comment

            • Lucas

              #7
              Re: How to get each pixel value from a picture file!

              The python image module in Python Image Library (PIL). Understand the Image module in Python, including image loading, editing, transformations, and common use cases for developers.


              im.load() said....

              Leif K-Brooks wrote:
              Lucas wrote:
              1)I just copy the tutorial to run "print pix[44,55]". I really dont
              know why they wrote that?!
              >
              What tutorial? Where does it say that?

              Comment

              • Gabriel Genellina

                #8
                Re: How to get each pixel value from a picture file!

                At Monday 23/10/2006 21:02, Lucas wrote:
                >http://www.pythonware.com/library/pi...book/image.htm
                >
                >im.load() said....
                >
                1)I just copy the tutorial to run "print pix[44,55]". I really dont
                know why they wrote that?!
                It clearly states that this syntax applies only to version 1.1.6 -
                and I presume you're using 1.1.5.
                (And please, don't top post...!)


                --
                Gabriel Genellina
                Softlab SRL

                _______________ _______________ _______________ _____
                Correo Yahoo!
                Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
                ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

                Comment

                • Fredrik Lundh

                  #9
                  Re: How to get each pixel value from a picture file!

                  Steve Holden wrote:
                  >3) pix = im.load()
                  > print pix[44,55]
                  > pix[44, 55] = value
                  > my python cannt identify "[x,y]" ??
                  >>
                  >
                  Now what makes you think that an image can be addressed that way? I'd be
                  quite surprised if yo got anything other than a TypeError doing that.
                  PIL 1.1.6 (still in beta) supports special pixel access objects.
                  earlier versions don't.

                  </F>

                  Comment

                  • Fredrik Lundh

                    #10
                    Re: How to get each pixel value from a picture file!

                    Dennis Lee Bieber wrote:
                    >2) i think putpixel((44, 55), (0, 0, 0)) and putpixel((44,55 ),0) is
                    >same.
                    >
                    It shouldn't be... The former is three separate data values, the
                    latter is one.
                    the "putpixel" API is polymorphic; you can use either tuples or integers
                    for RGB pixels (the latter should have the form 0xAARRGGBB).

                    </F>



                    Comment

                    • Tim Roberts

                      #11
                      Re: How to get each pixel value from a picture file!

                      "Lucas" <Luwian@gmail.c omwrote:
                      >
                      >2) I want to put a number into the picture for encryption(repl ace least
                      >significant bit (LSB) of image intensity with message bit).
                      What formats are your images? Remember that JPEG images are compressed
                      when they are written. It is rather unlikely that your low-order bit
                      changes will survive the compression process.

                      There is lots and lots of research on this subject. It's called
                      "steganogra phy" and "digital watermarking". Google is your friend.
                      --
                      Tim Roberts, timr@probo.com
                      Providenza & Boekelheide, Inc.

                      Comment

                      Working...