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
There is a function in PyDIP that does just this: dip.RadialMean. You can use it in a similar way to OP's radial_profile
function:
import PyDIP as dip
img = dip.ImageReadTIFF('crop.tif')
# center, radi = find_centroid(img)
center, radi = (509, 546), 55
rad = dip.RadialMean(img, binSize=1, center=center)
rad[radi:].Show()
Disclaimer: I'm an author of PyDIP and the DIPlib library.