ENH: add sum_angle() and sum_polar() functions to twodim_base.py #230

Open
wants to merge 1 commit into
from

5 participants

@jordens

sum_angle() computes the sum of a 2-d array along an angled axis
sum_polar() along radial lines or along azimuthal circles

@jordens jordens add sum_angle() and sum_polar() functions.
sum_angle() computes the sum of a 2-d array along an angled axis
sum_polar() along radial lines or along azimuthal circles
ba7766e
@rgommers
NumPy member

Hi @jordens, I can see how this would be useful, but adding new functions should really be discussed on the numpy-discussion mailing list first. Could you please bring it up there?

@charris charris commented on the diff May 21, 2012
numpy/lib/twodim_base.py
+
+
+def sum_angle(m, angle, aspect=1., binsize=None):
+ """
+ Compute the sum of a 2-d array along an rotated axis.
+
+ Parameters
+ ----------
+ m : array_like, shape(N, M)
+ 2-d input array to be summed
+ angle : float
+ The angle of the summation direction defined such that:
+ ``sum_angle(m, angle=0) == sum(m, axis=0)``
+ ``sum_angle(m, angle=pi/2) == sum(m, axis=1)``
+ aspect : float, optional
+ The input bin aspect ratio (second dimension/first dimension)
@charris
NumPy member
charris added a line comment May 21, 2012

Dimension or component?

@jordens
jordens added a line comment May 21, 2012

Dimension. Or I don`t understand what you mean by component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@charris
NumPy member

Correct me if I am wrong, but this looks like it is intended to work on images. Is that the case?

@jordens

Images are certainly a major application. But this is also interesting in the analysis of matrices that represent graphs.

@charris
NumPy member

I was asking because I thought this might be more appropriate for one of the image processing packages. In particular, it seems related to the Hough transform. I assume the application to graphs uses the adjacency matrix. In any case, it might be worth putting up a post on the scipy mailing list as well as here since that is where graph and image algorithms are located.

@teoliphant
NumPy member

The sum_angle function seems equivalent to the scipy.misc.radon function which is deprecated (but a very useful function). Because your implementation is so straightforward and well documented it could be useful in NumPy as well, but I agree with Chuck that you should ask on the SciPy list as well.

@jordens

Yes. angle_sum is a Hough or Radon transform. The implementation in scipy has a couple of problems: It is based on PIL and does not seem to work with floats. It does not conserve the sum over all entries (independent of padding...). Finally, the interpolations used in PIL do not really make sense in this application. It is also 40% slower than this one.

Scikits-image has taken the radon transform from scipy: https://github.com/scikits-image/scikits-image/blob/master/skimage/transform/radon_transform.py I believe that one does not suffer the problems the PIL-based one has. But it looks even slower.

I'll raise this on the scipy/scikits list.

@stefanv

@jordens Could we use your sum_angle in scikits-image? I'd love to improve the execution speed of the radon and hough transforms (actually, I think the hough tf already uses the bincount trick, so it may not benefit). Perhaps you would be interested in working on a PR together?

@jordens

@stefanv Sure. Feel free. I will help if I can find the time.

OTOH I would still love to see these added to numpy and agree with Travis' reasoning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment