files2 = [f for f in listdir(dstpath) if isfile(join(dstpath,f))]
for image in files2:
img = cv2.imread(os.path.join(dstpath,image))
equ = cv2.equalizeHist(img)
dstPath2 = join(dstpath,image)
cv2.imwrite(dstPath2,equ)
我有一个由jpg格式的灰度图像组成的文件夹,但是当我运行上面的代码进行直方图均衡时,它会给我上面提到的错误。请帮忙
答案 0 :(得分:0)
imread
默认情况下以彩色模式加载图片。尝试使用img = cv2.imread(your_image_path,cv2.IMREAD_GRAYSCALE)
代替
答案 1 :(得分:0)
@author: Quantum
"""
import cv2
import os
from os import listdir,makedirs
from os.path import isfile,join
path = r'' # Source Folder
dstpath = r'' # Destination Folder
try:
makedirs(dstpath)
except:
print ("Directory already exist, images will be written in asme folder")
# Folder won't used
files = [f for f in listdir(path) if isfile(join(path,f))]
for image in files:
try:
img = cv2.imread(os.path.join(path,image),cv2.IMREAD_GRAYSCALE)
**imgnew=cv2.equalizeHist(img)**
dstPath = join(dstpath,image)
cv2.imwrite(dstPath,imgnew)
except:
print ("{} is not converted".format(image))
我所做的只是添加了histeq功能,而我的文件转换为灰度