python批量直方图均衡化_Python中的自适应直方图均衡化

我尝试在python中实现自适应直方图均衡化。我把一张图像分成更小的区域,然后应用传统的直方图均衡化方法。然后我将这些较小的图像合并成一个,得到最终的结果图像。最后的图像看起来是非常块状的,每个区域的对比度都不同。有没有一种方法可以使每个单独的图像保持一致的对比度,使其看起来像一个单独的图像,而不是缝合在一起的较小的图像。在

import cv2

import numpy as np

from matplotlib import pyplot as plt

from scipy.misc import imsave

from scipy import ndimage

from scipy import misc

import scipy.misc

import scipy

import image_slicer

from image_slicer import join

from PIL import Image

img = 'watch.png'

num_tiles = 25

tiles = image_slicer.slice(img, num_tiles)

for tile in tiles:

img = scipy.misc.imread(tile.filename)

hist,bins = np.histogram(img.flatten(),256,[0,256])

cdf = hist.cumsum()

cdf_normalized = cdf *hist.max()/ cdf.max()

plt.plot(cdf_normalized, color = 'g')

plt.hist(img.flatten(),256,[0,256], color = 'g')

plt.xlim([0,256])

plt.legend(('cdf','histogram'), loc = 'upper left')

cdf_m = np.ma.masked_equal(cdf,0)

cdf_o = (cdf_m - cdf_m.min())*255/(cdf_m.max()-cdf_m.min())

cdf = np.ma.filled(cdf_o,0).astype('uint8')

img3 = cdf[img]

cv2.imwrite(tile.filename,img3)

tile.image = Image.open(tile.filename

image = join(tiles)

image.save('watch-join.png')

你可能感兴趣的:(python批量直方图均衡化)