[magick-users] Autolevel Correction
Fred Weinhaus
fmw at alink.net
Wed Apr 15 11:07:56 PDT 2009
Wolfgang,
>Fred's basic idea is to split the three channels R,G,B, adjust each of
>them separately and combine them again to a color photograph. As the
>above example shows, this works just fine. (Anthony: you may use the
>above photographs as an example, as the licence plates cannot be seen.)
>
>The gamm-values mentioned above are just abitrary examples. In the
>skript, I calculate them according to Fred's formula:
>
>gamma = ln(mean_value)/ln(0.5)
>
>This garantuees that in the corrected picture, the mean value is about
>half of the maximum pixel value (i.e. quantum range).
>
>A few remarks however:
>
>1) It is not really clear to me what the difference between
>"-contrast-stretch" and "-linear-stretch" exactly is.
I did a bunch of experiments and Anthony and I exchanged email about
this quite some time ago. Basically:
I believe you are correct in your explanation, but I would phrase it
as follows. The function -linear-stretch works by finding the bin
graylevels corresponding to the clip counts measured from 0 and
stretches from those graylevels. Whereas, the function
-contrast-stretch finds the bin graylevels corresponding to the clip
counts from the min/max bin and stretches from those bin graylevels.
In either case, counts can be raw cumulative or percent cumulative.
(This wording can be improved, but this is a quick note for tonight)
Also -contrast-stretch is sensitive to -channel, but -linear-stretch is not.
>
>2) @ Fred: The mean value which is needed for the gamma formula can be
>computed without using the "quantumrange" value, just by
>identify photo.jpg -format "%[fx:mean]"
True, but then it is sensitive to the mean of the image and not
driven towards a fixed mid-gray value. Could be another option.
>
>3) @ Fred: I think that "-contrast-stretch" does a better job on this as
>your computing of the "-level" values in your script. As far as I
>understood, "-contrast-stretch" actually lets you specify what
>percentage of the pixels will turn to pure black and pure white. (Correct ?)
My script allows you to specify the stretch values if you don't want
the defaults I chose. It is exactly like -contrast-stretch on each
channel (or combined channels depending upon what option you choose),
plus the -gamma is added.
>
>4) The gamma adjustment according to the above formula could be easily
>implemented in IM itself, for instance if the user supplies a gamma
>value of zero, or by some "auto-correct" or "middle" option.
Yes, I already suggested that. But Anthony's and Magick's time is
limited. Furthermore, Anthony and I are still debating how best to
improve -contrast-stretch and -linear-stretch.
>Or is there
>any chance that I can get the result of the "identify" statement into
>just one "convert" command, so that I could do the above transformation
>in a simple batch file, instead of having to deal with a tedious VBS?
Not sure what you mean here. But there has been some improvements on
Anthony's Windows notes. See
http://www.imagemagick.org/Usage/api/#windows
Fred
More information about the Magick-users
mailing list