Request for output from automated operators

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Request for output from automated operators

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

Re: Request for output from automated operators

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Request for output from automated operators

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

Re: Request for output from automated operators

Post 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)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Request for output from automated operators

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

Re: Request for output from automated operators

Post 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.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Request for output from automated operators

Post by GreenKoopa »

For -trim, I ran across the escape %@
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Request for output from automated operators

Post by snibgo »

Well spotted, thanks!
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Request for output from automated operators

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Request for output from automated operators

Post 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?)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Request for output from automated operators

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Request for output from automated operators

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply