Slow TIFF to PNG conversion
Slow TIFF to PNG conversion
I'm brand new to ImageMagick. My immediate need is to convert monochrome TIFF images to PNG on a Unix system, and I'm finding it to be much too slow.
My test image is a black & white TIFF image from a 200 DPI scan of an 8 1/2 x 11 document (around 1700 x 2200 pixels). The TIFF file is around 20K. We're not talking about something that's very big.
A straight conversion of this image to PNG is consistently taking around 17 seconds. I can convert it to GIF in around three seconds and to JPEG in less than one second. My timings using convert and using a MagickWand program I wrote are consistent.
Is there anything I can do to speed this up, or is the PNG writer just slow? Thanks for your insights.
Dave Lange
My test image is a black & white TIFF image from a 200 DPI scan of an 8 1/2 x 11 document (around 1700 x 2200 pixels). The TIFF file is around 20K. We're not talking about something that's very big.
A straight conversion of this image to PNG is consistently taking around 17 seconds. I can convert it to GIF in around three seconds and to JPEG in less than one second. My timings using convert and using a MagickWand program I wrote are consistent.
Is there anything I can do to speed this up, or is the PNG writer just slow? Thanks for your insights.
Dave Lange
Re: Slow TIFF to PNG conversion
Can you post a URL to one or two if your TIFF images? We want to reproduce the problem and then trace the source of any slow down. We'll look for an opportunity to speed up the conversion and post here with our results.
Re: Slow TIFF to PNG conversion
I don't have a way to send a URL. Is there some way I can attach the TIFF, or email it somewhere?
Dave
Dave
Re: Slow TIFF to PNG conversion
One thing you can do is to use a lower "quality"
The downside of this is that, although the conversion is lossless and there
is no difference in the image appearance, the resulting filesize might be larger.
The new PNG encoder (since 6.6.6-6 or so) is somewhat slower because
it examines every pixel to obtain an accurate color count, but that's
probably not the problem here because you only have two colors.
Code: Select all
convert file.gif -quality 20 file.png
is no difference in the image appearance, the resulting filesize might be larger.
The new PNG encoder (since 6.6.6-6 or so) is somewhat slower because
it examines every pixel to obtain an accurate color count, but that's
probably not the problem here because you only have two colors.
Re: Slow TIFF to PNG conversion
@dave, please email me the tiff (glennrp at imagemagick.org). I'm seeing about one
second for a similar-sized monochrome image, using the default PNG quality.
second for a similar-sized monochrome image, using the default PNG quality.
Re: Slow TIFF to PNG conversion
Can you try with an older ImageMagick version?
I found a dramatic performance drop with PNG when going from 6.6.1 to 6.6.6,
see viewtopic.php?f=2&t=17799
I found a dramatic performance drop with PNG when going from 6.6.1 to 6.6.6,
see viewtopic.php?f=2&t=17799
Re: Slow TIFF to PNG conversion
Interesting. Which version of the PNG library is being used in 6.6.1? I currently have PNG 1.4.5 and ImageMagick 6.6.6-10.
Dave
Dave
Re: Slow TIFF to PNG conversion
I tried setting -quality 20 and -quality 10. It inflated the size of the PNG file, but the performance was the same.
I notice that the PNG file is 8-bit, while my input TIFF is 1-bit. Can I force the PNG to be 1-bit as well, and would that possibly improve the performance?
Dave
I notice that the PNG file is 8-bit, while my input TIFF is 1-bit. Can I force the PNG to be 1-bit as well, and would that possibly improve the performance?
Dave
Re: Slow TIFF to PNG conversion
I used libpng 1.4.4 in all tests. It is most probably caused by the extensive refactoring of png.cWhich version of the PNG library is being used in 6.6.1?
since 6.6.2(?).
Regards, Axel.
Re: Slow TIFF to PNG conversion
I have more info to submit. The new png coder is not just slower than before, it also works incorrectly with -fft command, outputting only one image instead of two. Thus, a simple command like now takes significantly longer to process, and outputs only phase image - logo.png, but no magnitude. This wasn't the case in ImageMagick-6.6.5-10, which was faster (1 vs. 7 sec), and I used to get logo-0.png and logo-1.png from the above command.
Now, I can only get it to output two files by specifying logo_%d.png in the end, but the unreasonable slowness persists. What is even more interesting, is that if I actually specify two .png images as input for Inverse Fourier Transform procedure, the computation lasts for minutes, which is totally wrong.
I'm using png.c from 6.6.5-10 version and it seems to be working fine.
Code: Select all
convert logo: -fft logo.png
Now, I can only get it to output two files by specifying logo_%d.png in the end, but the unreasonable slowness persists. What is even more interesting, is that if I actually specify two .png images as input for Inverse Fourier Transform procedure, the computation lasts for minutes, which is totally wrong.
I'm using png.c from 6.6.5-10 version and it seems to be working fine.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Slow TIFF to PNG conversion
I have created a bug report for this at viewtopic.php?f=3&t=17840
Re: Slow TIFF to PNG conversion
Thanks for reporting that.
I have just noticed that even though the 6.6.5-10 png coder is as fast as before on small images, it still takes noticeably longer on large images. As an example, I process a 8834x4000 image with -distort srt 30 command on my C2D@3.33GHz machine. The CPU load goes up 100% for all cores while the actual distortion takes place in memory, then it drops to 50%, creates an empty .png file and, I assume, on this step, starts writting the actual file. Even with the older, thought to be faster, 6.6.5-10 version this process lasts roughly for 50 min (my computer fell asleep during the process for a couple of minutes, but I quickly woke it up, and the process resumed). With 6.6.4-10 version it lasts 8 sec! The time seems to grow in geometric progression as the image size grows:
8834x4000 image - 50 min vs 8 sec
2100x1500 image - 1:53 min vs 1 sec
This is obviously inadequate behaviour, therefore i'm forced to revert back to png.c taken from 6.6.4.10. I understand that recently there has been a lot of fixes for png.c, but these fixes seem to have impacted the speed drastically. I really hope you'll get this sorted out in future releases.
I have just noticed that even though the 6.6.5-10 png coder is as fast as before on small images, it still takes noticeably longer on large images. As an example, I process a 8834x4000 image with -distort srt 30 command on my C2D@3.33GHz machine. The CPU load goes up 100% for all cores while the actual distortion takes place in memory, then it drops to 50%, creates an empty .png file and, I assume, on this step, starts writting the actual file. Even with the older, thought to be faster, 6.6.5-10 version this process lasts roughly for 50 min (my computer fell asleep during the process for a couple of minutes, but I quickly woke it up, and the process resumed). With 6.6.4-10 version it lasts 8 sec! The time seems to grow in geometric progression as the image size grows:
8834x4000 image - 50 min vs 8 sec
2100x1500 image - 1:53 min vs 1 sec
This is obviously inadequate behaviour, therefore i'm forced to revert back to png.c taken from 6.6.4.10. I understand that recently there has been a lot of fixes for png.c, but these fixes seem to have impacted the speed drastically. I really hope you'll get this sorted out in future releases.
Re: Slow TIFF to PNG conversion
I checked again with 6.6.7-3. PNG conversions are back at normal speed.
Regard, Axel.
Regard, Axel.
Re: Slow TIFF to PNG conversion
Thanks for the update, Axel. I'll give it a try.
Dave
Dave
Re: Slow TIFF to PNG conversion
I installed 6.6.7-3, and the TIFF to PNG conversions are indeed much faster - around 2.5 seconds for my 1700x2200 bi-tonal image. Unfortunately, the output image is unusable.
If I view the PNG image with ImageMagick's display command at its native size, it looks fine. But if I try a resize to 850x1100, most of the black pixels are discarded and the result is not readable. (Doing the display with resize on the original TIFF image works fine.) If I copy the PNG image to Windows and view it there, it displays as very light gray text on a white background - again, unreadable.
Suggestions?
Thanks,
Dave
If I view the PNG image with ImageMagick's display command at its native size, it looks fine. But if I try a resize to 850x1100, most of the black pixels are discarded and the result is not readable. (Doing the display with resize on the original TIFF image works fine.) If I copy the PNG image to Windows and view it there, it displays as very light gray text on a white background - again, unreadable.
Suggestions?
Thanks,
Dave