Closed constantinpape closed 1 month ago
Something like this should work if you have the coordinates for the two spline - x_spline1 = np.array([x_coordinates of spline 1]) , shape: (N,) x_spline2 = np.array([... spline 2]) , shape: (N,)
x_dist = x_spline1[:, None] - x_spline2[None, :] similarly for y coordinate y_dist = y_spline1[:,None] - y_spline2[None,:]
(Euclidean) distance dist = np.sqrt(x_dist^2+y_dist^2) (N,N)
take any measure on it, for example the minimum min_dist = np.min(dist)
Above matrices (x_dist, y_dist) are skew symmetric. Can probably be made more efficient by just considering the upper or the lower triangle of them.
Sorry if my response was unwarranted/uninvited.
Hi Constantin,
Thanks a lot for your question!
Sorry we do not have a functionality to measure the distance between two splines, mostly because the library is (currently at least) "spline-intrinsic" while that would require to be "spline-extrinsic". More precisely, the library implements spline curves as parametric objects and provides all sorts of operations in their own parametric space (including drawing itself), but does not implement operation between spline objects in the ambient space where they live - which is what you would need to be able to tell how far apart two of them are (since the very notion of distance here is related to the surrounding space, not the spline themselves). Does that make sense?
That said, it may be something we want to add at some point along with other extrinsic measurements. Right now, one way to go to measure this would be to sample each spline, retrieve the coordinates of the samples for each, and calculate the Wasserstein distance between the two point sets.
Hello @constantinpape ,
As @vuhlmann mentioned we don't have any functions that operate on multiple splines (yet). However, I would be interested to implement it as an example for now. If I understand correctly, you want a distance measurement with sub-pixel accuracy without limiting the minimization to discrete steps.
I think minimizing the distance as a function of the parameters of the two splines should work. We might also be able to use a perpendicularity constraint.
Another possible approach could be to fit a level set to your masks or to initialize a level set based on a spline.
Thanks for the feedback, everyone.
@faymanns :
However, I would be interested to implement it as an example for now.
That would be great! I'd be happy to give this a try once it is there.
If I understand correctly, you want a distance measurement with sub-pixel accuracy without limiting the minimization to discrete steps.
Yes, exactly.
In the meantime, I will see if fitting splines to our segmented objects works as expected.
I have create a first draft for the example in 8ec82a8.
To see the plots you can have a look at this hidden build of the docs.
Thanks for the example @faymanns! This does exactly what I would need.
Unfortunately my active contours don't quite behave yet ;) :
I assume this is due to some coordinate system switch. I am busy with some other things now, but will come back to this as soon as I have time.
In any case, the distance measurement example works as expected!
Happy to hear that it is what you need, @constantinpape .
The objects you are trying to fit look pretty circular, I think an exponential spline with relatively few knots might work well. Do you agree @vuhlmann?
I added the example to the main website (#31).
I will close the issue for now, but feel free to reopen it or open a new one if the active contours still doesn't work.
Hi all,
first of all thanks for making this available, it looks very useful!
Is there functionality to measure the distance between two splines in
splinebox
/ is there an easy way to implement this? In particular, I would want to measure the minimal distance between the splines, but having other distance measures (e.g. percentiles in the distance integral) would also be of interest.For some context, we are interested in measuring the distances between segmented objects. We are currently doing this using an euclidean distance transform in the pixel / voxel grid, which however can lead to inaccuracies due to incorrect boundary placement of the segmentation and discretization artifacts. An alternatively would be fitting a spline to each object (initializing it with the segmentation mask and then fitting to the local membrane, inspired by the active contour example) and then measuring the distance between the fitted splines.