def genBlurImage(p_obj, img): smax = p_obj['delta0'] / p_obj['D'] * p_obj['N'] temp = np.arange(1,101) patchN = temp[np.argmin((smax*np.ones(100)/temp - 2)**2)] patch_size = round(p_obj['N'] / patchN) xtemp = np.round_(p_obj['N']/(2*patchN) + np.linspace(0, p_obj['N'] - p_obj['N']/patchN + 0.001, patchN)) xx, yy = np.meshgrid(xtemp, xtemp) xx_flat, yy_flat = xx.flatten(), yy.flatten() NN = 32 # For extreme scenarios, this may need to be increased img_patches = np.zeros((p_obj['N'], p_obj['N'], int(patchN**2))) den = np.zeros((p_obj['N'], p_obj['N'])) patch_indx, patch_indy = np.meshgrid(np.linspace(-patch_size, patch_size+0.001, num=2*patch_size+1), np.linspace(-patch_size, patch_size+0.001, num=2*patch_size+1)) for i in range(int(patchN**2)): aa = genZernikeCoeff(36, p_obj['Dr0']) temp, x, y, nothing, nothing2 = psfGen(NN, coeff=aa, L=p_obj['L'], D=p_obj['D'], z_i=1.2, wavelength=p_obj['wvl']) psf = np.abs(temp) ** 2 psf = psf / np.sum(psf.ravel()) focus_psf, _, _ = centroidPsf(psf, 0.85) #: Depending on the size of your PSFs, you may want to use this psf = resize(psf, (round(NN/p_obj['scaling']), round(NN/p_obj['scaling']))) patch_mask = np.zeros((p_obj['N'], p_obj['N'])) patch_mask[round(xx_flat[i]), round(yy_flat[i])] = 1 patch_mask = scipy.signal.fftconvolve(patch_mask, np.exp(-patch_indx**2/patch_size**2)*np.exp(-patch_indy**2/patch_size**2)*np.ones((patch_size*2+1, patch_size*2+1)), mode='same') den += scipy.signal.fftconvolve(patch_mask, psf, mode='same') img_patches[:,:,i] = scipy.signal.fftconvolve(img * patch_mask, psf, mode='same') out_img = np.sum(img_patches, axis=2) / (den + 0.000001) return out_img
时间: 2023-06-25 13:06:12 浏览: 107
这是一个生成模糊图像的函数,它使用了Zernike多项式生成PSF(点扩散函数),并将其卷积到图像的小块上,最后将所有小块合并成一个模糊的图像。具体的实现细节包括:
- 根据输入的参数计算每个小块的大小和位置
- 循环生成Zernike系数,用于生成每个小块的PSF
- 将PSF卷积到小块上,并使用卷积的结果计算每个小块的权重
- 将所有小块加权平均得到最终的模糊图像
该函数依赖于一些其他函数,如psfGen()和centroidPsf(),这些函数的作用是生成和处理PSF。
阅读全文