By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

PIL Decoder mode vs raw mode arguemts

P: 31
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
Share this Question
Share on Google+
6 Replies


bartonc
Expert 5K+
P: 6,596
My apologies, Nebulism. I just found your post in the Articles section.
Oct 2 '07 #2

bartonc
Expert 5K+
P: 6,596
I'll check the Python Imaging Library Handbook and get back to you.
Oct 2 '07 #3

bartonc
Expert 5K+
P: 6,596
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

P: 31
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
Expert 5K+
P: 6,596
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

P: 31
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.