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

Add 3rd and 4th order convergent cubic convolution interpolation methods with continuous first derivates in any number of dimensions, including extrapolation support #602

Closed
wants to merge 8 commits into from

Conversation

NikoBiele
Copy link

@NikoBiele NikoBiele commented Aug 27, 2024

Hi interpolators!

I noticed there had been a wish for gridded spline interpolations for a while.
I do not know how to accomplish gridded spline interpolations, but I had an implementation of a cubic convolution algorithm which I have translated. It implements "Cubic Convolution Interpolation for Digital Image
Processing" by Robert G. Keys (1981) IEEE Transactions On Acoustics, Speech, And Signal Processing, vol. ASSP-29, no. 6, December 1981.

I have attempted to implement it according to the package standards with a constructor and an interpolator (it also supports extrapolation). It supports interpolation in any number of dimensions, it has continuous first derivatives and feature both a 3rd and 4th order convergent implementation. The fact that this algorithm does not require continuous second derivatives can be an advantage in some cases, if one desires less overshoot than cubic splines achieves. This is especially true for the 3rd order cubic convolution interpolation, and as such it may be viewed as a compromise between splines and linear interpolation.

Kind regards, Nikolaj

This change implements the following algorithm: "Cubic Convolution Interpolation for Digital Image
Processing" by Robert G. Keys (1981) IEEE Transactions On Acoustics, Speech And Signal Processing. Its order of accuracy is between that of linear interpolation and cubic splines.
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 346 lines in your changes missing coverage. Please review.

Project coverage is 73.67%. Comparing base (8c25bad) to head (761992b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/cubic_convolution/cubic_convolution_coefs.jl 0.00% 125 Missing ⚠️
...bic_convolution/cubic_convolution_extrapolation.jl 0.00% 104 Missing ⚠️
...bic_convolution/cubic_convolution_interpolation.jl 0.00% 55 Missing ⚠️
src/cubic_convolution/cubic_convolution.jl 0.00% 41 Missing ⚠️
src/cubic_convolution/cubic_convolution_kernels.jl 0.00% 16 Missing ⚠️
src/convenience-constructors.jl 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #602       +/-   ##
===========================================
- Coverage   87.18%   73.67%   -13.51%     
===========================================
  Files          28       33        +5     
  Lines        1888     2234      +346     
===========================================
  Hits         1646     1646               
- Misses        242      588      +346     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

.gitignore Outdated
@@ -2,3 +2,4 @@
docs/build/
Manifest.toml
.vscode
temp_tester.jl
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
temp_tester.jl

Please revert this.

Copy link
Author

Choose a reason for hiding this comment

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

Got it. 👍

@mkitti
Copy link
Collaborator

mkitti commented Aug 29, 2024

I like where this is heading. Could you increase test coverage, please?

I am wondering about the name ConvolutionInterpolation and ConvolutionalKernel because this could refer to any interpolation that uses convolution rather than specifically smooth cubic convolution. Could you rename it be CubicConvolutionalInterpolation and CubicConvolutionalKernel?

ConvolutionInterpolation{T,N,typeof(coefs),typeof(it),typeof(knots)}(coefs, (knots_new), it, h, ConvolutionKernel())
end

function create_coefs(knots::Tuple{AbstractVector}, vs::AbstractVector{T}) where T
Copy link
Collaborator

Choose a reason for hiding this comment

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

This name seems too general. Perhaps rename is to create_cubic_convolutional_coefs?

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense, done.

I updated the requested names. I added 3D boundary conditions and some smaller improvements.
@NikoBiele
Copy link
Author

I also added 3D support and implemented your requested naming updates.

@NikoBiele
Copy link
Author

I will look into testing in the weekend. :)

@NikoBiele NikoBiele changed the title Add smooth cubic convolution interpolation in 1d and 2d with extrapolation support Add smooth cubic convolution interpolation in 1d, 2d and 3d Aug 29, 2024
Keeping specialized boundary and interpolation methods up to 3D to ensure speed
@NikoBiele NikoBiele changed the title Add smooth cubic convolution interpolation in 1d, 2d and 3d Add fast smooth cubic convolution interpolation in any number of dimensions Aug 30, 2024
@NikoBiele
Copy link
Author

Tomorrow is dedicated to writing tests. :)

@NikoBiele NikoBiele changed the title Add fast smooth cubic convolution interpolation in any number of dimensions Add 3rd and 4th order convergent cubic convolution interpolation methods with smooth first derivates in any number of dimensions, including extrapolation support Sep 3, 2024
@NikoBiele NikoBiele changed the title Add 3rd and 4th order convergent cubic convolution interpolation methods with smooth first derivates in any number of dimensions, including extrapolation support Add 3rd and 4th order convergent cubic convolution interpolation methods with continuous first derivates in any number of dimensions, including extrapolation support Sep 3, 2024
Both 3rd and 4th order convergence are options with 4th order being the default. Extrapolation is possible with boundary conditions, default being an error if attempting extrapolation.
@NikoBiele
Copy link
Author

I will write some tests now :)

The constructed interpolator is tested in 1D, 2D, 3D and 4D against random data at grid points, against linear mean values between grid points and for two extrapolation boundary conditions.
@NikoBiele
Copy link
Author

In the spirit of the paper mentioned above I derived and tested several of my own kernels! I finally found a really good and smooth one with continuous second derivatives which is 3rd order accurate and like the other ones here it only requires the original values as coefficients, as well as boundary conditions. :) I will implement it here when I find the time. :)

@NikoBiele
Copy link
Author

I will close this pull request and instead make my own package implementing this methodology. :)

@NikoBiele NikoBiele closed this Sep 28, 2024
@mkitti
Copy link
Collaborator

mkitti commented Sep 30, 2024

OK. I'm a little confused. Did you finish writing your tests?

@NikoBiele
Copy link
Author

I added tests above. But since nobody replied I interpreted this as a lack of interest. Also I'm getting very good at deriving these kernels, so I think this idea should have it's own space, so to speak. :)

@mkitti
Copy link
Collaborator

mkitti commented Sep 30, 2024

It's not lack of interest. I just did not know you were ready for the pull request to be reviewed again. Your last comment implied that you were still working on something. If you want to reopen, I can take a look. We could also consider restructuring this as an extension that will load when your package is present.

@NikoBiele
Copy link
Author

Thanks. I'm sorry that I misinterpreted your intent. No hard feelings at all. But I still thinks that this deserves its own package, as the progress I'm seeing currently suggests that my method will outperform cubic B-splines on important parameters (on equally spaced data), such as setup time (no linear system), accuracy (maximum absolute error, continuity and order of accuracy), simplicity and dimensionality, while having very similar execution time (hopefully on the order of 10 microseconds for 1d). Maybe the extension is a nice option. :)

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.

2 participants