Skip to content

More accurate interpolation#18

Merged
Rylern merged 3 commits intomainfrom
more-accurate-interpolation
Feb 25, 2026
Merged

More accurate interpolation#18
Rylern merged 3 commits intomainfrom
more-accurate-interpolation

Conversation

@Rylern
Copy link
Contributor

@Rylern Rylern commented Feb 19, 2026

Considering a point p and its four closest points p1, p2, p3, and p4, linear interpolation is implemented with the following formula:

p = t1*p1 + t2*p2 + t3*p3 + t4*p4

with the ti between 0 and 1 representing the distance between p and pi.

With integer images, the ImgLib2 NLinearInterpolatorFactory computes something like this:

p = round(t1*p1) + round(t2*p2) + round(t3*p3) + round(t4*p4)

This is an issue, because there is a high loss of precision. For example, with an image containing only pixels with value 20, this interpolation can create pixels with values 19 or 21.

This PR provides a custom implementation of the linear interpolation, which computes something like this:

p = round(t1*p1 + t2*p2 + t3*p3 + t4*p4)

There's still a precision loss, but less than before (and it's unavoidable).

@Rylern Rylern requested a review from petebankhead February 19, 2026 15:57
@Rylern Rylern merged commit c516821 into main Feb 25, 2026
1 check passed
@Rylern Rylern deleted the more-accurate-interpolation branch February 25, 2026 15:45
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.

1 participant