1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python

import Image
import numpy
import numpy.ma
import scipy.optimize
import pylab
import matplotlib.cm

y = numpy.load("data.npy")
data = numpy.sqrt( (y[0,:,:]-y[2,:,:])**2 + (y[1,:,:]-y[3,:,:])**2 )
data2 = data / data.max() * 255

im = Image.fromarray(data2.astype("uint8"),"L")
im.save("mask_2D_preedit.png")

# Now you should have edited the image with GIMP and
# saved your mask as 'mask_2D_postedit.png'.

maskim = Image.open("mask_2D_postedit.png")
mask = numpy.array(maskim.getdata()).reshape((1024,1024))
data2 = numpy.ma.masked_array(data,mask)

# Now you got a masked array without any disturbing
# elements for further treatment.

pylab.figure(figsize=(12,6))
pylab.subplot(121)
pylab.imshow(data,cmap=matplotlib.cm.spectral)
pylab.colorbar(orientation="horizontal")

pylab.subplot(122)
pylab.imshow(data2,cmap=matplotlib.cm.spectral)
pylab.colorbar(orientation="horizontal")

pylab.show()