isears / tf_clahe

CLAHE implemented in python TF ops
MIT License
24 stars 3 forks source link

Tensorflow CLAHE

Pytest

Contrast-limited adaptive histogram equalization implemented in tensorflow ops.

Setup

pip install tf_clahe

Use

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)

sidebyside example

Optimizing for GPU with XLA

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)

References