Closed nberliner closed 9 years ago
One way around this issue would be to directly calculate the curvature from the triangle that is spanned by the points along the path (see here for some math refresher). This would look something like this: and should give the exact values for each point. I am unsure however if we will need to add some smoothing after curvature calculation (some form is already implemented and should be easy to adapt).
I looked into it a bit more and with the proposed method above the edge still is not well defined. In addition, and more problematic, we would loose the information about the sign of the curvature.
Hence, instead of using the above method I switched to np.gradient()
to calculate the derivatives (previously this was done using gaussian_filter1d()
and continue to use the local curvature expression . The edges will still be problematic but much less so compared to the gaussian_filter1d()
method. See below for a test done on simulated data on a half-circle with radius 5.
I fixed another problem with displaying the curvature values and the curvature looks now fine to me. I will close this issue for now.
Note: so far the curvature color coding was recalculated for every contour segment, i.e. the maximum and minimum values defining the color spectrum were reset every time. This makes the plots not comparable between each other since the displayed colors do not correspond to the same curvature values. This is now fixed and the same color coding is used for all plots.
The current implementation of curvature calculation uses the local curvature expression. Calculation of the derivatives is done exploiting the fact that
(f*g)'= f'*g = f*g'
with*
the convolution (see wikipedia and stackoverflow). This however implicates that we are not calculating the derivative of our function but of the function convolved with a gaussian.In general this might work fine for many data points, whereas smoothing might become problematic for low sampling or few datapoints with significant edge contributions. As an example I generate points on a half circle with radius 5 and plotted the calculated curvature at each point. Towards the edges of the path the radii values are deviating significantly from the true value!
This plot can be generated using the following code: