471,338 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

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.fromstring("L",(512,512),dummystring2," 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#41>", line 1, in <module>
img2=Image.fromstring("L",(512,512),dummystring2," raw", "F;16")
File "C:\Python25\lib\site-packages\PIL\Image.py", line 1744, in fromstring
im.fromstring(data, decoder_name, args)
File "C:\Python25\lib\site-packages\PIL\Image.py", line 570, in fromstring
d = _getdecoder(self.mode, decoder_name, args)
File "C:\Python25\lib\site-packages\PIL\Image.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
Oct 1 '07 #1
6 8251
bartonc
6,596 Expert 4TB
My apologies, Nebulism. I just found your post in the Articles section.
Oct 2 '07 #2
bartonc
6,596 Expert 4TB
I'll check the Python Imaging Library Handbook and get back to you.
Oct 2 '07 #3
bartonc
6,596 Expert 4TB
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.fromstring("L",(512,512),dummystring2," 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#41>", line 1, in <module>
img2=Image.fromstring("L",(512,512),dummystring2," raw", "F;16")
File "C:\Python25\lib\site-packages\PIL\Image.py", line 1744, in fromstring
im.fromstring(data, decoder_name, args)
File "C:\Python25\lib\site-packages\PIL\Image.py", line 570, in fromstring
d = _getdecoder(self.mode, decoder_name, args)
File "C:\Python25\lib\site-packages\PIL\Image.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.
Oct 2 '07 #4
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
Oct 2 '07 #5
bartonc
6,596 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. img2 = Image.fromstring("F;16", (512, 512), dummystring2, "raw", "L")
Oct 2 '07 #6
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.fromstring("L",(512,512), buffed, "raw", "F;16")

Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
img2=Image.fromstring("L",(512,512), buffed, "raw", "F;16")
File "C:\Python25\lib\site-packages\PIL\Image.py", line 1744, in fromstring
im.fromstring(data, decoder_name, args)
File "C:\Python25\lib\site-packages\PIL\Image.py", line 570, in fromstring
d = _getdecoder(self.mode, decoder_name, args)
File "C:\Python25\lib\site-packages\PIL\Image.py", line 373, in _getdecoder
return apply(decoder, (mode,) + args + extra)
ValueError: unknown raw mode



Thanks,
JP
Oct 2 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by S Etchelecu | last post: by
2 posts views Thread by Geru | last post: by
reply views Thread by Whitney | last post: by
8 posts views Thread by jbrewer | last post: by
3 posts views Thread by Peter | last post: by
reply views Thread by jordi_ramis | last post: by
6 posts views Thread by Doug Stell | last post: by
1 post views Thread by =?Utf-8?B?c2Fz?= | last post: by
6 posts views Thread by Ankit | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.