PIL Decoder mode vs raw mode arguemts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nebulism
    New Member
    • Jun 2007
    • 31

    PIL Decoder mode vs raw mode arguemts

    Hey everyone,

    I am currently creating images pixel by pixel. This is too slow for many images. Anyways, I want to use the fromstring module in the Image library. I have read at this url, http://effbot.org/imagingbook/decoder.htm, that I use an unsigned little endian 16 bit decoder in the calling of the function.

    My segment that is called looks like this:

    img2=Image.from string("L",(512 ,512),dummystri ng2,"raw", "F;16")

    However I run into some type of library issue that I have yet to solve.

    Traceback (most recent call last):
    File "<pyshell#4 1>", line 1, in <module>
    img2=Image.from string("L",(512 ,512),dummystri ng2,"raw", "F;16")
    File "C:\Python25\li b\site-packages\PIL\Im age.py", line 1744, in fromstring
    im.fromstring(d ata, decoder_name, args)
    File "C:\Python25\li b\site-packages\PIL\Im age.py", line 570, in fromstring
    d = _getdecoder(sel f.mode, decoder_name, args)
    File "C:\Python25\li b\site-packages\PIL\Im age.py", line 373, in _getdecoder
    return apply(decoder, (mode,) + args + extra)
    ValueError: unknown raw mode

    Am I supposed to import some decoder library, and if so, which one?

    Thanks alot,
    JP
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    My apologies, Nebulism. I just found your post in the Articles section.

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      I'll check the Python Imaging Library Handbook and get back to you.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by Nebulism
        Hey everyone,

        I am currently creating images pixel by pixel. This is too slow for many images. Anyways, I want to use the fromstring module in the Image library. I have read at this url, http://effbot.org/imagingbook/decoder.htm, that I use an unsigned little endian 16 bit decoder in the calling of the function.

        My segment that is called looks like this:

        img2=Image.from string("L",(512 ,512),dummystri ng2,"raw", "F;16")

        However I run into some type of library issue that I have yet to solve.

        Traceback (most recent call last):
        File "<pyshell#4 1>", line 1, in <module>
        img2=Image.from string("L",(512 ,512),dummystri ng2,"raw", "F;16")
        File "C:\Python25\li b\site-packages\PIL\Im age.py", line 1744, in fromstring
        im.fromstring(d ata, decoder_name, args)
        File "C:\Python25\li b\site-packages\PIL\Im age.py", line 570, in fromstring
        d = _getdecoder(sel f.mode, decoder_name, args)
        File "C:\Python25\li b\site-packages\PIL\Im age.py", line 373, in _getdecoder
        return apply(decoder, (mode,) + args + extra)
        ValueError: unknown raw mode

        Am I supposed to import some decoder library, and if so, which one?

        Thanks alot,
        JP
        This page, in the section entitled "Decoding Floating Point Data" says:
        You can use the "raw" decoder to read images where data is packed in any standard machine data type, using one of the following raw modes:
        mode description
        "F" 32-bit native floating point.
        "F;8" 8-bit unsigned integer.
        "F;8S" 8-bit signed integer.
        "F;16" 16-bit little endian unsigned integer.
        "F;16S" 16-bit little endian signed integer.
        "F;16B" 16-bit big endian unsigned integer.
        "F;16BS" 16-bit big endian signed integer.
        "F;16N" 16-bit native unsigned integer.
        "F;16NS" 16-bit native signed integer.

        Comment

        • Nebulism
          New Member
          • Jun 2007
          • 31

          #5
          I have been looking at that and if you notice the function that I call includes the little endian floating point 16 bit int "F;16". Some reason it does not recognize the decoder (look at the error text included in the original post)? I was wondering if it was a syntax issue. Any ideas?

          JP

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by Nebulism
            I have been looking at that and if you notice the function that I call includes the little endian floating point 16 bit int "F;16". Some reason it does not recognize the decoder (look at the error text included in the original post)? I was wondering if it was a syntax issue. Any ideas?

            JP
            Reading this:
            The raw mode field is used to determine how the data should be unpacked to match PIL's internal pixel layout. PIL supports a large set of raw modes; for a complete list, see the table in the Unpack.c module. The following table describes some commonly used raw modes:
            mode description
            "1" 1-bit bilevel, stored with the leftmost pixel in the most significant bit. 0 means black, 1 means white.
            "1;I" 1-bit inverted bilevel, stored with the leftmost pixel in the most significant bit. 0 means white, 1 means black.
            "1;R" 1-bit reversed bilevel, stored with the leftmost pixel in the least significant bit. 0 means black, 1 means white.
            "L" 8-bit greyscale. 0 means black, 255 means white.
            I get the impression that you have mode and raw mode arguments reversed.

            Try[CODE=python]img2 = Image.fromstrin g("F;16", (512, 512), dummystring2, "raw", "L")[/CODE]

            Comment

            • Nebulism
              New Member
              • Jun 2007
              • 31

              #7
              I have tried reorganizing the inputs to the function, however it is still failing.

              Is there a specific library i might need to use?

              img2=Image.from string("L",(512 ,512), buffed, "raw", "F;16")

              Traceback (most recent call last):
              File "<pyshell#2 6>", line 1, in <module>
              img2=Image.from string("L",(512 ,512), buffed, "raw", "F;16")
              File "C:\Python25\li b\site-packages\PIL\Im age.py", line 1744, in fromstring
              im.fromstring(d ata, decoder_name, args)
              File "C:\Python25\li b\site-packages\PIL\Im age.py", line 570, in fromstring
              d = _getdecoder(sel f.mode, decoder_name, args)
              File "C:\Python25\li b\site-packages\PIL\Im age.py", line 373, in _getdecoder
              return apply(decoder, (mode,) + args + extra)
              ValueError: unknown raw mode



              Thanks,
              JP

              Comment

              Working...