Skip to content

bspline interpolation #86

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

Merged
merged 15 commits into from
Sep 14, 2020
Merged

Conversation

bogovicj
Copy link
Contributor

@bogovicj bogovicj commented Jun 25, 2020

@axtimwalde @tpietzsch

This pull request adds two kinds of BSpline interpolation.

1) On the fly interpolation

The first is most similar to current interpolation methods:

int splineOrder;
boolean clipping;
int radius;
realImg = Views.interpolate( img, new BSplineInterpolatorFactory<>( splineOrder, clipping, radius ));

This computes the interpolation kernel on-the-fly at every get. The kernel size is defined by radius. clipping=true sets the interpolator to behave like the ClampingNLinearInterpolator

2) Precomputed coefficients

The second method precomputes BSpline coefficients and is substantially faster if get is called many times, but at the cost of memory - it allocates a RandomAccessibleInterval<T> the same size as the image to be interpolated. T defaults to DoubleType. Use it like this:

int splineOrder;
boolean clipping;
factory= new BSplineCoefficientsInterpolatorFactory<>( img, splineOrder, clipping );
realImg = Views.interpolate( img, factory);

here the factory constructor computes the coefficients - which is why it needs to be passed. Unfortunately, this means that the img argument to Views.interpolate is meaningless. For example,

realImgFoo = Views.interpolate( img, factory);
realImgBar = Views.interpolate( someOtherImg, factory);

both result in the same thing. We stuck with this to keep the api consistent. No one should be doing the bottom thing anyway.

Generating the coefficients

BSplineDecomposition and BSplineCoefficientsInterpolator give more control for those who need it.
For example

/*
 * Compute the coefficients over an arbitrary interval 
 */
BSplineDecomposition<T,S> decomp = new BSplineDecomposition<>( splineOrder,, extendedImg );
long[] min = Intervals.minAsLongArray( interval );
Img<S> coefficientsBase = coefficientFactory.create( interval );
coefficients = Views.translate( coefficientsBase, min );
decomp.accept( coefficients );

/*
 * Get a RealRandomAccess that uses the spline coefficients computed above
 * and using a custom extension of the coefficients
 */
RealRandomAccess interp = BSplineCoefficientsInterpolator.build( 
     splineOrder, 
     Views.extendMirrorSingle( coefficients), 
     new FloatType());

* on-the-fly bspline interpolation
* bspline interpolation with precomputed coefficients
* bspline orders 0-5 inclusive

use bspline factory in test
@bogovicj
Copy link
Contributor Author

Note: don't merge this quite yet, I'm going to add methodology to lazily compute the coefficients block-wise on demand.

@tpietzsch
Copy link
Member

Note: don't merge this quite yet, I'm going to add methodology to lazily compute the coefficients block-wise on demand.

You can mark the PR as a draft while you work on it.
Then it cannot be merged yet.
It's on the right side in the Reviewers tab

Screenshot 2020-06-26 at 11 31 07

@bogovicj bogovicj marked this pull request as draft June 26, 2020 13:19
bogovicj added 2 commits June 26, 2020 10:10
* depend on imglib2-cache
* add some benchmarks
@bogovicj
Copy link
Contributor Author

@axtimwalde
From the hotknife repo, I moved org.janelia.saalfeldlab.hotknife.util.Lazy to net.imglib2.lazy.Lazy, removing some of the Ops- related methods

@bogovicj bogovicj marked this pull request as ready for review June 29, 2020 15:42
@bogovicj
Copy link
Contributor Author

TODO - make all added packages children of net.imglib2.algorithm

Copy link
Member

@axtimwalde axtimwalde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am all for merging this in the algorithms package until ImgLib2 core includes imglib2-cache and something like Lazy. Some left-overs and TODOs from testing should be removed or moved into tests.

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/planned-dev-nonlinear-elastix-imglib2-transforms-feedback-requested/31767/22

@axtimwalde axtimwalde merged commit 14a708f into imglib:master Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants