How to reduce the time taken by MagickWand methods

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

How to reduce the time taken by MagickWand methods

Post by ArunKumar »

I'm using MagickWand methods to resize image
MagickResizeImage() ,MagickReadImage() taking more time for larger Images.
Is there any way to reduce the time taken ?
Last edited by ArunKumar on 2020-04-28T02:15:16-07:00, edited 1 time in total.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

Want more performance from ImageMagick? Try these options:
If these options are prohibitive, you can reduce the quality of the image results. The default build is Q16 HDRI. If you disable https://imagemagick.org/script/high-dynamic-range.php, you use half the memory and instead of predominately floating point operations, you use the typically more efficient integer operations. The tradeoff is reduced precision and you cannot process out of range pixel values (e.g. negative). If you build the Q8 non-HDRI version of ImageMagick, you again reduce the memory requirements in half-- and once again there is a tradeoff, even less precision and no out of range pixel values. For a Q8 non-HDRI build of ImageMagick, use these configure script options: --with-quantum-depth=8 --disable-hdri.

In the case of image resizing, you can sample the image with MagickSampleImage() rather than with MagickResizeImage().

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

Thanks ..I sampled the image with MagickSampleImage() rather than with MagickResizeImage().
It reduced time .
But MagickReadImage() method taking more time to read the image .
Is there any way to reduce the time taken by the MagickReadImage().

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

Sure, read the links we provided. Its possible your image exceeds the memory resource limits of your host computer, or exceeds memory limits provided in your security policy, so its cached to disk. Disk access is much slower than memory access. If you provide a link to one of the images that is under-performing, we can review it to verify our assertion.

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

If you provide a link to one of the images that is under-performing, we can review it to verify our assertion.
Thanks

It taking more time to process the large image
Last edited by ArunKumar on 2020-04-28T02:15:51-07:00, edited 1 time in total.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

Set MAGICK_DEBUG:

Code: Select all

export MAGICK_DEBUG=cache
It will show you if your image is cached to disk.

Your image is 21600x21600 pixels. On our system, it was read and resized all in memory. We get these results:

Code: Select all

The program took 5.060282 seconds to read , 0.377161 seconds to resize , 0.299128 seconds to write , 5.738869 seconds for total execution
A portion of the read and write time consumption is attributed to decompression of the JPEG image and then compression of the PNG image. To eliminate the compression time, we tried this:

Code: Select all

$ convert image3.jpg image3.mpc
$ sample image3.mpc image3.pnm
The program took 0.001284 seconds to read , 0.243560 seconds to resize , 0.014884 seconds to write , 0.261686 seconds for total execution

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

A portion of the read and write time consumption is attributed to decompression of the JPEG image and then compression of the PNG image. To eliminate the compression time, we tried this:
CODE:
$ convert image3.jpg image3.mpc
$ sample image3.mpc image3.pnm
The program took 0.001284 seconds to read , 0.243560 seconds to resize , 0.014884 seconds to write , 0.261686 seconds for total execution
Can you give me the code that give the above result or what should I update on my code to get the above result

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

The workflow was to illustrate that the majority of the time is consumed by the JPEG and PNG delegate libraries for decompression/compression rather than ImageMagick. Both MPC and PNM image formats do not require compression. The MAGICK_DEBUG define was for you to determine if your image is processed in memory or on disk. Pixel processing on disk and compression/decompression are performance hits and the source of the majority of any performance issue you have with your program.

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

When the decompression/compression is taking place ?
During reading or writing ?

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

Decompression is required to read a JPEG or PNG image. Compression takes place when writing a JPEG or PNG image.

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

In the case of image resizing, you can sample the image with MagickSampleImage() rather than with MagickResizeImage().
But using MagickSampleImage() lead to loss of the Quality Image.
I need to resize the image without loss of Quality with less time
Any Way ?

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

For the best quality, use MagickResizeImage(). You can get quality and some performance increase with MagickScaleImage(). ImageMagick will automatically choose between resize, scale, and sample with MagickThumbnailImage().

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

export MAGICK_DEBUG=cache
It will show you if your image is cached to disk.
Yeah I'm getting something .But how to debug whether the image is readed & resized in memoy?

How to dubug the output of cache result ?

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: How to reduce the time taken by MagickWand methods

Post by magick »

If the debugging mentions heap, its processing in memory. If it mentions disk, its processing the image on disk.

ArunKumar
Posts: 59
Joined: 2020-03-05T00:12:15-07:00
Authentication code: 1152

Re: How to reduce the time taken by MagickWand methods

Post by ArunKumar »

magick wrote:
2020-04-11T11:16:51-07:00
If the debugging mentions heap, its processing in memory. If it mentions disk, its processing the image on disk.
It mention Heap during debugging .Since it take nearly 20 seconds to resize the 80MB JPEG image 8 seconds to read and 12 seconds to resize

I use MagickResizeImage() method to resize the image
Since MagickResizeImage() will give a high Quality Image than other resize Method . so it take
Why MagickReadImage() method take more time to read the high size image ..
Any Way to reduce the Time Taken by MagickReadImage() to read image without loss of Quality of image

Locked