我正在尝试在Python中实现自适应直方图均衡化。我将一张图片分成较小的区域,然后对其应用传统的直方图均衡化。然后将这些小图像合并成一个,并获得最终的结果图像。最终图像的特点是非常块状,并且每个单独区域的对比度级别不同。是否有一种方法可以保持每个单独图像的均匀对比度,使其看起来像单个图像而不是拼接在一起的小图像。
请看下面的图片进行更好的理解:
请看下面的图片进行更好的理解:
![Input](https://istack.dev59.com/PgaNb.webp)
![Output](https://istack.dev59.com/XYdg4.webp)
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')