From ec4657eda81f0fa448cadc3e09b10437d499da85 Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Wed, 15 May 2024 18:21:11 +0200 Subject: [PATCH] Clean low pass denoiser --- datasets/raise/utils.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/datasets/raise/utils.py b/datasets/raise/utils.py index a8f8110..6c699a0 100644 --- a/datasets/raise/utils.py +++ b/datasets/raise/utils.py @@ -60,28 +60,22 @@ def denoise(imageNpArray, denoiser): # fft of image fft1 = fftpack.fftshift(fftpack.fft2(imageNpArray)) + # Padding as follows may not be perfectly correct but seems fine enough. GAUSSIAN_SIGMA = 50 - #low_pass_np = np.zeros(image1_np.shape, dtype = np.uint8) - low_pass_np_size = min(image1_np.shape) - low_pass_np = getGaussianKernel(low_pass_np_size, GAUSSIAN_SIGMA) + imageNpArrayShape = imageNpArray.shape + lowPassNpArraySize = min(imageNpArrayShape) + lowPassNpArray = getGaussianKernel(lowPassNpArraySize, GAUSSIAN_SIGMA) - #rectangle_low_pass_np = np.zeros(fft1.shape) - #rectangle_low_pass_np[] - - requiredH, requiredW = image1_np.shape - vert_pad_size = (requiredH - low_pass_np_size) // 2 - hor_pad_size = (requiredW - low_pass_np_size) // 2 - rectangle_low_pass_np = np.pad(low_pass_np, [(vert_pad_size, vert_pad_size), (hor_pad_size, hor_pad_size)]) + wantedHeight, wantedWidth = imageNpArrayShape + verticalPadSize, horizontalPadSize = [(wantedDimension - lowPassNpArraySize) // 2 for wantedDimension in [wantedHeight, wantedWidth]] + rectangleLowPassNpArray = np.pad(lowPassNpArray, [(verticalPadSize, verticalPadSize), (horizontalPadSize, horizontalPadSize)]) # Unsure that doing such *normalization* is appropriate. - rectangle_low_pass_np /= rectangle_low_pass_np.max() - - #plt.imshow(rectangle_low_pass_np) - #plt.show() + rectangleLowPassNpArray /= rectangleLowPassNpArray.max() # multiply both the images - filtered = np.multiply(fft1, lowPassNp) + filtered = np.multiply(fft1, rectangleLowPassNpArray) # inverse fft ifft2 = np.real(fftpack.ifft2(fftpack.ifftshift(filtered)))