Page 1 of 3
Make an Adaptive Histogram Equalization
Posted: 2013-06-05T03:09:36-07:00
by MathieuC
Hello,
I'm trying to convert this image :
to this image :
I read the page about Color Modification but i don't find the good args to apply. I would like to try the redist script from Fred's ImageMagick Scripts but i'm using the windows version of ImageMagick and I cannot install cygwin.
Does somebody knows the way to convert the first image to the second ? Or to use the redist script on windows ?
Best regards
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-05T03:47:28-07:00
by snibgo
This is quite close:
Code: Select all
convert originalnew.jpg ( +clone -equalize ) -average o.jpg
Instead of taking the average, you could blend.
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-05T05:06:37-07:00
by MathieuC
Thank a lot, it's working
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-05T08:00:15-07:00
by MathieuC
I spoke too fast, with this image is do not work :
Original :
After convert originalnew.jpg ( +clone -equalize ) -average o.jpg :
The same image process with the software Color Factory of Fotoware, it's using
the adaptive historgram equalization technique (very powerful) :
I'm trying to do the same image process with ImageMagick.
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-05T13:55:37-07:00
by fmw42
What version of IM are you using. If old it may be equalizing differently for each channel. If new the default is to equalize the same for all channels.
If you are on a recent version of IM, you can try both
-equalize
or
-channel rgb -equalize
see if either give you a good result.
The only way to use my redist, is if you install Cygwin on Windows.
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-05T15:15:22-07:00
by snibgo
"Equalize" is an extreme effect that can benefit from other options. For example (in v6.8.5-7):
Code: Select all
convert room.jpg ( +clone -channel RGB -equalize ) -average r.jpg
... seems a good result to me.
A huge number of histogram equalization effects are available using just ImageMagick. In addition, IM can generate a histogram for processing by an external program, to create a clut which is then applied to the image.
I use the external program technique for various processing, including what Wiki calls "contrast limited adaptive histogram equalization (CLAHE)", and various others including my current favourite, which involves finding the first and last peaks in the histogram, and increasing the contrast between the peaks at the expense of contrast outside the peaks. (Hence, the darkest tones will become darker, while the lightest tones will become lighter.)
Your sample result from Fotoware appears to do something similar: the dark doorway becomes very dark, while the middle tones of the right and middle walls have become spread further apart. This is very similar to the result from my script in this post, but slightly more extreme. So a blend instead of average would probably nail it.
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-06T05:49:30-07:00
by MathieuC
@fmw42
I'm using ImageMagick 6.8.5-4 2013-04-28 Q16
@snibgo
It's better thank to you. What is the software/process do you use to make the CLAHE process ?
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-06T10:18:37-07:00
by fmw42
Did you try my suggestion of testing
-equalize
or
-channel rgb -equalize
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-06T13:56:28-07:00
by snibgo
MathieuC wrote:What is the software/process do you use to make the CLAHE process ?
My own software. The contrast limiting is very simple: after reading the histogram, it can cap each value before calculating the cumulative. For the cap value, the code calculates the mean and standard deviation of the histogram counts. The user specifies a multiple of the standard deviation. The cap is the mean, plus this multiple times the StdDev.
This comes after other process such as filling null counts. (A 14-bit camera can only generate 2^14 values, so a 16-bit histogram has counts in only about 1/4 of the values. The histogram is shaped like a comb, which confuses some processes. I fill in null counts by spreading non-zero counts.)
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-06T20:32:28-07:00
by fmw42
There is code available at
http://tog.acm.org/resources/GraphicsGe ... iv/clahe.c if anyone wants to implement it. It is a reference in
http://en.wikipedia.org/wiki/Adaptive_h ... ualization
snibgo wrote:My own software. The contrast limiting is very simple: after reading the histogram, it can cap each value before calculating the cumulative. For the cap value, the code calculates the mean and standard deviation of the histogram counts. The user specifies a multiple of the standard deviation. The cap is the mean, plus this multiple times the StdDev.
Just curious if you redistributed the capped values on the histogram as described in the Wikipedia page?
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-07T14:59:02-07:00
by snibgo
fmw42 wrote:Just curious if you redistributed the capped values on the histogram as described in the Wikipedia page?
I didn't. I wasn't sure of the value of doing so. Redistributing seemed to be the equivalent of simply lowering the cap slightly. The magic (or the art) is in selecting the best cap value.
But I could be wrong about redistribution; when I get some time, I intend to experiment.
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-11T00:37:40-07:00
by MathieuC
Does someone knows a software who implements the CLAHE process (freeware/shareware) and who can be call with a DOS command line ?
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-11T22:52:01-07:00
by fmw42
MathieuC wrote:Does someone knows a software who implements the CLAHE process (freeware/shareware) and who can be call with a DOS command line ?
Not DOS, but you can download CLAHE plugin for ImageJ for all platforms
see
http://rsb.info.nih.gov/ij/plugins/clahe/index.html
http://rsb.info.nih.gov/ij/download.html
It is also in OpenCV library,
see
http://opencv.org/
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-14T15:39:21-07:00
by snibgo
If you are playing with adaptive histogram equalisation, you might look into the strongly related technique of pseudo-HDR. (HDR = High Dynamic Range.)
Here's a quick and easy pseudo-HDR. Windows script, but fairly easily translatable. It merges two equalised images: the darkest 30% and lightest 70%. (Adjust the boundary, CUTPC, as desired.) The mask used for the blend is a heavily blurred version of the original, which thus replicates the Adaptive effect of Adaptive Histogram Equalisation.
This script doesn't limit the contrast introduced by equalisation, so noise in areas of fairly constant tone becomes exagerated.
Code: Select all
set SRC=sm.jpg
set CUTPC=30
FOR /F "usebackq" %%L IN (`%IM%identify -format "WW=%%w\nHH=%%h" %SRC%`) DO set %%L
"convert" %SRC% ^
-alpha off ^
-colorspace HSL -channel B ^
-equalize ^
-colorspace sRGB -channel RGB,sync ^
( -clone 0 -level 0%%,%CUTPC%%% ) ^
( -clone 0 -level %CUTPC%%%,100%% ) ^
( -clone 0 -resize 2%%x2%% -resize "%WW%x%HH%^!" ) ^
-delete 0 ^
-compose Over -composite ^
pseudo.jpg
Re: Make an Adaptive Histogram Equalization
Posted: 2013-06-18T00:08:29-07:00
by MathieuC
Thank you for your help, the results is better than -equalize.