Contrast-limited adaptive histogram equalization implemented in tensorflow ops.
pip install tf_clahe
import tensorflow as tf
import tf_clahe
img = tf.io.decode_image(tf.io.read_file('./path/to/your/img'))
# With sane defaults (8x8 tiling and 4.0 clip limit)
img_clahe = tf_clahe.clahe(img)
# With custom parameters (4x4 tiling and 3.0 clip limit)
img_clahe = tf_clahe.clahe(img, tile_grid_size=(4, 4), clip_limit=3.0)
A considerable performance improvement can be achieved by using the gpu_optimized
flag
in combination with XLA compilation. For example:
import tf_clahe
import tensorflow as tf
@tf.function(experimental_compile=True) # Enable XLA
def fast_clahe(img):
return tf_clahe.clahe(img, gpu_optimized=True)