Slow TIFF to PNG conversion

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
dwlange
Posts: 7
Joined: 2011-01-12T08:13:01-07:00
Authentication code: 8675308

Slow TIFF to PNG conversion

Post by dwlange »

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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Slow TIFF to PNG conversion

Post by magick »

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.
dwlange
Posts: 7
Joined: 2011-01-12T08:13:01-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by dwlange »

I don't have a way to send a URL. Is there some way I can attach the TIFF, or email it somewhere?

Dave
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Slow TIFF to PNG conversion

Post by glennrp »

One thing you can do is to use a lower "quality"

Code: Select all

 convert file.gif -quality 20 file.png
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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Slow TIFF to PNG conversion

Post by glennrp »

@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.
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: Slow TIFF to PNG conversion

Post by axelrose »

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
dwlange
Posts: 7
Joined: 2011-01-12T08:13:01-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by dwlange »

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
dwlange
Posts: 7
Joined: 2011-01-12T08:13:01-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by dwlange »

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
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: Slow TIFF to PNG conversion

Post by axelrose »

Which version of the PNG library is being used in 6.6.1?
I used libpng 1.4.4 in all tests. It is most probably caused by the extensive refactoring of png.c
since 6.6.2(?).

Regards, Axel.
bobo
Posts: 2
Joined: 2011-01-14T15:54:24-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by bobo »

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

Code: Select all

convert logo: -fft logo.png
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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Slow TIFF to PNG conversion

Post by fmw42 »

I have created a bug report for this at viewtopic.php?f=3&t=17840
bobo
Posts: 2
Joined: 2011-01-14T15:54:24-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by bobo »

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.
axelrose
Posts: 96
Joined: 2008-12-16T06:01:27-07:00

Re: Slow TIFF to PNG conversion

Post by axelrose »

I checked again with 6.6.7-3. PNG conversions are back at normal speed.

Regard, Axel.
dwlange
Posts: 7
Joined: 2011-01-12T08:13:01-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by dwlange »

Thanks for the update, Axel. I'll give it a try.

Dave
dwlange
Posts: 7
Joined: 2011-01-12T08:13:01-07:00
Authentication code: 8675308

Re: Slow TIFF to PNG conversion

Post by dwlange »

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
Post Reply