Page 1 of 1

group4 compression bug

Posted: 2016-10-11T19:18:09-07:00
by richmarisa
Hi, I'm getting an all-black page when I try to convert this png image to a group4 compressed tif

The image: https://www.dropbox.com/s/7qv50tgzac8hgkv/0002.png?dl=0
My command: convert 0002.png -compress group4 0002.tif

Setting a threshold helps in this case, but I'm looking for a general way to convert pages of text and images (which I want to be dithered, not thresholded). I have other problem images that don't go to black with group4 compression if I use -auto-level but that only works sometimes.

Why is this image failing to all black? If this isn't a bug, is there a way to detect/predict which images are going to fail like this one?

Version: ImageMagick 7.0.3-2 Q16 x86_64 2016-09-28
MacOS 10.11.6

Thanks!

Re: group4 compression bug

Posted: 2016-10-11T19:45:10-07:00
by fmw42
I believe group4 may require a binary image before compressing. It may not directly convert your image to bilevel. So if you want to dither, try -monochrome in place of -threshold.

try

Code: Select all

convert 0002.png -monochrome -compress group4 0002.tif
This seems to work fine for me on IM 6.9.6.1 Q16 Mac OSX

See
https://en.wikipedia.org/wiki/Group_4_compression
http://www.imagemagick.org/script/comma ... monochrome
http://www.imagemagick.org/Usage/quantize/#monochrome

Re: group4 compression bug

Posted: 2016-10-12T05:20:31-07:00
by richmarisa
I agree that this worked in IM 6.9, the problem only appeared in version 7.0.2, I'm currently on 7.0.3-2
Adding -monochrome I get

convert 0002.png -monochrome -compress group4 0002.tif
convert(23133,0x7fff7507b000) malloc: *** error for object 0x7f8300000000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
and still get a black image

Re: group4 compression bug

Posted: 2016-10-12T06:57:55-07:00
by magick
We're using ImageMagick 7.0.3-3 and your command completes without complaint. Perhaps you ran out of memory in libtiff. Try this command instead:
  • convert -limit memory 2mb 0002.png -threshold 50% -compress group4 0002.tif

Re: group4 compression bug

Posted: 2016-10-12T07:53:34-07:00
by richmarisa
Thank you, limiting the memory did solve that crash.

Here is an image that works fine for me:
https://www.dropbox.com/s/f1axlkr1jtdjqhx/0003.png?dl=0
convert 0003.png -compress group4 0003.tif
(with or without -monochrome) gives me a very nice dithered tiff image instead of the all-black image from 0002.png.
You can see that using -threshold would not give a good result for 0003.png.

I've tried several dither and ordered-dither options which all seem to fail when convert-ing 0002.png
Might this be an initialization problem since there aren't very many non-white pixels in the image?
In general, pages full of text do convert nicely.

Here is another example image that is all black when converted to the group4 tif using a dither (not threshold) process.
https://www.dropbox.com/s/41cysju7o2ejqgt/0007.png?dl=0

Re: group4 compression bug

Posted: 2016-10-12T09:01:26-07:00
by fmw42
I can confirm that it works fine using -monochrome on IM 6.9.6.1 but fails on IM 7.0.3.3 Q16 Mac OSX (both non-hdri).

Works:

Code: Select all

convert 0007.png -monochrome -compress group4 0007_6.tif
Fails -- all black:

Code: Select all

im7 convert 0007.png -monochrome -compress group4 0007_7.tif