python,numpy,scipy,python-2.6,ndimage

A belated thanks to both Jaime and Kazemakase for their replies. The manual neighbour-checking method did remove all isolated patches, but also removed patches attached to others by one corner (i.e. to the upper-right of the square in the sample array). The summed area table works perfectly and is very...

python,image-processing,numpy,scipy,ndimage

The generic_filter expects myfunc to return a scalar, never a vector. However, there is nothing that precludes myfunc from also adding information to, say, a list which is passed to myfunc as an extra argument. Instead of using the array returned by generic_filter, we can generate our vector-valued array by...

python,image-processing,scipy,ndimage

I'm pretty sure you're counting the white pixels rather than the black pixels. Try inverting the image and then count.

python-2.7,numpy,scipy,filtering,ndimage

This worked for me. There were a couple little problems with the code: import scipy.ndimage.filters import numpy as np Array = rand( 100,100 ) def Func(a): a = a.reshape((3,3)) weights = np.array([[0.5,.05,0.5],[0.5,1,0.5],[0.5,0.5,0.5]]) a = np.multiply(a,weights) a = np.sum(a) return a out = scipy.ndimage.filters.generic_filter(Array,Func,footprint=np.ones((3,3)),mode='constant',cval=0.0,origin=0.0) You had a = np.reshape( (3,3) )...

You can investigate this error by putting a print statement in modal: def modal(arr): print(arr) return np.argmax(np.bincount(arr.flatten())) You'll see output like [ 92. 92. 31. 92. 92. 31. 87. 87. 18.] which shows that arr contains floats, not ints. The documentation for np.bincount states its first argument must be a...

python,memory,numpy,scipy,ndimage

It's not that the correlation operator is slow, but rather that your problem is very large. The direct correlation (or convolution) of a 3D array of size N by a kernel of size n involves, roughlyN**3*(2*n**3) floating point operations. So with a fairly recent CPU at 10 GFLOP per core,...