I am trying to applying these two filters in the frequency domain. First, the low-pass filter, followed by the Laplace of Gaussian filter. Although my image is being filtered correctly, the output is wrapping around. Also, the output image is shifted ( it looks as if the image has been duplicated).
Here's the input and output: Before and After filter
Here's my code:
# Padding the image
image = Pad(image)
# The mask for low-pass filter
rows, cols = image.shape
center = (rows, cols)
crow, ccol = rows/2, cols/2
Low_mask = np.zeros((rows, cols), dtype=np.float32)
Low_mask[crow-cutoff:crow+cutoff, ccol-cutoff:ccol+cutoff] = 1
# Shifting the mask (low-pass)
Low_mask_dft = np.fft.fft2(Low_mask)
Low_mask_dft_shift = np.fft.fftshift(Low_mask_dft)
# Shifting the image
image_dft = np.fft.fft2(image)
image_dft_shift = np.fft.fftshift(image_dft)
# Performing the convolution
image_fdomain = np.multiply(image_dft_shift, Low_mask_dft_shift)
# Shifting the mask (LOG)
LOGmask = GaussKernel(center)
LOGmask_dft = np.fft.fft2(LOGmask)
LOGmask_dft_shift = np.fft.fftshift(LOGmask_dft)
# Performing the convolution
frequency_image = np.multiply(image_fdomain, LOGmask_dft_shift)
# Now, return the image back to it's original form
result = np.fft.ifftshift(frequency_image)
result = np.fft.ifft2(result)
result = np.absolute(result)
return result