PMXBOT Log file Viewer

Help | Karma | Search:

#pil logs for Monday the 21st of October, 2013

(Back to #pil overview) (Back to channel listing) (Animate logs)
[15:54:46] <Heiber> Hi there
[15:55:26] <Heiber> I am trying to save a tiff image using pillow from raw to group3, and I got this error
[15:55:29] <Heiber> atts = dict([(k,v) for (k,(v,)) in ifd.items() if k not in blocklist])
[15:55:29] <Heiber> ValueError: too many values to unpack
[15:55:53] <Heiber> maybe somebody can help me
[16:03:07] <wiredfool> Heiber: yeah
[16:03:40] <wiredfool> what version are you using?
[16:03:47] <wiredfool> of Pillow
[16:04:19] <Heiber> 2.2.1 version
[16:04:26] <Heiber> and 3.8.1. libtiff
[16:04:39] <wiredfool> that's not a libtiff issue, that's a pillow one
[16:04:47] <Heiber> ok
[16:05:02] <Heiber> I have a tiff raw image 300 dpi, 30mb disk space
[16:05:19] <Heiber> I open it with TiffImagePlugin.TiffImageFile
[16:05:49] <Heiber> then I change info array with info['compression'] = 'group3'
[16:05:52] <wiredfool> yeah. what's happening is that there's something in the tiff image directory that's not fitting the template of key, (value,) as a tuple
[16:05:59] <Heiber> then I do .save and I got that error
[16:06:15] <wiredfool> ah. try save('filename.tiff', compression='group4')
[16:06:19] <wiredfool> or group3
[16:06:25] <Heiber> let me check
[16:07:43] <Heiber> it saves but without compression
[16:07:51] <Heiber> just raw as original
[16:08:01] <wiredfool> right, just seeing that. let me look at the code for a sec
[16:08:15] <Heiber> tif6 = TiffImagePlugin.TiffImageFile('c:/Scanner/aaa.tif')
[16:08:21] <Heiber> tif6.save("c:/SCanner/otrootrootro.tiff", compression='group3')
[16:09:13] <wiredfool> yeah. I'm looking at it, and I'm not sure how it worked.
[16:09:30] <wiredfool> the info dicts require tuples, but the compression is coming out as a string
[16:09:48] <wiredfool> if it doesn't get the string from the info dict, then it doesn't register the compression.
[16:11:20] <Heiber> mmm
[16:12:54] <Heiber> what recommend me to convert this image to tiff compressed?
[16:13:52] <wiredfool> give me a few minutes
[16:16:27] <wiredfool> It looks like the tests on it don't actually check what they're supposed to.
[16:17:32] <Heiber> oo so many thanks wiredtool
[16:17:48] <wiredfool> this was originally my patch
[16:27:10] <Heiber> aaa ok
[16:27:17] <Heiber> so you are the author :)
[16:27:23] <wiredfool> of this part
[16:29:01] <Heiber> that's good
[16:30:45] <Heiber> pillow let me work with image in a StringIO?
[16:31:42] <wiredfool> yes in python 2.x, use bytesio in 3.x
[16:32:28] <wiredfool> can you set Image.DEBUG=True, run your original crashing save, and give me the line after: 'Saving using libtiff encoder'
[16:32:46] <Heiber> ok sure
[16:33:10] <wiredfool> if it's long, post it at https://gist.github.com/
[16:33:29] <Heiber> using info array to change compression?
[16:33:49] <Heiber> or passing compression on save function?
[16:33:57] <Heiber> I will do both
[16:34:04] <wiredfool> the first
[16:35:44] <Heiber> mmm does not show nothing
[16:36:05] <wiredfool> hmm.
[16:36:20] <Heiber> >>> tif6.DEBUG = True
[16:36:22] <Heiber> >>> tif6.info['compression'] = 'group4'
[16:36:22] <Heiber> >>> tif6.save("c:/Scanner/pruebadebug.tiff")
[16:36:22] <Heiber> Traceback (most recent call last):
[16:36:22] <Heiber> File "<console>", line 1, in <module>
[16:36:22] <Heiber> File "C:\Python27\lib\site-packages\PIL\Image.py", line 1453, in save
[16:36:26] <Heiber> save_handler(self, fp, filename)
[16:36:26] <Heiber> File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 1008, in _save
[16:36:26] <Heiber> atts = dict([(k,v) for (k,(v,)) in ifd.items() if k not in blocklist])
[16:36:28] <Heiber> ValueError: too many values to unpack
[16:36:34] <wiredfool> nope, Image.DEBUG
[16:36:40] <Heiber> o sorry
[16:36:45] <wiredfool> it's a static flag on the module
[16:36:57] <wiredfool> no problem
[16:37:17] <Heiber> Traceback (most recent call last):
[16:37:17] <Heiber> File "<console>", line 1, in <module>
[16:37:17] <Heiber> File "C:\Python27\lib\site-packages\PIL\Image.py", line 1453, in save
[16:37:17] <Heiber> save_handler(self, fp, filename)
[16:37:17] <Heiber> File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 1008, in _save
[16:37:17] <Heiber> atts = dict([(k,v) for (k,(v,)) in ifd.items() if k not in blocklist])
[16:37:19] <Heiber> ValueError: too many values to unpack
[16:37:21] <Heiber> Saving using libtiff encoder
[16:37:23] <Heiber> [(256, (2552,)), (257, (4200,)), (258, (8, 8, 8)), (259, (4,)), (262, (2,)), (273, (0,)), (277, (3,)), (278, (4200,)), (279, (32155200,))]
[16:37:38] <wiredfool> ah, ok.
[16:37:55] <Heiber> did you realize the problem?
[16:38:07] <wiredfool> it's the 258 tag
[16:38:08] <Heiber> sorry my english I am an spanish speaker
[16:38:12] <wiredfool> no problem
[16:38:29] <wiredfool> is this a full color tiff?
[16:38:47] <Heiber> yes
[16:38:57] <Heiber> rgb 24 300 dpi full color
[16:39:17] <Heiber> how can I change it to black and whit? I have to do barcode processing.
[16:39:36] <wiredfool> img.convert('1')
[16:40:14] <wiredfool> there's also a threshold, or point() method if you need more comprehensive control over the conversion
[16:40:57] <wiredfool> you might try group4 after conversion, since it's basically a better version of group3.
[16:41:46] <Heiber> >>> tif6.convert('1')
[16:41:48] <Heiber> <PIL.Image.Image image mode=1 size=2552x4200 at 0x247C1C0>
[16:41:48] <Heiber> >>> print tif6.info
[16:41:48] <Heiber> {'resolution': (1, 1), 'compression': 'group4'}
[16:41:48] <Heiber> >>> tif6.save("c:/Scanner/gris.tiff")
[16:41:48] <Heiber> Saving using libtiff encoder
[16:41:49] <Heiber> [(256, (2552,)), (257, (4200,)), (258, (8, 8, 8)), (259, (4,)), (262, (2,)), (273, (0,)), (277, (3,)), (278, (4200,)), (279, (32155200,))]
[16:41:52] <Heiber> Traceback (most recent call last):
[16:41:54] <Heiber> File "<console>", line 1, in <module>
[16:41:56] <Heiber> File "C:\Python27\lib\site-packages\PIL\Image.py", line 1453, in save
[16:41:58] <Heiber> save_handler(self, fp, filename)
[16:42:00] <Heiber> File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 1008, in _save
[16:42:04] <Heiber> atts = dict([(k,v) for (k,(v,)) in ifd.items() if k not in blocklist])
[16:42:06] <Heiber> ValueError: too many values to unpack
[16:42:11] <wiredfool> that's not clearing the tiff tags
[16:42:29] <wiredfool> I need to fix that anyway
[16:43:28] <Heiber> tif7 = TiffImagePlugin.TiffImageFile('c:/Scanner/testsebastian.tiff')
[16:43:28] <Heiber> *** TiffImageFile._open ***
[16:43:28] <Heiber> - __first: 8
[16:43:28] <Heiber> - ifh: II*
[16:43:49] <Heiber> tag: ImageWidth (256) - type: short (3) - value: (2552,)
[16:43:49] <Heiber> tag: ImageLength (257) - type: short (3) - value: (4200,)
[16:43:49] <Heiber> tag: BitsPerSample (258) - type: short (3) - value: (8, 8, 8)
[16:43:49] <Heiber> tag: Compression (259) - type: short (3) - value: (1,)
[16:43:49] <Heiber> tag: PhotometricInterpretation (262) - type: short (3) - value: (2,)
[16:43:49] <Heiber> tag: StripOffsets (273) - type: long (4) - value: (180,)
[16:43:51] <Heiber> tag: SamplesPerPixel (277) - type: short (3) - value: (3,)
[16:43:53] <Heiber> tag: RowsPerStrip (278) - type: short (3) - value: (4200,)
[16:43:55] <Heiber> tag: StripByteCounts (279) - type: long (4) - value: (32155200,)
[16:43:57] <Heiber> tag: XResolution (282) - type: rational (5) - value: ((300, 1),)
[16:43:59] <Heiber> tag: YResolution (283) - type: rational (5) - value: ((300, 1),)
[16:44:01] <Heiber> tag: ResolutionUnit (296) - type: short (3) - value: (2,)
[16:44:05] <Heiber> *** Summary ***
[16:44:07] <Heiber> - compression: raw
[16:44:09] <Heiber> - photometric_interpretation: 2
[16:44:11] <Heiber> - planar_configuration: 1
[16:44:13] <Heiber> - fill_order: 1
[16:44:15] <Heiber> - size: (2552, 4200)
[16:44:16] <wiredfool> yeah. Add BITSPERSAMPLE to the blocklist= line
[16:44:17] <Heiber> format key: ('II', 2, 1, 1, (8, 8, 8), ())
[16:44:19] <Heiber> - raw mode: RGB
[16:44:21] <Heiber> - pil mode: RGB
[16:44:23] <Heiber> tiles: [('raw', (0, 0, 2552, 4200), 180, ('RGB', 0, 1))]
[16:44:25] <Heiber> that's is helpfull?
[16:44:38] <wiredfool> thats' an rgb image.
[16:44:58] <wiredfool> convert returns a new image,
[16:45:07] <wiredfool> so bw = img.convert('1')
[16:45:28] <Heiber> how I add BITRESAMPLE to the blocklist=?
[16:46:07] <Heiber> b = tif7.convert('1')
[16:46:07] <Heiber> >>> print b.info
[16:46:07] <Heiber> {'compression': 'raw', 'dpi': (300, 300)}
[16:46:44] <wiredfool> blocklist = [STRIPOFFSETS, STRIPBYTECOUNTS, ROWSPERSTRIP, ICCPROFILE] # ICC Profile crashes.
[16:46:52] <wiredfool> TiffImagePlugin.py, lini 1010
[16:46:58] <wiredfool> line
[16:47:15] <Heiber> b.info['compression'] = 'group3'
[16:47:15] <Heiber> >>> b.save('c:/Scanner/group3.tiff')
[16:47:16] <Heiber> Saving using libtiff encoder
[16:47:16] <Heiber> [(256, (2552,)), (257, (4200,)), (259, (3,)), (262, (1,)), (273, (0,)), (278, (4200,)), (279, (1339800,))]
[16:47:16] <Heiber> {256: 2552, 257: 4200, 259: 3, 262: 1}
[16:47:22] <Heiber> ok I will add that
[16:47:41] <wiredfool> otoh, that seems to have worked, since the convert didn't copy the bytes pre sample entry in the info linst
[16:48:55] <Heiber> yes, if I convert it and save it worked
[16:49:08] <Heiber> let me check if changing BITRESAMPLE makes it working with full color
[16:49:24] <wiredfool> g3/4 aren't color compressions
[16:49:53] <wiredfool> you'll want tiff_deflate or tiff_adobe_deflate compression to do color
[16:50:13] <Heiber> aaa ok so I have to convert it ...
[16:50:17] <Heiber> that was my error
[16:50:45] <wiredfool> well, it shouldn't do what it was doing.
[16:50:46] <Heiber> mmm
[16:50:58] <Heiber> it adds some noise on background
[16:51:10] <Heiber> a lot of points
[16:51:57] <wiredfool> g4 is lossless, but only for bw. And it doesn't compress small features well.
[16:52:17] <Heiber> well i do it in group3
[16:52:20] <wiredfool> on the other hand, it's really good for clean text on a white background
[16:52:31] <wiredfool> group4 is basically a better version of g3
[16:52:33] <Heiber> maybe you can pointme
[16:52:43] <Heiber> I have this tiff scanned full color 300 dpi
[16:53:06] <Heiber> I have to convert it to jpg and tiff group3
[16:53:19] <Heiber> jpg I think is not problem
[16:53:56] <wiredfool> what are you scanning?
[16:53:57] <Heiber> so for tiff I use convert('1'), but result image has a lot of noise on background
[16:54:11] <Heiber> can I send you the image?
[16:54:18] <Heiber> it is a simple scan
[16:54:26] <Heiber> no photo
[16:54:49] <Heiber> maybe some another function to make background clear?
[16:55:40] <Heiber> original version is a Scan using twain doing a .BMP file
[16:57:05] <wiredfool> look at Image.point
[16:57:11] <wiredfool> I've got to run, meeting here.
[16:57:26] <Heiber> thanks for your help
[17:01:53] <Heiber> wiredtool: thanks, dither = 0 does the thing