如何在PythonJupyter中构建用于计算点扩散函数图像处理的函数?

问题描述

在图像处理中,对图像进行傅立叶变换,然后进行傅立叶中心变换,然后进行欠采样,然后返回到逆中心变换,再通过逆傅立叶变换返回图像。那么,要计算点扩散函数,下面的函数还可以吗?

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)```

解决方法

您可以使用此 https://github.com/cgohlke/psf,一个用于荧光显微镜的点扩散函数计算

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...