Hi Gleb
I thought a bit more about how to speed up calculating the radial profiles. At the moment, you have a triple loop, the outer loops goes through the grid of radius values, the inner two loops through the pixels of the image. We should turn this around, as I show below.
Input:
abs(x) < 1
Output:
with .
First the naive form. We simply swap the loops. For this, we need to calculate numerator and denominator of res[i] separately and divide only at the end.
Now have a look at the inner loop: For most of the values of r, w will be zero, and we could skip all those itertaions of the loop.
In fact, we already know before entering the loop that w can only be nonzero if
abs( r - d ) < s
. Therefore, the innermost loop has to run only from d-s
to d+s
This reduces run-time by a factor of rmax/(2*s)
, which may well by around 100.