Using Stream as a Batch Tool

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
BenSande
Posts: 2
Joined: 2015-07-27T07:59:46-07:00
Authentication code: 1151

Using Stream as a Batch Tool

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using Stream as a Batch Tool

Post 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.
BenSande
Posts: 2
Joined: 2015-07-27T07:59:46-07:00
Authentication code: 1151

Re: Using Stream as a Batch Tool

Post 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.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Using Stream as a Batch Tool

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using Stream as a Batch Tool

Post 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.
Post Reply