Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当我在灰度图像中应用中值滤波器时,它会转换回RGB图像。为什么?_Python_Rgb - Fatal编程技术网

Python 当我在灰度图像中应用中值滤波器时,它会转换回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

当我在灰度图像中应用中值滤波器时,它会转换回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 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的?这是否回答了您的问题?是否可以添加输入图像和输出图像或输入图像和输出图像的形状