Page 1 of 1

Help consolidate everything to then 'glob' batch-process (Windows)

Posted: 2018-11-03T09:50:02-07:00
by LDAsh
I feel terrible to beg for help, but I've been bashing my head against a wall long enough now...
(Version: ImageMagick 6.9.0-1 Q16 x86 2014-12-22)
I'm trying to turn this BAT file into something that can be 1 line and so be able to *.* batch-process a large amount of files.
The reason for splitting it up this way is so I have an output image for each command to inspect and tweak.
_________________________________________

convert _.png -filter Point -resize 300%%x300%% png32:_2(tmp).png
convert _2(tmp).png -alpha deactivate -median 0x3 -despeckle png32:_3(tmp).png
convert _3(tmp).png -roll +1+1 _4(tmp).png
convert _4(tmp).png -gaussian-blur 2x2 _5(tmp).png
convert _5(tmp).png -filter Mitchell -resize 66.666666%%x66.666666%% _6(tmp).png
convert _6(tmp).png -sharpen 3x9 -sharpen 2x9 -sharpen 1x3 _7(tmp).png
convert _7(tmp).png -separate -seed 666 -attenuate 0.08 +noise gaussian -combine -colorspace sRGB _8(tmp).png
convert _8(tmp).png -brightness-contrast -0x-1 -black-threshold 0.4%% _(out).png
_________________________________________

So instead of beginning specifically with "_.png" and ending with "_(out).png", I'm looking instead to "*.png" and "*(out).png" so it would do everything in a folder.
I've been over this page several times - https://imagemagick.org/script/command- ... essing.php
...and I've tried a number of different approaches, but I always get errors and/or unfinished processing if I even get an output at all, so forgive me for not posting what I've already tried but there are a bunch of them now. Simply adding a * to every filename here does not work.

If anyone would be kind enough to help, that would be great!
.
.
.

Re: Help consolidate everything to then 'glob' batch-process (Windows)

Posted: 2018-11-03T10:41:16-07:00
by fmw42
You can concatenate each command without saving the temp output. Then I would suggest you use mogrify to process all file in a given folder. ImageMagick does not allow wild cards for both input and output in most cases. There are ways to do that but it means holding all images in memory at the same time. Mogrify works one image at a time.

Try this for one image

Code: Select all

convert image.png -filter Point -resize 300%%x300%% ^
-alpha deactivate -median 0x3 -despeckle ^
-roll +1+1 ^
-gaussian-blur 2x2 ^
-filter Mitchell -resize 66.666666%%x66.666666%% ^
-sharpen 3x9 -sharpen 2x9 -sharpen 1x3 ^
-separate -seed 666 -attenuate 0.08 +noise gaussian -combine -colorspace sRGB ^
-brightness-contrast -0x-1 -black-threshold 0.4%% result.png
If that works then see mogrify at https://imagemagick.org/Usage/basics/#mogrify. But I suggest you create a new directory first to hold the output using -path argument so that you do not overwrite your input with bad results. Or save a copy of your input directory.


# create new directory to hold the output
# change directory to the one holding your input images

Code: Select all

mogrify -format png -path path/to/new_directory ^
-filter Point -resize 300%%x300%% ^
-alpha deactivate -median 0x3 -despeckle ^
-roll +1+1 ^
-gaussian-blur 2x2 ^
-filter Mitchell -resize 66.666666%%x66.666666%% ^
-sharpen 3x9 -sharpen 2x9 -sharpen 1x3 ^
-separate -seed 666 -attenuate 0.08 +noise gaussian -combine -colorspace sRGB ^
-brightness-contrast -0x-1 -black-threshold 0.4%% ^
*.png
I am not sure if mogrify will allow the -separate ... -combine. So if it does not, then you will have to write a for loop over each file in your directory, unless you have enough memory to hold all the images you want to process.

Why do you need to separate the channels to add noise? You will be adding color noise to each grayscale channel. Is that what you want? Can you not just replace

Code: Select all

-separate -seed 666 -attenuate 0.08 +noise gaussian -combine -colorspace sRGB ^
with

Code: Select all

-seed 666 -attenuate 0.08 +noise gaussian ^

Re: Help consolidate everything to then 'glob' batch-process (Windows)

Posted: 2018-11-03T11:43:16-07:00
by LDAsh
Thanks so much fmw42! That all works except for the noise command you mentioned at the bottom, which indeed fails.
The whole reason for doing it that way is to make the noise monochrome, or a least less colourful, as mentioned in this thread:-
http://www.imagemagick.org/discourse-se ... 1&start=15
Most of that thread goes way over my head but if there's another way to do this, I'd be interested to know...

Re: Help consolidate everything to then 'glob' batch-process (Windows)

Posted: 2018-11-03T13:05:22-07:00
by fmw42
If you want monochrome noise (grayscale), then you can do

Gaussian Gray Noise

Code: Select all

convert image.png ^
( -clone 0 -fill "gray(50%%)" -colorize 100 -seed 666 -attenuate 0.08 +noise gaussian -modulate 100,0,100 ) ^
-compose hardlight -composite result
Change the attenuation and seed as desired. The modulate desaturates the noise image to grayscale and it is composited over the image using -compose hardlight.

To do that in mogrify, then you need to create your grayscale noise image separately first to use for all your other images.

So

Code: Select all

convert image.png -fill "gray(50%%)" -colorize 100 -seed 666 -attenuate 0.08 +noise gaussian -modulate 100,0,100 noise.png
then in mogrify you composite the noise image over your other processed image, then continue your processing.

Code: Select all

mogrify -format png -path path/to/new_directory ^
-filter Point -resize 300%%x300%% ^
-alpha deactivate -median 0x3 -despeckle ^
-roll +1+1 ^
-gaussian-blur 2x2 ^
-filter Mitchell -resize 66.666666%%x66.666666%% ^
-sharpen 3x9 -sharpen 2x9 -sharpen 1x3 ^
-draw "image hardlight 0,0 0,0 'noise.png'" -alpha off ^
-brightness-contrast -0x-1 -black-threshold 0.4%% ^
*.png
see https://imagemagick.org/Usage/basics/#mogrify_compose