, ... , :
- numpy
out, . . np.sqrt(x, x) . x += 1 , x = x + 1, . , *=, +=, /= .. , numexpr, @eumiro. ( numexpr ... .)
, -, 10000x10000 filtsize 3:

- . numpy.select(...). , , , , select.
, ( ) , :
import numpy
import scipy.ndimage
def main(x=None):
if x is None:
ni, nj = 10000, 10000
x = numpy.arange(ni*nj, dtype=numpy.float32).reshape(ni,nj)
filtsize = 3
nlooks = 10.0
dfactor = 10.0
x = enh_lee(x, filtsize, nlooks, dfactor)
return x
def moving_average(Ic, filtsize):
Im = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(Ic, filtsize, output=Im)
return Im
def moving_stddev(Ic, filtsize):
Im = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(Ic, filtsize, output=Im)
Im *= -1
Im += Ic
Im **= 2
scipy.ndimage.filters.uniform_filter(Im, filtsize, output=Im)
return numpy.sqrt(Im, Im)
def enh_lee(Ic, filtsize, nlooks, dfactor):
Ci = moving_stddev(Ic, filtsize)
Im = moving_average(Ic, filtsize)
Ci /= Im
Cu = numpy.sqrt(1 / nlooks).astype(numpy.float32)
Cmax = numpy.sqrt(1 + (2 * nlooks)).astype(numpy.float32)
W = Ci.copy()
W -= Cu
W *= -dfactor
W /= Cmax - Ci
W = numpy.exp(W, W)
If = Im * W
W *= -1
W += 1
W *= Ic
If += W
del W
out = If
filter = Ci <= Cu
numpy.putmask(out, filter, Im)
del Im
filter = Ci >= Cmax
numpy.putmask(out, filter, Ic)
return out
if __name__ == '__main__':
main()
:

, , (i.m.o.).
numpy.where...
numpy.where out, ~ 300 . , , ...
numpy.putmask numpy.select ( @eumiro .)
numexpr, ( pure-numpy , ). , ... numexpr, .
import numpy
import scipy.ndimage
import numexpr as ne
def main(x=None):
if x is None:
ni, nj = 10000, 10000
x = numpy.arange(ni*nj, dtype=numpy.float32).reshape(ni,nj)
filtsize = 3
nlooks = 10.0
dfactor = 10.0
x = enh_lee(x, filtsize, nlooks, dfactor)
return x
def moving_average(Ic, filtsize):
Im = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(Ic, filtsize, output=Im)
return Im
def moving_stddev(Ic, filtsize):
Im = numpy.empty(Ic.shape, dtype='Float32')
scipy.ndimage.filters.uniform_filter(Ic, filtsize, output=Im)
Im = ne.evaluate('((Ic-Im) ** 2)')
scipy.ndimage.filters.uniform_filter(Im, filtsize, output=Im)
return ne.evaluate('sqrt(Im)')
def enh_lee(Ic, filtsize, nlooks, dfactor):
Ci = moving_stddev(Ic, filtsize)
Im = moving_average(Ic, filtsize)
Ci /= Im
Cu = numpy.sqrt(1 / nlooks).astype(numpy.float32)
Cmax = numpy.sqrt(1 + (2 * nlooks)).astype(numpy.float32)
W = ne.evaluate('exp(-dfactor * (Ci - Cu) / (Cmax - Ci))')
If = ne.evaluate('Im * W + Ic * (1 - W)')
del W
out = ne.evaluate('where(Ci <= Cu, Im, If)')
del Im
del If
out = ne.evaluate('where(Ci >= Cmax, Ic, out)')
return out
if __name__ == '__main__':
main()
numexpr: ( , !)
Numexpr *

- where ( select). . - select . cython ( , numpy ). , , , ...
, , . numpy ...