如何在tensorflow中实现图像的直方图均衡化?

2024-09-30 04:27:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个深入学习和张量流新手。在

我正在尝试修改cifar10tensorflow教程,以便将其用于面部输入图像。在

如何计算直方图均衡化?在

是否可以包装类似于:Histogram equalization of grayscale images with NumPy中的解决方案?在


Tags: of图像numpywith教程解决方案直方图histogram
1条回答
网友
1楼 · 发布于 2024-09-30 04:27:34

对于灰度uint8图像,您可以使用如下方法:

def tf_equalize_histogram(image):
    values_range = tf.constant([0., 255.], dtype = tf.float32)
    histogram = tf.histogram_fixed_width(tf.to_float(image), values_range, 256)
    cdf = tf.cumsum(histogram)
    cdf_min = cdf[tf.reduce_min(tf.where(tf.greater(cdf, 0)))]

    img_shape = tf.shape(image)
    pix_cnt = img_shape[-3] * img_shape[-2]
    px_map = tf.round(tf.to_float(cdf - cdf_min) * 255. / tf.to_float(pix_cnt - 1))
    px_map = tf.cast(px_map, tf.uint8)

    eq_hist = tf.expand_dims(tf.gather_nd(px_map, tf.cast(image, tf.int32)), 2)
    return eq_hist

试验用:

^{pr2}$

相关问题 更多 >

    热门问题