Most efficient way to calculate radial profile

后端 未结 4 1431
误落风尘
误落风尘 2020-12-02 12:32

I need to optimize this part of an image processing application.
It is basically the sum of the pixels binned by their distance from the central spot.

d         


        
4条回答
  •  旧时难觅i
    2020-12-02 13:05

    Taken from a numpy Enhancement Proposal I am working on:

    pp.plot(*group_by(np.round(R, 5).flatten()).mean(data.flatten()))
    

    The call to mean returns the unique values in R, and the mean of corresponding values in data over identical values in R.

    So not quite the same as a histogram based solution; you don't have to remap to a new grid, which is nice if you want to fit a radial profile, without loss of information. Performance should be slightly better than your original solution. Also, standard deviations can be computed with the same efficiency.

    Here is my latest draft numpy group_by EP; not a very concise answer as such, but a very general one. I hope we can all agree numpy needs something like np.group_by(keys).reduce(values); if you have any feedback, it would be welcome.

提交回复
热议问题