Python 当我在灰度图像中应用中值滤波器时,它会转换回RGB图像。为什么?
当我在灰度图像中应用中值滤波器时,它会转换回RGB图像。为什么? 见下面的代码:Python 当我在灰度图像中应用中值滤波器时,它会转换回RGB图像。为什么?,python,rgb,Python,Rgb,当我在灰度图像中应用中值滤波器时,它会转换回RGB图像。为什么? 见下面的代码: path = '/content/img_gray' # Source Folder dstpath = '/content/img_filtered_gray' # Destination Folder try: makedirs(dstpath) except: print ("Directory already exist, images will be written in sam
path = '/content/img_gray' # Source Folder
dstpath = '/content/img_filtered_gray' # Destination Folder
try:
makedirs(dstpath)
except:
print ("Directory already exist, images will be written in same folder")
# Folder won't used
files = list(filter(lambda f: isfile(join(path,f)), listdir(path)))
for image in files:
try:
img = cv2.imread(os.path.join(path,image))
median = cv2.medianBlur(img,5)
dstPath = join(dstpath,image)
cv2.imwrite(dstPath,median)
except:
print ("{} is not converted".format(image))
在应用
medianBlur
之前,从BGR转换为灰色:
img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
median = cv2.medianBlur(img,5)
请注意,OpenCV中的默认颜色格式通常称为RGB,但实际上是BGR(字节颠倒)。您是如何确定输入图像为灰度,输出图像为RGB的?这是否回答了您的问题?是否可以添加输入图像和输出图像或输入图像和输出图像的形状