HELP: convert +distor slower than expected

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?".
Post Reply
samio
Posts: 1
Joined: 2012-08-20T04:51:51-07:00
Authentication code: 67789

HELP: convert +distor slower than expected

Post by samio »

Hello,

using IM to perspective distort an image, the output is amazing quality wise but the operation takes about 1 sec on a number of different configurations. I took a look at the debug output and it seems that the cache.c destroy takes the most time. I need your kind help in improving the convert operation.

the debug output is as follows
$ convert img/game-stats.png -debug cache -log "%u %m:%l %e" -matte -virtual-pixel transparent +distort Perspective "0,0 95,258 0,960 95,1218 640,960 607, 1234 640,0 607,334" +repage -format png -interpolate bicubic scratch/test-full.png
2012-08-20T14:49:30+03:00 0:00.000 0.000u 6.7.8 Cache convert[688]: cache.c/DestroyPixelCache/1446/Cache
destroy
2012-08-20T14:49:30+03:00 0:00.000 0.000u 6.7.8 Cache convert[688]: cache.c/OpenPixelCache/4050/Cache
open img/game-stats.png[0] (heap memory, 640x960 4.688MiB)
0.080u cache.c:4050 open img/game-stats.png[0] (heap memory, 514x978 3.835MiB)
0.580u cache.c:1446 destroy img/game-stats.png[0]
0.970u cache.c:1446 destroy img/game-stats.png[0]
Samy-Alzhranis-MacBook:appview samy$ convert img/game-stats.png -debug All -log "%u %m:%l %e" -matte -virtual-pixel transparent +distort Perspective "0,0 95,258 0,960 95,1218 640,960 607, 1234 640,0 607,334" +repage -format png -interpolate bicubic scratch/test-full.png
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: utility.c/ExpandFilenames/939/Configure
Command line: convert {img/game-stats.png} {-debug} {All} {-log} {%u %m:%l %e} {-matte} {-virtual-pixel} {transparent} {+distort} {Perspective} {0,0 95,258 0,960 95,1218 640,960 607, 1234 640,0 607,334} {+repage} {-format} {png} {-interpolate} {bicubic} {scratch/test-full.png}
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/share/ImageMagick-6.7.8/coder.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/lib/ImageMagick-6.7.8/config/coder.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/etc/ImageMagick/coder.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/share/doc/ImageMagick-6.7.8/coder.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/Users/samy/.magick/coder.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: coder.c/LoadCoderList/693/Configure
Loading coder configuration file "/opt/local/etc/ImageMagick/coder.xml" ...
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Module convert[704]: module.c/OpenModule/1264/Module
Searching for module "PNG" using filename "png.la"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Module convert[704]: module.c/GetMagickModulePath/565/Module
Searching for coder module file "png.la" ...
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Module convert[704]: module.c/OpenModule/1273/Module
Opening module at path "/opt/local/lib/ImageMagick-6.7.8/modules-Q16/coders/png.la"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Module convert[704]: module.c/OpenModule/1300/Module
Method "RegisterPNGImage" in module "PNG" at address 0x100acd900
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Module convert[704]: module.c/OpenModule/1314/Module
Method "UnregisterPNGImage" in module "PNG" at address 0x100ad89f0
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Policy convert[704]: policy.c/IsRightsAuthorized/485/Policy
Domain: Path; rights=Read; pattern="img/game-stats.png" ...
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Blob convert[704]: blob.c/OpenBlob/2530/Blob
read 3 magic header bytes
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Cache convert[704]: cache.c/DestroyPixelCache/1446/Cache
destroy
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/share/ImageMagick-6.7.8/magic.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/lib/ImageMagick-6.7.8/config/magic.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/etc/ImageMagick/magic.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/opt/local/share/doc/ImageMagick-6.7.8/magic.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: configure.c/GetConfigureOptions/564/Configure
Searching for configure file: "/Users/samy/.magick/magic.xml"
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Configure convert[704]: magic.c/LoadMagicList/679/Configure
Loading magic configure file "/opt/local/etc/ImageMagick/magic.xml" ...
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Policy convert[704]: policy.c/IsRightsAuthorized/485/Policy
Domain: Coder; rights=Read; pattern="PNG" ...
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadPNGImage/3652/Coder
Enter ReadPNGImage()
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Policy convert[704]: policy.c/IsRightsAuthorized/485/Policy
Domain: Path; rights=Read; pattern="img/game-stats.png" ...
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Blob convert[704]: blob.c/OpenBlob/2530/Blob
read 3 magic header bytes
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2056/Coder
Enter ReadOnePNGImage()
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2079/Coder
image->matte=0
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2258/Coder
PNG width: 640, height: 960
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2262/Coder
PNG color_type: 2, bit_depth: 8
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2266/Coder
PNG compression_method: 0
2012-08-20T14:58:56+03:00 0:00.000 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2270/Coder
PNG interlace_method: 0, filter_method: 0
2012-08-20T14:58:56+03:00 0:00.010 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2840/Coder
Reading PNG IDAT chunk(s)
2012-08-20T14:58:56+03:00 0:00.010 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2855/Coder
Converting PNG pixels to pixel packets
2012-08-20T14:58:56+03:00 0:00.010 0.000u 6.7.8 Resource convert[704]: resource.c/AcquireMagickResource/262/Resource
Area: 4.915MB/4.915MB/4.295GB
2012-08-20T14:58:56+03:00 0:00.010 0.000u 6.7.8 Resource convert[704]: resource.c/AcquireMagickResource/262/Resource
Memory: 4.915MB/4.688MiB/2GiB
2012-08-20T14:58:56+03:00 0:00.010 0.000u 6.7.8 Cache convert[704]: cache.c/OpenPixelCache/4050/Cache
open img/game-stats.png[0] (heap memory, 640x960 4.688MiB)
2012-08-20T14:58:56+03:00 0:00.010 0.000u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/2938/Coder
Looking for cheap transparent pixel
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/3215/Coder
No transparent pixel was found
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/3369/Coder
Reading PNG text chunk
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/3404/Coder
length: 16
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/3406/Coder
Keyword: Software
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadOnePNGImage/3604/Coder
exit ReadOnePNGImage()
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadPNGImage/3730/Coder
page.w: 0, page.h: 0,page.x: 0, page.y: 0.
2012-08-20T14:58:56+03:00 0:00.080 0.080u 6.7.8 Coder convert[704]: png.c/ReadPNGImage/3736/Coder
exit ReadPNGImage()
0.080u resource.c:262 Area: 4.022MB/4.022MB/4.295GB
0.080u resource.c:262 Memory: 4.022MB/8.523MiB/2GiB
0.080u cache.c:4050 open img/game-stats.png[0] (heap memory, 514x978 3.835MiB)
0.570u cache.c:1446 destroy img/game-stats.png[0]
0.570u resource.c:811 Memory: 4.915MB/3.835MiB/2GiB
0.570u policy.c:485 Domain: Coder; rights=Write; pattern="PNG" ...
0.570u png.c:10958 Enter WritePNGImage()
0.570u png.c:7523 Enter WriteOnePNGImage()
0.570u png.c:7683 storage_class=DirectClass
0.570u png.c:7991 Enter BUILD_PALETTE:
0.570u png.c:7996 image->columns=514
0.570u png.c:7998 image->rows=978
0.570u png.c:8000 image->matte=1
0.570u png.c:8002 image->depth=8
0.570u png.c:8038 image->colors=0
0.570u png.c:8042 (zero means unknown)
0.570u png.c:8046 Regenerate the colormap
0.610u png.c:8163 Check colormap for background (65535,65535,65535)
0.610u png.c:8189 No room in the colormap to add background color
0.610u png.c:8205 image has more than 256 colors
0.610u png.c:8403 image->colors=0
0.610u png.c:8427 number_transparent = 1
0.610u png.c:8441 number_opaque > 256
0.610u png.c:8450 number_semitransparent > 256
0.610u png.c:8454 All pixels and the background are black or white
0.610u png.c:8465 Exit BUILD_PALETTE:
0.610u png.c:8835 Cheap transparency is not possible.
0.610u png.c:8974 width=514
0.610u png.c:8976 height=978
0.610u png.c:8978 image_matte=1
0.610u png.c:8980 image->depth=8
0.610u png.c:8982 Tentative ping_bit_depth=8
0.610u png.c:8997 Setting up pHYs chunk
0.610u png.c:9024 Set up PNG pHYs chunk: xres: 72, yres: 72, units: 0.
0.610u png.c:9067 Setting up bKGD chunk (1)
0.610u png.c:9069 background_color index is 0
0.610u png.c:9073 ping_bit_depth=8
0.610u png.c:9204 Selecting PNG colortype:
0.610u png.c:9263 Selected PNG colortype=6
0.610u png.c:9299 Number of colors: 0
0.610u png.c:9302 Tentative PNG bit depth: 8
0.610u png.c:9314 Tentative PNG color type: RGB+Alpha (6)
0.610u png.c:9319 image_info->type: 0
0.610u png.c:9322 image_depth: 8
0.610u png.c:9325 image->depth: 8
0.610u png.c:9329 ping_bit_depth: 8
0.610u png.c:9745 PNG color type: RGB+Alpha (6)
0.610u png.c:9753 Setting up deflate compression
0.610u png.c:9756 Compression buffer size: 32768
0.610u png.c:9763 Compression mem level: 9
0.610u png.c:9843 Compression level: 7
0.610u png.c:9852 Setting up filtering
0.610u png.c:9856 Base filter method: ADAPTIVE
0.610u png.c:9971 Setting up sRGB chunk
0.610u png.c:9994 Setting up gAMA chunk
0.610u png.c:10022 Setting up cHRM chunk
0.610u png.c:10114 Writing PNG header chunks
0.610u png.c:10157 Setting up bKGD chunk
0.610u png.c:10159 background color = (255,255,255)
0.610u png.c:10164 index = 0, gray=255
0.610u png.c:10183 Setting up pHYs chunk
0.610u png.c:10185 x_resolution=72
0.610u png.c:10188 y_resolution=72
0.610u png.c:10191 unit_type=0
0.610u policy.c:485 Domain: Path; rights=Write; pattern="scratch/test-full.png" ...
0.610u png.c:10319 Writing PNG image data
0.610u png.c:10322 Allocating 2056 bytes of memory for pixels
0.610u png.c:10522 Writing row of pixels (3)
0.960u png.c:10610 Wrote PNG image data
0.960u png.c:10613 Width: 514
0.960u png.c:10616 Height: 978
0.960u png.c:10625 PNG bit-depth written: 8
0.960u png.c:10634 PNG color-type written: 6
0.960u png.c:10637 PNG Interlace method: 0
0.960u png.c:10689 Setting up text chunk
0.960u png.c:10692 keyword: date:create
0.960u png.c:10689 Setting up text chunk
0.960u png.c:10692 keyword: date:modify
0.960u png.c:10689 Setting up text chunk
0.960u png.c:10692 keyword: Software
0.960u png.c:10708 Writing PNG end info
0.960u png.c:10770 exit WriteOnePNGImage()
0.960u png.c:11621 exit WritePNGImage()
0.960u cache.c:1446 destroy img/game-stats.png[0]
0.960u resource.c:811 Memory: 4.022MB/0B/2GiB
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: HELP: convert +distor slower than expected

Post by anthony »

Distory perspective can become slow in some situations, this is the result of the EWA filter merging large numbers of pixels to generate near 'perfect' color for each pixel.

Setting interpolate does nothing if you set it AFTER the operator.
It also does nothing unless you turn of EWA filters using -filter point.


Basically if you want to understand what is going on, read the introductory sections of Image Distortions.
http://www.imagemagick.org/Usage/distort/
And especially... Area vs SuperSampling (which is still better than interpolated sampling)
http://www.imagemagick.org/Usage/distor ... a_vs_super

For turning of EWA see... EWA Resampling and Filters
http://www.imagemagick.org/Usage/distorts/#distort_ewa
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply