I am a beginner.
in this code, I want to read multiple images and then denoise using median filtering. but I got this error ‘TypeError: Expected Ptrcv::UMat for argument ‘%s’’
import cv2
import glob
import matplotlib.pyplot as plt
import numpy as np
import random
from PIL import Image
image_list = []
path = “K:/Dataset/All_images/resized_images/.”
for file in glob.glob(path):
a= cv2.imread(file)
denoised_images = []
a = Image.open(file)
image_list.append(a)
for image in image_list:
image = cv2.cvtColor(image_list, cv2.COLOR_RGB2BGR)
noisy = np.zeros(a.shape, np.uint8)
p = 0.2
for i in range(noisy.shape[0]):
for j in range(noisy.shape[1]):
r = random.random()
if r < p/2:
noisy[i][j] = [0, 0, 0]
elif r < p:
noisy[i][j] = [255, 255, 255]
else:
noisy[i][j] = image[i][j]
denoised = cv2.medianBlur(noisy, 5)
output = [image, denoised ]
titles = [‘Original’, ‘Denoised’]
for i in range(2):
plt.subplot(1, 2, i+1)
plt.imshow(output[i])
plt.title(titles[i])
plt.xticks([])
plt.yticks([])
plt.show()
#if name == “main”:
main()’’’