I'm trying to understand why if I set to 0+0j one line over two on the bottom half of the frequency domain gives me a shifted copy on the original image when I reconstruct the spacial image:
here is the example
import cv2 as cv
import math
import numpy as np
import matplotlib.pyplot as plt
imgpath = "MRI_blackandwhite.png"
img = cv.imread(imgpath, cv.IMREAD_GRAYSCALE)
norm_image = cv.normalize(img, None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F)
amp = (np.fft.fftshift(np.fft.fft2(norm_image)))
amp[367//2:-1:2] = amp[367//2:-1:2]* (0+0j)
amp_log = np.abs(amp)
norm_amp = cv.normalize(amp_log, None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F)
restoredAMP = np.abs(np.fft.ifft2(np.fft.ifftshift(amp)))
plt.subplot(131), plt.imshow(norm_image, "gray", vmin=0, vmax=1), plt.title('Image')
plt.xticks([]), plt.yticks([])
plt.subplot(132), plt.imshow(norm_amp, "gray", vmin=0, vmax=1), plt.title('Amplitude')
plt.xticks([]), plt.yticks([])
plt.subplot(133), plt.imshow(restoredAMP, "gray", vmin=0, vmax=1), plt.title('Restored ')
plt.xticks([]), plt.yticks([])
plt.show()
The easiest way to understand this is that you are multiplying half of your k-space by a delta comb filter. Here some pseudo-code
delta_comb = np.ones(shape)
delta_comb[shape//2:-1:2] = 0
k_space_ = k_space * delta_comb
ifft(k_space_) = ifft(k_space) convolved with ifft(delta_comb)
# and
ifft(delta_comb) = delta_comb_with_1_over_spacing
Multiplication in k-space is equivalent to convolution by the FFT(delta comb) in image space. The FFT of a delta comb is another delta comb, with spacing FOV/k-spacing. In your case k-spacing=2, so the FFT of the delta comb is a delta comb with FOV/2 spacing. If you convolve your image with a delta comb, you get copies of your image centered at each individual delta.
The fact that you are taking only half of your k-space just messes up with the relative amplitudes of the image and its "N/2 ghost", but it would work just the same if you had amp[0:-1:2] = amp[0:-1:2]* (0+0j)
in there instead.
But why? What is the intuition behind this, you may ask. Well, by zeroing out lines of k-space you are forcing the coefficients of a number of waves to necessary be zero. Since the coefficient of any given point in k-space is defined by a sum over components in the dual space (image space), the only way for a component to be 0 is if this sum perfectly cancels out. Because frequencies are independent from each other, the only way for coefficients to cancel out is if the positive and negative wave perfectly cancel each out, which means they have to be perfectly out of phase. For that you need them to be shifted. So it's really about the phase being zero that causes the information from the opposing wave to not be cancelled or be cancelled out. You cannot reason about it thinking of amplitudes alone.