In Image processing, the image is fourier transformed, then center transformed in fourier, and then under-sampled, and back to inverse center transform and back to image by inverse fourier transform. So, to calculate Point Spread Function, is the below function alright?
def apply_Fu(sampling_pattern, x):
#compute subsampled FFT #Sampling pattern is matrix where 1 means we take that sample for undersampling
return sampling_pattern*np.fft.fftshift(np.fft.fft2(x))
def apply_Fu_adjoint(sampling_pattern, y):
#Compute adjoing of subsampled k space
return np.fft.ifft2(np.fft.ifftshift(sampling_pattern*y))
def spr(gridsize, sampling_pattern):
# gridsize should be 2-element tuple, e.g. gridsize = (10, 10)
maxima = np.zeros(gridsizedtype = np.complex_)
for x in range(gridsize[0]):
for y in range(gridsize[1]):
# in this iteration, the index "i" corresponds to the gridpoint (x, y)
# construct basis vector
e_i = np.zeros(gridsize, dtype = np.complex_)
e_i[x, y] = 1
# compute psf_i = Fu* Fu e_i
# psf_i[xx, yy] is PSF(i,j) if index "j" corresponds to gridpoint (xx, yy)
psf_i = apply_Fu_adjoint(sampling_pattern, apply_Fu(sampling_pattern, e_i))
# normalize; psf_i[x, y] is PSF(i,i)
psf_i = psf_i / psf_i[x, y]
# trick to exclude point "i" itself from maximum: set it to -infinity
psf_i[x, y] = -np.inf
# "inner" maximum, over "j"
maxima[x, y] = np.max(psf_i)
spr = np.max(maxima)
return spr
spr = spr(img.shape, random)
np.abs(spr)```
You can use this https://github.com/cgohlke/psf, a Point Spread Function calculations for fluorescence microscopy