Clean low pass denoiser
This commit is contained in:
parent
95796b53fc
commit
ec4657eda8
@ -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)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user