printing out min,max,mean value of a picture

hello
I’m trying to find out how I could print the min,max,mean values of a picture.
I have a script (Perl) where I would like to send a gmic command and continue doing things with these values
something like
gmic ima.1.png ima.2.png sub abs e {mean value,max value etc…} -o tmp.png

is this possible?
luc

Yes, you can do something like this :

gmic image.png echo_stdout[] "{[ia,im,iM]}"

(using echo will output on stderr).

1 Like

ok cool.thank you David
just for me to get to the bottom of this , why do I have to put ia,im,iM inside [ ] ?

This is a way to represent a vector of numbers in the G’MIC math parser (so between {}). A math expression returning a vector is substituted by a string where all those numbers are separated by commas.
It is basically the same as writing {ia},{im},{iM}, but this latter form invokes 3x time the math evaluator so is probably a bit slower to run (and longer to write :slight_smile: ).

1 Like

ok.clear for me.thank you very much

In another example you used echo[]. Is there a reason for the empty square brackets?

Foe echo_stdout no, it has no difference with or without selections (echo_stdout does nothing with the selected images by the way).
For echo, this is a bit different, as specifying a [selection] for this particular command is not related to the images, but to the command scope that is also echo-ed.
echo[] string tells G’MIC to write only the specified string on stderr and nothing else.

:thinking: Could you please elaborate a bit more? I know how to redirect but I don’t know much about stdout and stderr and what you mean by scope. A few examples would help (if you have the time :sunny:).

Maybe an example is worth a thousands words:
Define this function in file foo.gmic:

foo : 
   echo "First comment\n"
   echo[^-1] "Second comment\n"
   echo[] "Third comment\n"
   echo_stdout "Fourth comment\n"

Then try this from the console:

$ gmic foo.gmic foo
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'foo.gmic' (1 new, total: 3135).
[gmic]-0./foo/ First comment

[gmic]-0./ Second comment

Third comment
Fourth comment


[gmic]-0./ End G'MIC interpreter.

Another try, with redirection of stdout to a file:

$ gmic foo.gmic foo >stdout.txt
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'foo.gmic' (1 new, total: 3135).
[gmic]-0./foo/ First comment

[gmic]-0./ Second comment

Third comment

[gmic]-0./ End G'MIC interpreter.

$ cat stdout.txt 
Fourth comment