Page 1 of 1
Referring to the filename with %t makes my code slow?
Posted: 2014-03-16T13:36:02-07:00
by jack-mann
I found out that this code is about 60% slower:
Code: Select all
convert image_*.png -background white -gravity center -extent 20400x -crop 400x400 -set "filename:data" "%t_%[fx:page.x/400]" +repage +adjoin "cropped_%[filename:data].png"
than using a loop (pseudo code):
Code: Select all
for (y=0;y < 34;y++)
{
convert image_{y}.png -background white -gravity center -extent 20400x -crop 400x400 -set "filename:data" "%[fx:page.x/400]" +repage +adjoin "cropped_{y}_%[filename:data].png"
}
The reason seems to be in the first case I reference with %t the input image name.
How can this be?
Re: Referring to the filename with %t makes my code slow?
Posted: 2014-03-16T13:47:18-07:00
by fmw42
try adding -ping, so that IM reads only the meta data and not the full image.
convert
-ping image_*.png -background white -gravity center -extent 20400x -crop 400x400 -set "filename:data" "%t_%[fx:page.x/400]" +repage +adjoin "cropped_%[filename:data].png"
see
http://www.imagemagick.org/Usage/basics/#controls
Re: Referring to the filename with %t makes my code slow?
Posted: 2014-03-16T14:11:49-07:00
by jack-mann
ping does not help.. also all cropped images are all black now....
Re: Referring to the filename with %t makes my code slow?
Posted: 2014-03-16T15:46:55-07:00
by fmw42
Sorry about the -ping. Bad suggestion.
Without the external loop, I think IM convert will try to read all the images into memory and process them all, thus doubling or tripling the memory usage. You may be running out of memory and thus IM using disk space to supplement. With the loop, it will only read one image, process it and then write it, so the memory requirements are much smaller.
Re: Referring to the filename with %t makes my code slow?
Posted: 2014-03-16T22:43:34-07:00
by jack-mann
I would also assume that the second cmd is first putting all input images in memory.
there is probably no way to hint the first command to behave memory-wise like the second for loop command?
Since of a stream pipeline?
Re: Referring to the filename with %t makes my code slow?
Posted: 2014-03-16T22:53:24-07:00
by fmw42
I would also assume that the second cmd is first putting all input images in memory.
No, then second command with the loop only processes one image at a time and thus only one image in memory at a time (plus any intermediates needed for processing and the output). I think the first command tries to read all the images first before processing each one.