Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience methods for signed distance transform #72

Open
hanslovsky opened this issue Aug 3, 2018 · 1 comment
Open

Convenience methods for signed distance transform #72

hanslovsky opened this issue Aug 3, 2018 · 1 comment

Comments

@hanslovsky
Copy link
Member

With the newly introduced binary distance transform methods (#69, #71), we can now very easily create a signed distance transform (beware: Kotlin!):

private fun <B: BooleanType<B>, T: RealType<T>> signedDistanceTransform(
		mask: RandomAccessibleInterval<B>,
		distanceOutside: RandomAccessibleInterval<T>,
		distanceInside: RandomAccessibleInterval<T>,
		vararg weights: Double = doubleArrayOf(1.0),
		distanceType: DistanceTransform.DISTANCE_TYPE = DistanceTransform.DISTANCE_TYPE.EUCLIDIAN
): RandomAccessibleInterval<T> {
	DistanceTransform.binaryTransform(mask, distanceOutside, distanceType, *weights)
	DistanceTransform.binaryTransform(not(mask), distanceInside, distanceType, *weights)
	val paired= Views.interval(Views.pair(distanceOutside, distanceInside), mask)
	return difference(paired)

}

with helper methods

fun <B: BooleanType<B>> not(mask: RandomAccessibleInterval<B>): RandomAccessibleInterval<B>
{
	return Converters.convert(mask, { s,t -> t.set(!s.get()) }, Util.getTypeFromInterval(mask).createVariable())!!
}

fun<T: RealType<T>> difference(pairs: RandomAccessibleInterval<Pair<T, T>>): RandomAccessibleInterval<T> {
	return Converters.convert(
			pairs,
			{ s,t -> t.set(s.a); t.sub(s.b) },
			Util.getTypeFromInterval(pairs).a.createVariable())!!
}

This will be negative inside the object defined by mask and positive everywhere else.

@axtimwalde
Copy link
Member

Happy to add this once we decided what to do about the fact that this steps from -1 to 1 skipping 0 per definition of the distance transform boundaries being in the boundary pixel and not between boundary pixels (lab discussion, @hanslovsky knows the details). In isotropic spaces, we could probably just subtract 0.5 from all distances which states that the boundary is 0.5px closer to the pixel without making an effort to explain where it is. But this would not work with non-isotropic grids. This means this offset should probably go into the DT algorithm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants