Page 1 of 1

"-set" or "%[fx...]" taking very long time

Posted: 2010-06-18T18:35:48-07:00
by snibgo
On Windows 7, IM 6.6.2-3, create a source image:

Code: Select all

convert -size 3200x3200 xc:red red.png
The following takes a reasonable 1 minute to create the 10,000 files:

Code: Select all

convert ^
  red.png ^
  -crop 32x32 ^
  +repage +adjoin ^
  x.png
But if we add one line, in preparation for a row_column output name:

Code: Select all

convert ^
  red.png ^
  -crop 32x32 ^
  -set filename:tile "%%[fx:page.x/32]_%%[fx:page.y/32]" ^
  +repage +adjoin ^
  x.png
Now the time increases to about 1 minute per output file, for a total time of 7 days. (One dual-core CPU is saturated, the other is idle. There is negligible memory use or disk activity.)

Am I doing something stupid, or is there a bug in "-set" or "%[fx...]"?

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-18T18:49:54-07:00
by fmw42
On my Mac OSX Tiger G4 single processor and IM 6.6.2-7 Q16 beta


convert -size 128x128 xc:red red.png

time convert \
red.png \
-crop 32x32 \
-set filename:tile "%[fx:page.x/32]_%[fx:page.y/32]" \
+repage +adjoin \
x.png

creates 16 tiles in:

real 0m0.666s
user 0m0.217s
sys 0m0.145s

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-18T18:53:13-07:00
by snibgo
Thanks. Can you repeat the test with "-size 3200x3200"?

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T09:17:30-07:00
by snibgo
[Responding to a post, now vanished, from magick explaining that this isn't a bug but %[fx: ] is evaluated for every pixel.]

Thanks, that makes sense.

In a few places, the documentation says, "For use with -format, the value-escape %[fx: ] is evaluated just once for each image in the current image sequence." I suggest this is expanded: "When used with -set, value-escape %[fx: ] is evaluated once for every pixel."

The "Cutting and Bordering examples" page http://www.imagemagick.org/Usage/crop/#crop_tile could also be modified.

As a possible future enhancement, a facility for doing calulations once per image might be useful.

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T09:42:07-07:00
by magick
Your expression is evaluated over 70k times. Since FX expressions are interpreted, it can be quite slow. We added fxc: in ImageMagick 6.6.2-7 Beta, available by sometime tomorrow. Here an fxc: expression is evaluated just once and cached. The next call returns the cached result rather than reevaluating the expression. Your command is quite fast when using fxc:page.x/32 rather than fx:page.x/32.

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T12:19:07-07:00
by snibgo
Thanks for the speedy response. I can't currently compile. Someone else may test it.

Thanks again.

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T14:13:35-07:00
by fmw42
snibgo wrote:Thanks for the speedy response. I can't currently compile. Someone else may test it.

Thanks again.
Alan,

I can test it once the beta is available. I am downloading whatever is the current version of the beta now. We will see if it has the change.

Fred

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T14:47:30-07:00
by fmw42
OK. It seems to be in the new beta.


time convert \
red.png \
-crop 32x32 \
-set filename:tile "%[fxc:page.x/32]_%[fxc:page.y/32]" \
+repage +adjoin \
x.png

create 1024 image in:


real 0m9.612s
user 0m4.265s
sys 0m3.908s


Fred

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T16:20:29-07:00
by snibgo
Thanks Fred. Good stuff. It's still slow, but we are now talking minutes rather than days.

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T16:24:54-07:00
by fmw42
snibgo wrote:Thanks Fred. Good stuff. It's still slow, but we are now talking minutes rather than days.
My test was 9 sec not 9 minutes.

Fred

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-19T16:57:44-07:00
by snibgo
Yes, 9.6 seconds for 1024 files, so 94 seconds (1.5 minutes) for the 10,000 files we would get from a 3200x3200 source. This may not be significantly slower than we were getting without the "-set filemame fx" option

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-20T19:55:35-07:00
by anthony
snibgo wrote:In a few places, the documentation says, "For use with -format, the value-escape %[fx: ] is evaluated just once for each image in the current image sequence." I suggest this is expanded: "When used with -set, value-escape %[fx: ] is evaluated once for every pixel
The %[fx:] should be just once only for each image with i,j set to 0 and just the red channel used. That is how it was defined.

However their are some fx options that may require some identify settings, that could need to process all the pixels.
Specifically getting the min, max, and mean values of a image. However if it is implemented right it should only need to do that once only, and ONLY if requested.

A %[pixel:] on the other hand is supposed to do just one value with all color channels.

Only the -fx is suposed to process every pixel, over the specified -channel range (though there was talk of allowing it to use -region to limit how many pixels should be looked at.

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-20T20:01:54-07:00
by anthony
magick wrote:Your expression is evaluated over 70k times. Since FX expressions are interpreted, it can be quite slow. We added fxc: in ImageMagick 6.6.2-7 Beta, available by sometime tomorrow. Here an fxc: expression is evaluated just once and cached. The next call returns the cached result rather than reevaluating the expression. Your command is quite fast when using fxc:page.x/32 rather than fx:page.x/32.

As I mentioned the original defintion of %[fx:] percent escape when it was first created was for just one fx evaluation per image.
Why is it not doing this?

Only -fx was suposed to iterate over all values.

As such I suggest the new %[fxc:] should really be the default %[fx:].

Re: "-set" or "%[fx...]" taking very long time

Posted: 2010-06-21T05:25:50-07:00
by magick
We had code that stopped fx: from checking the property cache. We assume for a reason but we changed the algorithm to check the cache first as you suggested. Let us know if it broken anything.