image processing in sage
Dear all,
I have problems to call scipy.ndimage.binary_opening
. Code, output and error messages in sage are as follows...
SAGE:
from numpy import *
import scipy.ndimage
import matplotlib.image
import matplotlib.pyplot
img=matplotlib.image.imread(DATA+'NbW-STEM.png')
type(img)
print "Image dtype: %s"%(img.dtype)
print "Image size: %6d"%(img.size)
print "Image shape: %3dx%3d"%(img.shape[0],img.shape[1])
print "Max value %1.2f at pixel %6d"%(img.max(),img.argmax())
print "Min value %1.2f at pixel %6d"%(img.min(),img.argmin())
print "Variance: %1.5f\nStandard deviation: %1.5f"%(img.var(),img.std())
OUTPUT:
Image dtype: float32
Image size: 261075
Image shape: 295x295
Max value 1.00 at pixel 226320
Min value 0.00 at pixel 17109
Variance: 0.02580
Standard deviation: 0.16062
SAGE:
BWatoms=img>0.62
BWatoms=scipy.ndimage.binary_opening(BWatoms,structure=ones((2,2)))
ERROR MESSAGE:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_27.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("QldhdG9tcz1pbWc+MC42MgpCV2F0b21zPXNjaXB5Lm5kaW1hZ2UuYmluYXJ5X29wZW5pbmcoQldhdG9tcyxzdHJ1Y3R1cmU9b25lcygoMiwyKSkp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpaXpo0G/___code___.py", line 4, in <module>
exec compile(u'BWatoms=scipy.ndimage.binary_opening(BWatoms,structure=ones((_sage_const_2 ,_sage_const_2 )))
File "", line 1, in <module>
File "/home/ottom/Documents/sage_build/sage-4.6.1/local/lib/python2.6/site-packages/scipy/ndimage/morphology.py", line 646, in binary_opening
origin)
File "/home/ottom/Documents/sage_build/sage-4.6.1/local/lib/python2.6/site-packages/scipy/ndimage/morphology.py", line 394, in binary_erosion
output, border_value, origin, 0, brute_force)
File "/home/ottom/Documents/sage_build/sage-4.6.1/local/lib/python2.6/site-packages/scipy/ndimage/morphology.py", line 229, in _binary_erosion
raise RuntimeError, 'structure rank must equal input rank'
RuntimeError: structure rank must equal input rank
This code was also tested on the sage-online server (alpha), which failed as well. The code worked fine with Enthought 6.2-2 (pylab-mode). Any suggestions are welcome.
All the best
Otto