Page 1 of 1
Request for output from automated operators
Posted: 2013-05-09T21:47:43-07:00
by snibgo
When processing video frames, I often want to apply the same processing to all the frames in one clip. IM has automated versions of manual operators (eg "-auto-level" and "-level"). Using the automated version on all frames generally gives a jerky result. I would like to use the automated version on one frame, then use the same setting on all the other frames.
So I would like "-auto-level" to optionally give the equivalent manual operation. Perhaps I would ask for it via an artefact such as -print '%[auto-level:levels]\n', or something.
Code: Select all
Automated Manual
========= ======
-auto-level -level
-auto-gamma -gamma
-auto-orient -orient
-contrast-stretch -level
-linear-stretch -level
-normalize -level
-trim -crop
Perhaps I can already get the equivalent to an automated operation. Feel free to tell me.
Re: Request for output from automated operators
Posted: 2013-05-09T22:05:31-07:00
by fmw42
Kind of a kludge, but perhaps you can process the first frame with -auto-level. Then figure out what the min and max have changed "from" via its verbose info (the to values are of course 0 and 255) and then using -level on all the other images. I don't know about doing the same with -contrast-stretch other than 0, which should be about the same as -auto-level. I suppose one could look at the histograms and figure out the corresponding min and max values where the clip occurred for any black-point and white-point percent clip values and then use -level again. That is likely more accurate for -linear-stretch than for -contrast-stretch.
Autogamma is done via finding the mean value in the image (in range 0 to 1), then computing log(0.5/mean) and using that value with -gamma.
If one can figure out some function to apply, however complex, it can applied to a hald image and one can loop over each frame with -hald-clut. This would be much easier if -hald-clut could be applied to a sequence of images (somewhat like mogrify).
It certainly would be nice to be able to get verbose information from -contrast-stretch and -linear-stretch and -normalize on the clip values in graylevel values of some form or another (quantum range, or 0 to 1, or percent). Similarly min and max from -auto-level and gamma value from -auto-gamma, but these last two just come from the input image's min,max and mean values, which you can get from string formats %[min], %[max] and %[mean]
You can get the trim coordinates already from string formats %O and %P see
http://www.imagemagick.org/script/escape.php
I suppose this or what you have requested would be much easier in IM 7 with its new scripting. But Anthony would be able to say more.
Re: Request for output from automated operators
Posted: 2013-05-09T23:10:30-07:00
by snibgo
Thanks Fred.
For contrast-stretch, I currently use an external program that reads a histogram file and spits out the appropriate level operator for given thresholds.
I had brain-fade, and had forgotten min, max and %P%O.
Can I query your gamma formula?
Code: Select all
identify -format "%[fx:mean] %[fx:log(0.5/mean)]" rose:
0.412341 0.083713
0.083713 is a very small value for "-gamma", and gives a different result to "-auto-gamma".
My table now reads:
Code: Select all
Automated Manual
========= ======
-auto-level -level SOLVED: use min and max
-auto-gamma -gamma SOLVED? use log(0.5/mean)
-auto-orient -orient
-contrast-stretch -level
-linear-stretch -level
-normalize -level
-trim -crop SOLVED: use %P%O
Re: Request for output from automated operators
Posted: 2013-05-09T23:18:16-07:00
by fmw42
snibgo wrote:Thanks Fred.
Can I query your gamma formula?
Code: Select all
identify -format "%[fx:mean] %[fx:log(0.5/mean)]" rose:
0.412341 0.083713
0.083713 is a very small value for "-gamma", and gives a different result to "-auto-gamma"
My mistake. I remembered it wrong and had not double checked. It is log(mean)/log(0.5). At least that was what I coded in my script, autogamma, and I presume Anthony used that in his -auto-gamma.
gammaval=`convert xc: -format "%[fx:log($mean/100)/log($midrange)]" info:` as per my script.
where mean has been converted to percent and midrange is nominally 50. So converting to range 0 to 1 it would be log(mean)/log(midrange)
Re: Request for output from automated operators
Posted: 2013-05-09T23:26:59-07:00
by snibgo
Code: Select all
identify -format "%[fx:log(mean)/log(0.5)]" rose:
That seems to be it. I get zero difference when using this for "-gamma", compared to using "-auto-gamma". Thanks.
Re: Request for output from automated operators
Posted: 2013-05-10T09:46:43-07:00
by fmw42
I would still agree that it would be nice to be able to get all that information from those functions, say via -verbose or some other method.
Re: Request for output from automated operators
Posted: 2013-05-11T02:13:14-07:00
by GreenKoopa
For -trim, I ran across the
escape %@
Re: Request for output from automated operators
Posted: 2013-05-11T02:37:29-07:00
by snibgo
Well spotted, thanks!
Re: Request for output from automated operators
Posted: 2013-05-12T19:18:51-07:00
by anthony
the automatic versions are all designed to be single image processing
They do not handle multiple images using the same values.
Do do that either.
- append a representative set of the images and do an auto- whatever, the determine what it did
At the moment the operators do not store tha values it used in image properties/artifacts (they may in the future... adding to my to-do list) so determining the values can be tricky
- append ALL the images, do the operation, then tile crop the images to separate images
this works, but may not be usedful for LARGE numbers of images such as video.
An example of this is using append to side-by-side append two animations together
http://www.imagemagick.org/Usage/anim_mods/#append
(The third method)
So it is difficult either way. The first is practical but difficult, the second has memory limits.
Re: Request for output from automated operators
Posted: 2013-05-12T19:24:28-07:00
by fmw42
I think the point is to be able to extract the pertinent information (if possible) from running the comman on an image, e.g. clip graylevels (-contrast-stretch, -normalize, -linear-stretch), gamma value (-auto-gamma), etc. (-verbose or -define?)
Re: Request for output from automated operators
Posted: 2013-05-12T21:38:26-07:00
by snibgo
Yes, I want to use Anthony's first method: from a representative frame (or a number of representative frames appended), do an automatic operation, then repeat the equivalent operation with identical parameters on all the frames in a clip.
The only operation I use that IM doesn't give me useful information is "-contrast-stretch". So I've written my own program to analyse a histogram. I'm currently experimenting with this, getting out a more inteligent curve that takes some account of peaks and troughs in the histogram, or equalisation with various tweaks, and so on.
My "-trim" requirement is more complex. It's for a "stabilise" feature, where frames in a hand-held video shot are straightened up, using "-distort perspective" or my own software that triangulates and uses barycentric coordinates.
Re: Request for output from automated operators
Posted: 2013-05-12T21:48:19-07:00
by anthony
Okay so we need these operators to generate some artifacts for images with the internal values it decided on using.
I'd prefer to use an artifact rather than a property as propertys are saved with images (if format allows, like PNG) while artifacts are not saved.