First of all, I would like to thank you for all your efforts to produce this wonderful piece of software. I have worked for more than 20 years in

research and ImageMagick has been my go-to tool for several tasks for as many years.

This email concerns the CLAHE option that exists in IM7. In reality there are 2 different versions implemented in different softwares:

1) Original CLAHE which calculates a equalization function for a number of boxes and interpolates between these boxes to get a transfer function for each pixel.

2) Exact CLAHE which calculates the transfer function for each pixel based on a box centered of that pixel. No interpolation is needed

The advantage of "1", which is the version currently implemented in IM7, is speed; the dis-advantage is that it introduces artifacts (stripes) when the interpolation is not able to follow strong gradients in the image.

I would like to ask your help/opinion for making available option 2, also. Any pointers or help implementing this would be greatly appreciated.

Sacha Hony

Here I list some of the background information on method "2":

The available implementations use a trick (sliding window) to gain speed. Basically the histogram centered on the next pixel is updated from the previous histogram by removing just those pixels that moved out of the window and adding just those that entered. Because of this those implementations are sometimes referred to as SWAHE (https://en.wikipedia.org/wiki/Adaptive_ ... ualization). This could be the name used in IM7.

I have found:

Implementation in java: https://imagej.nih.gov/ij/plugins/clahe/CLAHE_.java

Implementation in python: https://github.com/anntzer/clahe

But both of these are impractical (i.e. slow) because of the overhead of the framework.

The scikit-image rank-equalization has a nice figure that demonstrates the sliding window strategy:

https://github.com/scikit-image/scikit- ... generic.py

I have implemented the basic sliding window algorithm (in the y-direction) in python but I am not a good enough C++ programmer to implement it for IM7.

Code: Select all

```
import numpy as np
def slidehist(img, h, x0, x1, y0, y1):
# we remove the bottom strip from the previous calculation
# if it was in the image
if y0-1 >= 0:
h = h - np.histogram(
img[x0:x1, y0-1],
bins=256,
range=(0, 256)
)[0]
# we add the bottom strip to the previous calculation
# if it is in the image
if y1 < img.shape[1]:
h = h + np.histogram(
img[x0:x1, y1],
bins=256,
range=(0, 256)
)[0]
return h
```