Narrow band feature request

26 views
Skip to first unread message

Adrian Butscher

unread,
Feb 23, 2016, 1:15:57 PM2/23/16
to scikit-fmm
Hi,

I am currently using skfmm to construct distance functions from level set functions on large grids.  However, I only need the distance values in a narrow band (size of my choosing) around the zero contour of the level set function.  Is there a way to use the current code to stop the computation of the distance values when the value inside the NEAR region reach, say 1.1 times the bandwidth? The output should then be an array the size of the grid, with the correct distance values at the grid points in the narrow band and equal to +/- the band width distance everywhere else (depending on if inside or outside the zero contour of the level set function).  If not, would it be possible to offer some guidance on where to modify the C++ code to achieve something along these lines?  (I am not a C++ coder alas.)

Many thanks.

Adrian Butscher

Jason Furtney

unread,
Feb 23, 2016, 1:36:58 PM2/23/16
to sciki...@googlegroups.com
Dear Adrian Butscher,

Thanks for getting in touch, this is a useful feature and should not
be too difficult to add. There is no way to do this currently.

When you say " 1.1 times the bandwidth" how are you defining bandwidth?

I think we would do this by making a small change in base_marcher.cpp
in the baseMarcher::solve method. On line 125 we are freezing a point,
here we could check if this criteria is met and return early. Some
changes will need to be made in the Python wrapper that calls the c++
code to add an optional argument.

I should be able to get to it this week.

Thanks,
Jason
> --
> You received this message because you are subscribed to the Google Groups
> "scikit-fmm" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scikit-fmm+...@googlegroups.com.
> To post to this group, send email to sciki...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/scikit-fmm/30ce288d-408c-4aaf-8b99-a3a6a225528c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Adrian Butscher

unread,
Feb 23, 2016, 1:56:17 PM2/23/16
to sciki...@googlegroups.com
Thank you for your very fast reply.  I'm also very happy that you'll get this feature working so soon.

I imagine that bandwidth is a user-specified parameter and let ZC be the zero-contour of the level set function we're trying to process.  If the bandwidth is set to L then the algorithm will accurately compute distance values at the gridpoints contained in the region 

{ x \in R^d : distance(x, ZC) <= L }

and output +/- L at the remaining gridpoints of the grid, with sign determined by which side of the zero-contour the gridpoint is on. (And the business with the 1.1 was simply this: perhaps for safety one would want accurate values in the above region with L replaced by 1.1*L, depending on how the NEAR and ACTIVE gridpoints are processed by the fast-marching algorithm.)

Does this make sense?

Adrian



You received this message because you are subscribed to a topic in the Google Groups "scikit-fmm" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scikit-fmm/JdC1xKDq5rc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scikit-fmm+...@googlegroups.com.

To post to this group, send email to sciki...@googlegroups.com.

Jason Furtney

unread,
Feb 23, 2016, 2:54:15 PM2/23/16
to sciki...@googlegroups.com
Here is a branch on github which is a start.

https://github.com/scikit-fmm/scikit-fmm/tree/narrow

Now skfmm.distance() will accept an optional narrow keyword argument
which is the length scale of the narrow band. The return value will be
a masked array if there are points beyond the narrow band.

I have only tested this in 1D:

In [1]: import skfmm
In [2]: phi=[-1,-1,-1,1,1,1]
In [3]: skfmm.distance(phi, narrow=1.0)
masked_array(data = [-- -- -0.5 0.5 -- --],
mask = [ True True False False True True],
fill_value = 1e+20)

I am off for today but can return to this tomorrow. Some clean up,
documentation and testing is needed.

On Tue, Feb 23, 2016 at 12:56 PM, Adrian Butscher
> https://groups.google.com/d/msgid/scikit-fmm/CABPx5hEE1YXU1pWXa64qOxKsJVAhr0%3D7AkmdC%3DUM1JcR9UcLEQ%40mail.gmail.com.

Adrian Butscher

unread,
Feb 23, 2016, 3:13:36 PM2/23/16
to sciki...@googlegroups.com

Jason Furtney

unread,
Feb 25, 2016, 5:22:50 PM2/25/16
to sciki...@googlegroups.com
I added more testing and documentation to the github branch.
https://github.com/scikit-fmm/scikit-fmm/tree/narrow

As currently written, the narrow parameter is actually half the bandwidth.

Values of the narrow parameter smaller than the grid spacing (which
defaults 1) will result in extra points getting into the narrow band.
This is probably not a bid deal.

I decided it makes the most sense to return a masked array where the
points outside the narrow band are masked off. The mask is only added
if there are points outside the narrowband or if the input is a masked
array.

If you need a signed constant distance outside the narrowband you
could do something like this:

import numpy as np
from skfmm import distance
N = 50
X, Y = np.meshgrid(np.linspace(-1, 1, N), np.linspace(-1, 1, N))
r = 0.5
dx = 2.0 / (N - 1)
phi = (X) ** 2 + (Y) ** 2 - r ** 2
bandwidth = 4*dx
d = distance(phi, dx, narrow=bandwidth)
d.data[d.mask]=np.sign(phi[d.mask])*bandwidth
d=d.data

Could you test this on your application? If everything looks OK I will
push out a release.

Thanks,
Jason


On Tue, Feb 23, 2016 at 2:13 PM, Adrian Butscher
> https://groups.google.com/d/msgid/scikit-fmm/CABPx5hHgGrhfymuRiE5O4kB%2BY7WbPqmu_mTJtJvykcdS7CPQNg%40mail.gmail.com.

Adrian Butscher

unread,
Feb 25, 2016, 6:14:19 PM2/25/16
to sciki...@googlegroups.com
I've done a bit of testing already (I did this today at roughly 11 AM --- when I downloaded the code from GIT).  So far so good.  I'll do a bit more testing along the lines you suggest and I'll get back to you ASAP.

Thanks.

Adrian


Adrian Butscher

unread,
Feb 28, 2016, 11:18:56 PM2/28/16
to sciki...@googlegroups.com
Hi Jason,

Everything checks out on my end regarding the narrow band feature, as far as I can tell.  Thanks again for working on this for me, and so quickly.  I appreciate your efforts.

Adrian
Reply all
Reply to author
Forward
0 new messages