composite help, need help with performance and shortening

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
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

composite help, need help with performance and shortening

Post by gotskill10 »

IM Version: 6.3.5

I have a relatively simple application of ImageMagick. I'm using it to take one image, and tile it on a large canvas while mirroring the image on the edges.
The entire time, Im only working with one image, but Im loading it into memory each time and calling functions that have already been called.

Can anyone help me take this down from 18 seconds in execution time? I've looked through the documentation and haven't been able to find anything.

convert -size 4320x4320 xc:white \
\( ./assets/bg.jpg -flop -geometry 3888x3888-3672+216 \) -composite \
\( ./assets/bg.jpg -flop -geometry 3888x3888+4104+216 \) -composite \
\( ./assets/bg.jpg -flip -geometry 3888x3888+216-3672 \) -composite \
\( ./assets/bg.jpg -flip -geometry 3888x3888+216+4104 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888-3672-3672 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888+4104-3672 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888-3672+4104 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888+4104+4104 \) -composite \
./assets/bg.jpg -geometry 3888x3888+216+216 -composite \
./assets/tiled_bg.jpg

What could this simplify to?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: composite help, need help with performance and shortening

Post by Bonzo »

Does this have any effect ?

Code: Select all

convert -size 4320x4320 xc:white ./assets/bg.jpg -write mpr:image +delete \ 
\( mpr:image -flop -geometry 3888x3888-3672+216 \) -composite \ 
\( mpr:image  -flop -geometry 3888x3888+4104+216 \) -composite \ 
\( mpr:image  -flip -geometry 3888x3888+216-3672 \) -composite \ 
\( mpr:image  -flip -geometry 3888x3888+216+4104 \) -composite \ 
\( mpr:image  -flip -flop -geometry 3888x3888-3672-3672 \) -composite \ 
\( mpr:image  -flip -flop -geometry 3888x3888+4104-3672 \) -composite \ 
\( mpr:image  -flip -flop -geometry 3888x3888-3672+4104 \) -composite \ 
\( mpr:image  -flip -flop -geometry 3888x3888+4104+4104 \) -composite \ 
mpr:image  -geometry 3888x3888+216+216 -composite \ 
./assets/tiled_bg.jpg
I have not tested it; if it does not work try changing the first line:

Code: Select all

convert ./assets/bg.jpg -write mpr:image +delete -size 4320x4320 xc:white \ 
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: composite help, need help with performance and shortening

Post by el_supremo »

I've modified Bonzo's idea to use more temporary images so that fewer flips and flops are done which should save some time.
I haven't tested it but it should work.

Code: Select all

convert -size 4320x4320 xc:white \
\( ./assets/bg.jpg -write mpr:image -flop -write mpr:flop -geometry 3888x3888-3672+216 \) -composite \
\( mpr:flop -geometry 3888x3888+4104+216 \) -composite \
\( mpr:image  -flip -write mpr:flip -geometry 3888x3888+216-3672 \) -composite \
\( mpr:flip -geometry 3888x3888+216+4104 \) -composite \
\( mpr:flip -flop -write mpr:flipflop -geometry 3888x3888-3672-3672 \) -composite \
\( mpr:flipflop -geometry 3888x3888+4104-3672 \) -composite \
\( mpr:flipflop -geometry 3888x3888-3672+4104 \) -composite \
\( mpr:flipflop -geometry 3888x3888+4104+4104 \) -composite \
mpr:image  -geometry 3888x3888+216+216 -composite \
./assets/tiled_bg.jpg
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: composite help, need help with performance and shortening

Post by anthony »

As you are wanting a 'mirror tile' effect there is a vert tricky method that should be very fast...

Im have somethng calls 'virtual pixels' which define what pixel should be returned when you 'lookup' an image but MISS the actual image.
http://www.imagemagick.org/Usage/misc/#virtual

The new 'distort' function can 'lookup' an image and its surrounding virtual pixel 'space' without actually distorting the image (no-op).
http://www.imagemagick.org/Usage/distor ... rt_options

Also it has a special option that lets you create a larger 'view' of the distorting 'space' using a 'viewport' setting
http://www.imagemagick.org/Usage/distor ... t_viewport

so given your image, lets mirror tile it into a large area!

Code: Select all

convert   ./assets/bg.jpg  -set viewport 4320x4320+0+0 \
       -virtual-pixel Mirror  -distort SRT 0  +repage tiled_bg.jpg
Now is't that a lot better than all those flips and flops!!!!!

Of course you can distort the images too.. See Affine Tiling
http://www.imagemagick.org/Usage/distorts/#affine_tile

As a bonus this can work for multiple images simultaneously.
A feature that was put to good use to so a simple tile of an animations, specifically glitter tiles...
http://www.imagemagick.org/Usage/anim_m ... tter_tiles
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite help, need help with performance and shortening

Post by fmw42 »

gotskill10 wrote:IM Version: 6.3.5

I have a relatively simple application of ImageMagick. I'm using it to take one image, and tile it on a large canvas while mirroring the image on the edges.
The entire time, Im only working with one image, but Im loading it into memory each time and calling functions that have already been called.

Can anyone help me take this down from 18 seconds in execution time? I've looked through the documentation and haven't been able to find anything.

convert -size 4320x4320 xc:white \
\( ./assets/bg.jpg -flop -geometry 3888x3888-3672+216 \) -composite \
\( ./assets/bg.jpg -flop -geometry 3888x3888+4104+216 \) -composite \
\( ./assets/bg.jpg -flip -geometry 3888x3888+216-3672 \) -composite \
\( ./assets/bg.jpg -flip -geometry 3888x3888+216+4104 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888-3672-3672 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888+4104-3672 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888-3672+4104 \) -composite \
\( ./assets/bg.jpg -flip -flop -geometry 3888x3888+4104+4104 \) -composite \
./assets/bg.jpg -geometry 3888x3888+216+216 -composite \
./assets/tiled_bg.jpg

What could this simplify to?
I don't know if this is exactly what you are trying to do as you have not provided an input and output image, but you may want to look at my tidbits on unfolding and mirror tiling at:

http://www.fmwconcepts.com/imagemagick/ ... php#unfold
http://www.fmwconcepts.com/imagemagick/ ... php#mirror

(credit to Anthony for most of these methods)
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: composite help, need help with performance and shortening

Post by gotskill10 »

I was able to complete my task with this:

http://www.fmwconcepts.com/imagemagick/ ... php#unfold

Its taking me 13 seconds instead of 18. Thanks for all your help guys.
Post Reply