sum_angle() and sum_polar() functions

Hello, I submitted two functions to numpy that sum 2d matrices along angled cartesian or polar coordinates. https://github.com/numpy/numpy/pull/230 The two functions certainly have their main application in image processing and might be better suited for scipy of scikits-image. sum_angle() is not much more than the old scipy.misc.pilutils.radon() transform. But the later is deprecated and has several problems (floats, non-conserved sum(), interpolation, speed) as discussed in the pull request. The new scikits-image.transform.radon() appears to be more generic but a bit complicated and potentially even slower than the imrotate()-based version in scipy. Could sum_angle() and sum_polar() find a place in scipy or scikits-image or are they simple enough to be useful for numpy? -- Robert Jordens.

On Mon, May 21, 2012 at 6:50 AM, Robert Jördens <jordens@gmail.com> wrote:
Hello, I submitted two functions to numpy that sum 2d matrices along angled cartesian or polar coordinates. https://github.com/numpy/numpy/pull/230 The two functions certainly have their main application in image processing and might be better suited for scipy of scikits-image.
sum_angle() is not much more than the old scipy.misc.pilutils.radon() transform. But the later is deprecated and has several problems (floats, non-conserved sum(), interpolation, speed) as discussed in the pull request.
The new scikits-image.transform.radon() appears to be more generic but a bit complicated and potentially even slower than the imrotate()-based version in scipy.
Could you time the scikits-image version, it's not obvious from reading the code that it will be very slow?
Could sum_angle() and sum_polar() find a place in scipy or scikits-image or are they simple enough to be useful for numpy?
My impression is that it would fit best in scikits-image. Perhaps ndimage would be a reasonable place too. It's too specialized for numpy imho. Ralf

On Mon, May 21, 2012 at 1:16 AM, Ralf Gommers <ralf.gommers@googlemail.com> wrote:
Could you time the scikits-image version, it's not obvious from reading the code that it will be very slow?
In [47]: from scipy.misc.pilutil import radon as scipy_radon In [50]: from skimage.transform import radon as scikits_radon In [46]: a=np.random.randn(1000, 1000) In [53]: angle_sum(a, .1).shape Out[53]: (1100,) In [54]: scikits_radon(a, [.1]).shape Out[54]: (1415, 1) In [55]: scipy_radon(a, [.1]).shape Out[55]: (1000, 1) In [56]: %timeit angle_sum(a, .1) 10 loops, best of 3: 24.7 ms per loop In [57]: %timeit scikits_radon(a, [.1]) 10 loops, best of 3: 136 ms per loop In [58]: %timeit scipy_radon(a, [.1]) 10 loops, best of 3: 47.6 ms per loop In [59]: a.sum() Out[59]: -682.83728184031156 In [60]: angle_sum(a, .1).sum() Out[60]: -682.83728184032327 In [61]: scikits_radon(a, [.1]).sum() Out[61]: -682.83727334014043 In [62]: scipy_radon(a, [.1]).sum() Out[62]: 124316062.0
My impression is that it would fit best in scikits-image. Perhaps ndimage would be a reasonable place too. It's too specialized for numpy imho.
angle_sum() at least can be applied beyond image processing in the analysis of coupling matrices or adjacency graphs. Both functions are simple and generic. -- Robert Jordens.

On Mon, May 21, 2012 at 2:06 AM, Robert Jördens <jordens@gmail.com> wrote:
Could you time the scikits-image version, it's not obvious from reading
On Mon, May 21, 2012 at 1:16 AM, Ralf Gommers <ralf.gommers@googlemail.com> wrote: the
code that it will be very slow?
In [47]: from scipy.misc.pilutil import radon as scipy_radon In [50]: from skimage.transform import radon as scikits_radon
In [46]: a=np.random.randn(1000, 1000)
In [53]: angle_sum(a, .1).shape Out[53]: (1100,)
In [54]: scikits_radon(a, [.1]).shape Out[54]: (1415, 1)
In [55]: scipy_radon(a, [.1]).shape Out[55]: (1000, 1)
In [56]: %timeit angle_sum(a, .1) 10 loops, best of 3: 24.7 ms per loop
In [57]: %timeit scikits_radon(a, [.1]) 10 loops, best of 3: 136 ms per loop
In [58]: %timeit scipy_radon(a, [.1]) 10 loops, best of 3: 47.6 ms per loop
In [59]: a.sum() Out[59]: -682.83728184031156
In [60]: angle_sum(a, .1).sum() Out[60]: -682.83728184032327
In [61]: scikits_radon(a, [.1]).sum() Out[61]: -682.83727334014043
In [62]: scipy_radon(a, [.1]).sum() Out[62]: 124316062.0
My impression is that it would fit best in scikits-image. Perhaps ndimage would be a reasonable place too. It's too specialized for numpy imho.
angle_sum() at least can be applied beyond image processing in the analysis of coupling matrices or adjacency graphs. Both functions are simple and generic.
Looks like you need to sell this as a faster Radon or Hough, angle_sum is a bit too generic ;) Chuck

On Mon, May 21, 2012 at 1:06 AM, Robert Jördens <jordens@gmail.com> wrote:
On Mon, May 21, 2012 at 1:16 AM, Ralf Gommers <ralf.gommers@googlemail.com> wrote:
Could you time the scikits-image version, it's not obvious from reading the code that it will be very slow?
In [47]: from scipy.misc.pilutil import radon as scipy_radon In [50]: from skimage.transform import radon as scikits_radon
Looking at this again, I don't think the comparison is accurate. The skimage version of the radon transform does linear interpolation, whereas sum_angle uses the nearest neighbor. Stéfan

On Wed, May 23, 2012 at 5:41 PM, Stéfan van der Walt <stefan@sun.ac.za> wrote:
Looking at this again, I don't think the comparison is accurate. The skimage version of the radon transform does linear interpolation, whereas sum_angle uses the nearest neighbor.
Point taken. IDL and some other toolkits I had a look at defaulted to nearest neighbor. It might be good to have the option of choosing the interpolation method in skimage. -- Robert Jordens.

On Tue, May 29, 2012 at 4:17 PM, Robert Jördens <jordens@gmail.com> wrote:
Point taken. IDL and some other toolkits I had a look at defaulted to nearest neighbor. It might be good to have the option of choosing the interpolation method in skimage.
At the moment we make use of an accelerated linear interpolation routine to speed things up, but we could default to ndimage for higher orders--it'll just be quite a bit slower. Stéfan
participants (4)
-
Charles R Harris
-
Ralf Gommers
-
Robert Jördens
-
Stéfan van der Walt