magick wrote:We'll take a look at integrating it this weekend. Should the option name be -redist?
That is OK with me. Something like:
-redist shape brightness,low-contrast[,high-contrast]
or
-redist shape mean,low-sigma[,high-sigma]
( or -redistribute is OK, too). You can decide or see if Anthony has any input.
There are two current options for shape of distribution: Gaussian and Uniform. When uniform is used, there are no other arguments. The 3 other arguments are only for the Gaussian option.
If only one contrast/sigma value is supplied then use that for both. In my redist all values are in percent range 0-100 (or higher for contrast/sigma). I am not sure how you want to deal with the 3 values (i.e. if you want to use percents and/or raw graylevels or the usual sigma type values.) I will leave that to you. The sigma values are the percent graylevels that correspond to one-sigma on the gaussian distribution -- so they control the rate of roll-off or width in percent graylevel for the gaussian. The mean/brightness controls the percent graylevel corresponding to the center or peak of the gaussian distribution.
Uniform is the same as IM -equalize, except that in my redist it uses the global histogram. But it would be nice to have the new function be channel sensitive. That way it can use the global histogram or work channel by channel. I also have an option to use the Lightness/Brightness channel from HSL or HSB (or intensity channels from other colorspaces), but if that is too much, leave it off. The main thing is that it should do it globally or each channel separately (for RGB). If you decide only to do the Gaussian, then it would be nice to have -equalize be channel sensitive and allow one to work on the global histogram as well as the current channel-by-channel situation.
It would be nice to have the distribution/shape be modular, so that other distributions could be added later if desired. But if not, and you decide to only do the Gaussian, then it could be: -gaussian-redist or -gaussian-redistribute as below:
-gaussian-redistribute brightness,low-contrast[,high-contrast]
or
-gaussian-redistribute mean,low-sigma[,high-sigma]
( The 3 values are something like midtones,shadows,highlights)
In any case, if you want to use my nominal values (or some nominal values for the defaults --- I used 60,60,60), then all the arguments would be optional
Here is a synopsis of how it works.
It works by first converting the image to some color space, nominally HSL or
RGB. Then it computes a histogram for the image.
If the image is converted to other than RGB, then the grayscale will come
from an intensity-like channel. Otherwise, if the color space is RGB, the
RGB image is converted to a simple global grayscale image. The script then
generates the integral of the specified distribution scaled to the last
value in the image's cumulative histogram. For each value in the image's cumulative
histogram, it finds the closest value in the integral and then looks to see
what is its graylevel. It uses those graylevel values as the y-value in a
mapping transformation whose x-values range from 0-255. This mapping
transformation is expressed as a 1-D image and used with the IM function
-fx or -clut to transform the input image's values in each of its channels.
For the uniform distribution, it turns out that the cumulative histogram is
lookup transformation for -clut itself. So no integration is necessary.
See my page at
http://www.fmwconcepts.com/imagemagick/redist.php and the script for more details. Feel free to contact me for further discussions.
Fred