def wiener(image, psf, balance, reg=None, is_real=True, clip=True):
 if (reg is None):
  (reg, _) = uft.laplacian(image.ndim, image.shape, is_real=is_real)
 if (not np.iscomplexobj(reg)):
  reg = uft.ir2tf(reg, image.shape, is_real=is_real)
 if (psf.shape != reg.shape):
  trans_func = uft.ir2tf(psf, image.shape, is_real=is_real)
 else:
  trans_func = psf
 wiener_filter = (np.conj(trans_func) / ((np.abs(trans_func) ** 2) + (balance * (np.abs(reg) ** 2))))
 if is_real:
  deconv = uft.uirfft2((wiener_filter * uft.urfft2(image)), shape=image.shape)
 else:
  deconv = uft.uifft2((wiener_filter * uft.ufft2(image)))
 if clip:
  deconv[(deconv > 1)] = 1
  deconv[(deconv < (-1))] = (-1)
 return deconv

def wiener ( image , psf , balance , reg = None , is_real = True , clip = True ) : if ( reg is None ) : ( reg , _ ) = uft . laplacian ( image . ndim , image . shape , is_real = is_real ) if ( not np . iscomplexobj ( reg ) ) : reg = uft . ir2tf ( reg , image . shape , is_real = is_real ) if ( psf . shape != reg . shape ) : trans_func = uft . ir2tf ( psf , image . shape , is_real = is_real ) else : trans_func = psf wiener_filter = ( np . conj ( trans_func ) / ( ( np . abs ( trans_func ) ** 2 ) + ( balance * ( np . abs ( reg ) ** 2 ) ) ) ) if is_real : deconv = uft . uirfft2 ( ( wiener_filter * uft . urfft2 ( image ) ) , shape = image . shape ) else : deconv = uft . uifft2 ( ( wiener_filter * uft . ufft2 ( image ) ) ) if clip : deconv [ ( deconv > 1 ) ] = 1 deconv [ ( deconv < ( - 1 ) ) ] = ( - 1 ) return deconv
minimum mean square error inverse filter .