def wiener(im, mysize=None, noise=None):
im = asarray(im)<EOL>if mysize is None:<EOL><INDENT>mysize = [<NUM_LIT:3>] * len(im.shape)<EOL><DEDENT>mysize = asarray(mysize)<EOL>if mysize.shape == ():<EOL><INDENT>mysize = np.repeat(mysize.item(), im.ndim)<EOL><DEDENT>lMean = correlate(im, ones(mysize), '<STR_LIT>') / product(mysize, axis=<NUM_LIT:0>)<EOL>lVar = (correlate(im ** <NUM_LIT:2>, ones(mysize), '<STR_LIT>') / product(mysize, axis=<NUM_LIT:0>)<EOL>- lMean ** <NUM_LIT:2>)<EOL>if noise is None:<EOL><INDENT>noise = mean(ravel(lVar), axis=<NUM_LIT:0>)<EOL><DEDENT>res = (im - lMean)<EOL>res *= (<NUM_LIT:1> - noise / lVar)<EOL>res += lMean<EOL>out = where(lVar < noise, lMean, res)<EOL>return out<EOL>
Perform a Wiener filter on an N-dimensional array.

Apply a Wiener filter to the N-dimensional array `im`.

Parameters
----------
im : ndarray
    An N-dimensional array.
mysize : int or arraylike, optional
    A scalar or an N-length list giving the size of the Wiener filter
    window in each dimension.  Elements of mysize should be odd.
    If mysize is a scalar, then this scalar is used as the size
    in each dimension.
noise : float, optional
    The noise-power to use. If None, then noise is estimated as the
    average of the local variance of the input.

Returns
-------
out : ndarray
    Wiener filtered result with the same shape as `im`.