I am trying to denoise many several noises with several filters for a research i have, i found a deconvolution Wiener filter made by "mr.tranleanh" on Github, as you can see here .
what I did is that I canceled the blurring part in the code and only add Gaussian noise to my images, and I made a PSNR calculation each time I apply the filter, and for each time I was increasing the size of the Gaussian kernel the PSNR value is getting bigger, so that's mean that the noise is being reduced, and all that without adding blurring to the image.
I am wondering whether I can use the Wiener filter for reducing noise in this way (without blurring).
- Can a deconvolution Wiener filter reduce noise without blurring?
- Why does the image get darker each time I apply the Wiener filter?
Shortly this is how I wrote the code:
def add_gaussian_noise(img, sigma): gauss = np.random.normal(0, sigma, np.shape(img)) noisy_img = img + gauss noisy_img[noisy_img < 0] = 0 noisy_img[noisy_img > 255] = 255 return noisy_img def wiener_filter(img, kernel, K): kernel /= np.sum(kernel) dummy = np.copy(img) dummy = fft2(dummy) kernel = fft2(kernel, s = img.shape) kernel = np.conj(kernel) / (np.abs(kernel) ** 2 + K) dummy = dummy * kernel dummy = np.abs(ifft2(dummy)) return dummy def gaussian_kernel(kernel_size = 3): h = gaussian(kernel_size, kernel_size / 3).reshape(kernel_size, 1) h = np.dot(h, h.transpose()) h /= np.sum(h) return h def rgb2gray(rgb): return np.dot(rgb[...,:3], [0.2989, 0.5870, 0.1140]) if __name__ == '__main__': # Load image and convert it to gray scale file_name = os.path.join('/content/Hand.jpeg') img = rgb2gray(plt.imread(file_name)) # Add Gaussian noise noisy_img = add_gaussian_noise(blurred_img, sigma = 20) # Apply Wiener Filter kernel = gaussian_kernel(3) filtered_img = wiener_filter(noisy_img, kernel, K = 10)
the type of images I want to apply the wiener filter on :
they are just normal gray images, but I will add salt&pepper noise by this code :
import cv2 def add_noise(img): row , col = img.shape number_of_pixels = random.randint(300, 10000 ) for i in range(number_of_pixels): y_coord=random.randint(0, row - 1) x_coord=random.randint(0, col - 1) img[y_coord][x_coord] = 255 number_of_pixels = random.randint(300 , 10000) for i in range(number_of_pixels): y_coord=random.randint(0, row - 1) x_coord=random.randint(0, col - 1) img[y_coord][x_coord] = 0 return img img = cv2.imread('/content/Hand.jpeg', cv2.IMREAD_GRAYSCALE) cv2.imwrite('s&p12spe.jpg', add_noise(img))
the full code for adding salt&pepper noise source in case you want more explanation.
again I just want to denoise salt&pepper noise via Wiener filter, and I know salt&pepper noise is denoised via other filters like median filter, but am doing this for research purposes, and the only code I found for the Wiener filter is the one I uploaded here in the question, i don't know if more information can help you, but thanks anyway