Page 1 of 1

Using Stream as a Batch Tool

Posted: 2015-07-27T08:10:15-07:00
by BenSande
I'm trying to use stream to produce a file of the greyscale data for each of a large number of .bmp files. Based on the batch syntax of convert, I tried

Code: Select all

stream -map i -storage-type short *.bmp *.raw 
which did not work. I get one file titled *.raw, which seems to be the data from just the first file. I've tried a few variations on the asterisks, but got error messages, and am quite puzzled. This command gives me exactly the output I want when applied to one file at a time, but I have a dataset of 831 files! Is there a way to do this as a batch operation?

I am using ImageMagick 6.8.9-9 Q16 in Ubuntu.

Re: Using Stream as a Batch Tool

Posted: 2015-07-27T09:56:52-07:00
by fmw42
Try mogrify rather than stream for processing of each file in a folder. I do not know stream, so cannot comment about that.

Re: Using Stream as a Batch Tool

Posted: 2015-07-28T01:41:37-07:00
by BenSande
Mogrify doesn't have the ability to stream to a binary short storage file, which is what I really need. Neither does convert, otherwise I would be using that. The -map and -storage-type tools are stream only.

I have found a workaround to this problem using for loops, but if anyone knows of a slicker way to make stream work for batches I would still be very interested.

Re: Using Stream as a Batch Tool

Posted: 2015-07-28T20:37:26-07:00
by 246246
BenSande wrote:Mogrify doesn't have the ability to stream to a binary short storage file, which is what I really need. Neither does convert, otherwise I would be using that. The -map and -storage-type tools are stream only.
In your case, if I understand correctly,

Code: Select all

convert -depth 16 file.bmp GRAY:file.raw
will do the same thing. (mogrify has same ability so

Code: Select all

mogrify -depth 16 -format gray -- *.bmp
would work but it does not have the ability to change file name. So you get filename.gray instead, and have to rename it later.
Recommended to read http://www.imagemagick.org/Usage/basics/#mogrify_not)
BenSande wrote:I get one file titled *.raw, which seems to be the data from just the first file. I've tried a few variations on the asterisks, but got error messages, and am quite puzzled.
Expanding * is a work of shell, not a ImageMagick, so even

Code: Select all

convert *.bmp *.png
would not work as you expected. Suppose you have only .bmp files, say 1.bmp 2.bmp, in your current directory, Imagemagick received
"convert" "1.bmp" "2.bmp" "*.png"
You can check it using -debug 'Configure'

Code: Select all

$ convert -debug 'Configure' *.bmp *.png 2>&1| head
2015-07-29T11:22:45+09:00 0:00.009 0.015u 6.9.1 Configure convert[3464]: utility.c/ExpandFilenames/936/Configure
  Command line: convert {-debug} {Configure} {1.bmp} {2.bmp} {*.png}
then *-0.png and *-1.png are created automagically (as PNG doesn't support multi page format.)

So '-set filename' trick may work for convert. Try

Code: Select all

convert *.bmp -depth 16 -set filename:f '%t' +adjoin GRAY:'%[filename:f].raw'
But still, I think for loop with stream is best answer as long as you use unix. It is easier to understand and there is no reason for loop is not suitable for batch.

Re: Using Stream as a Batch Tool

Posted: 2015-07-28T22:09:35-07:00
by fmw42
Wildcard output does not work the way you would like. For every input you can only have one output image name, but you can append image numbers to that one name using %d.

convert *.jpg <some processing> output.jpg

will make

output-0.jpg, output-1.jpg ... output-N.jpg

I assume stream is limited the same way. Only mogrify, to my knowledge, will process one output with the same name as each input.

However, I am not an expert at the use of stream.