Page 1 of 1

Resizing and cropping one image multiple times in one comman

Posted: 2013-06-17T02:49:44-07:00
by blindcoder
Hello.

I have another question about using a single command for multiple operations:
I want to crop an image into tiles, then resize that image, then crop the result again. Right now I have this code:

Code: Select all

convert -monitor ../output.jpg \
-write mpr:output \
\( mpr:output -crop 256x256 -set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" output_files/14/%[filename:tile].jpg \) \
\( mpr:output -resize 50% -write mpr:output \) \
\( mpr:output -crop 256x256 -set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" output_files/13/%[filename:tile].jpg \)
At the end of the command I get the following error message:

Code: Select all

convert: unable to open image `output_files/14/%[filename:tile].jpg':  @ error/blob.c/OpenBlob/2587.
convert: unable to open image `output_files/13/%[filename:tile].jpg':  @ error/blob.c/OpenBlob/2587.
convert: unbalanced parenthesis `)' @ error/convert.c/ConvertImageCommand/3007.
I don't understand either of those error messages. Shouldn't %[filename:tile] be replaced by "0_0" "0_1" etc and the result of the crop be saved to disk? No output files are generated at all.
Also, there are three opening and three closing brackets, so how can they be unbalanced?

Kind regards,
Benjamin

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T05:01:35-07:00
by Bonzo
What platform are you running this on?

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T05:03:54-07:00
by snibgo
Does output_files/14/%[filename:tile].jpg exist before you run the command? If it doesn't, the command will fail, because you have asked to read it. Perhaps you wanted to write it; use "-write".

A convert command should never end in a close bracket. It should end with an output filename. If you want to discard the result, use "NULL:".

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T05:08:59-07:00
by blindcoder
I'm running this on Ubuntu 12.04 with IM 6.6.9-7 2013-06-09 Q8

Maybe I asked it to read it, but I did not mean to do that. I meant for convert to write cropped tiles of 256x256 px to 0_0.jpg 0_1.jpg etc. Like it would with:

Code: Select all

convert -monitor ../output.jpg -crop 256x256 -set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" output_files/14/%[filename:tile].jpg
Adding NULL: to the end gets rid of the "unbalanced parenthesis" error, but still does not output any files in output_files/{13,14}.

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T06:06:26-07:00
by snibgo
The basic syntax of the convert command is:

Code: Select all

convert {input_file} {processing} {output_file}
If you want to write in other places, you need the "-write" command. As you did for the mpr outputs.

SOLVED: Resizing and cropping one image multiple times in on

Posted: 2013-06-17T06:15:08-07:00
by blindcoder
snibgo wrote:The basic syntax of the convert command is:

Code: Select all

convert {input_file} {processing} {output_file}
If you want to write in other places, you need the "-write" command. As you did for the mpr outputs.
Not sure if you meant to say this, but with this hint I managed to get it working like this:

Code: Select all

convert -monitor ../output.jpg \
-write mpr:output \
\( mpr:output -crop 256x256 -set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" -write output_files/14/%[filename:tile].jpg \) \
\( mpr:output -resize 50% -write mpr:output \) \
\( mpr:output -crop 256x256 -set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" -write output_files/13/%[filename:tile].jpg \)

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T06:21:49-07:00
by snibgo
Yes, that's it. However, you don't have a final output file, so you should add "NULL:" to the end. Alternatively, change your last line to remove the parentheses and "-write".

After your resize, you are writing the mpr then immediately reading it again. This is superfluous.

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T06:27:33-07:00
by blindcoder
snibgo wrote:Yes, that's it. However, you don't have a final output file, so you should add "NULL:" to the end. Alternatively, change your last line to remove the parentheses and "-write".

After your resize, you are writing the mpr then immediately reading it again. This is superfluous.
Ah, yes, I forgot to post the NULL:, the laptop I'm running convert on is not the same as the one I'm posting from.
I don't understand your second sentence, though. I thought I need to store the resized image somewhere?
I'm repeating this for /12, /11, /10, ..., /0 so I'm scaling the image down 14 times and each time I -crop the resulting, resized image.

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T07:02:01-07:00
by snibgo
The sequence ...

Code: Select all

-resize 50% -write mpr:output \) \
\( mpr:output -crop 256x256
... can be replaced with ...

Code: Select all

-resize 50% -crop 256x256

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T07:07:47-07:00
by blindcoder
snibgo wrote:The sequence ...

Code: Select all

-resize 50% -write mpr:output \) \
\( mpr:output -crop 256x256
... can be replaced with ...

Code: Select all

-resize 50% -crop 256x256
But only for the last one, right? Or is it automatically written back to mpr:output?

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T07:55:26-07:00
by snibgo
The replacement code I showed will work for the command you posted. Nothing is automatically written to mpr:output.

Re: Resizing and cropping one image multiple times in one co

Posted: 2013-06-17T09:11:47-07:00
by snibgo
And you start off by writing to mpr:output then reading it. I can see you are reading that same image again before the resize, but then overwrite it before reading it again.

I suspect "clone" would be useful here, to simplify the command, use less memory and perhaps speed it up. If you post the entire command, perhaps I can advise further.