如何在不考虑零值的情况下进行直方图均衡?

时间:2019-11-20 02:07:30

标签: python histogram cdf

我有一个介于0和255之间的numpy数组。现在,这个numpy数组具有很多零值(比所有其他值加起来更多的零值)。这对cdf有何影响?对于所有其他值,它都具有很高的值。这种行为不是故意的。

我使用以下代码:

def image_histogram_equalization(image, number_bins = 256):
        # get image histogram
        image_histogram, bins = np.histogram(image.flatten(), bins=range(0, number_bins), density=True)

        cdf = image_histogram.cumsum() # cumulative distribution function
        cdf = 255 * cdf / cdf[-1] # normalize

        # use linear interpolation of cdf to find new pixel values
        image_equalized = np.interp(image.flatten(), bins[:-1], cdf)

        return image_equalized.reshape(image.shape), cdf

    image_new = image_histogram_equalization(image_source)[0]

有没有办法在直方图均衡化中不包含零值?

谢谢

0 个答案:

没有答案