我有许多 .png
扩展格式的彩色图像,其默认名称为 right.1.png
、right.2.png
、 ...和right.n.png
,还有wrong.1.png
、wrong.2.png
...和错误.n.png
。我想通过使用任何库 numpy、cv2 等对所有图像在 python 中进行直方图均衡。我应该将均衡后的图像及其默认名称保存在一个新文件夹中,在当前工作目录中将其称为 NEWFOLDER
。
我尝试按照以下链接获取灰度图像,但无法成功 How to implement histogram equalization for images in tensorflow? 任何处理此问题的建议
最佳答案
使用 opencv 进行直方图均衡化非常简单。 Here's文档。
# Histogram equalization
def hist_equal(file_name):
# Read image file
img = cv2.imread(DIR_PATH + file_name, 0)
# Apply histogram equalization
equ = cv2.equalizeHist(img)
# Save file to new directory
cv2.imwrite(NEW_DIR_PATH + file_name, equ)
要迭代目录中的文件,您可以使用 Python 中的 os
库。
# Iterate through each image file
for file_name in os.listdir(DIR_PATH):
hist_equal(file_name)
关于python - 如何在Python中对许多彩色图像进行直方图均衡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59418904/