This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new c92fbca Add a simple interpolation test. c92fbca is described below commit c92fbca4ea76b61d979ec90d39bf1e2a2b838011 Author: Martin Desruisseaux AuthorDate: Thu Mar 26 11:18:35 2020 +0100 Add a simple interpolation test. --- .../java/org/apache/sis/image/Interpolation.java | 7 +- .../org/apache/sis/image/LanczosInterpolation.java | 4 +- .../java/org/apache/sis/image/ResampledImage.java | 13 ++- .../org/apache/sis/image/InterpolationTest.java | 114 +++++++++++++++++++++ .../apache/sis/test/suite/FeatureTestSuite.java | 1 + 5 files changed, 132 insertions(+), 7 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/Interpolation.java b/core/sis-feature/src/main/java/org/apache/sis/image/Interpolation.java index cdb0498..ef5ac57 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/Interpolation.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/Interpolation.java @@ -25,6 +25,9 @@ import java.nio.DoubleBuffer; * of pixels using a local neighborhood. The sampling is performed by the {@link ResampledImage} class, which * gives the sample values to the {@code interpolate(…)} method of this interpolation. * + *

All methods in this interface shall be safe for concurrent use in multi-threading context. + * For example interpolations may be executed in a different thread for each tile in an image.

+ * *

This interface is designed for interpolations in a two-dimensional space only.

* * @author Rémi Marechal (Geomatys) @@ -134,7 +137,9 @@ public interface Interpolation { }; /** - * Lanczos interpolation. The kernel is: + * Lanczos interpolation for photographic images. + * This interpolation is not recommended for images that may contain NaN values. + * The Lanczos reconstruction kernel is: * *
* L(x) = a⋅sin(π⋅x)⋅sin(π⋅x/a)/(π⋅x)² diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/LanczosInterpolation.java b/core/sis-feature/src/main/java/org/apache/sis/image/LanczosInterpolation.java index 138df5f..91e63e7 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/LanczosInterpolation.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/LanczosInterpolation.java @@ -22,8 +22,8 @@ import java.nio.DoubleBuffer; /** - * Lanczos interpolation of arbitrary size. - * The kernel is: + * Lanczos interpolation of arbitrary size. This interpolation is good for photographic images but + * not recommended for images that may contain NaN values. The Lanczos reconstruction kernel is: * *
* L(x) = a⋅sin(π⋅x)⋅sin(π⋅x/a)/(π⋅x)² diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java index 5323ce9..ca61728 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java @@ -16,6 +16,7 @@ */ package org.apache.sis.image; +import java.util.Arrays; import java.nio.DoubleBuffer; import java.awt.Dimension; import java.awt.Rectangle; @@ -103,14 +104,17 @@ public class ResampledImage extends ComputedImage { * by a non-linear transform from this image to the specified source image. * That transform should map {@linkplain org.opengis.referencing.datum.PixelInCell#CELL_CENTER pixel centers}. * + *

If a pixel in this image can not be mapped to a pixel in the source image, then the sample values are set + * to {@code fillValues}. If the given array is {@code null}, or if any element in the given array is {@code null}, + * then the default fill value is NaN for floating point data types or zero for integer data types.

+ * * @param bounds domain of pixel coordinates of this resampled image. * @param toSource conversion of pixel coordinates of this image to pixel coordinates of {@code source} image. * @param source the image to be resampled. * @param interpolation the object to use for performing interpolations. * @param fillValues the values to use for pixels in this image that can not be mapped to pixels in source image. - * The array length must be equal to the number of bands. If the array is {@code null}, - * the default value is zero in all bands. If any element in the array is {@code null}, - * the default value is zero for the corresponding band. + * The array length must be equal to the number of bands. + * May be {@code null} or contain {@code null} elements. */ public ResampledImage(final Rectangle bounds, final MathTransform toSource, final RenderedImage source, final Interpolation interpolation, final Number[] fillValues) @@ -168,6 +172,7 @@ public class ResampledImage extends ComputedImage { this.fillValues = fill; } else { final double[] fill = new double[numBands]; + Arrays.fill(fill, Double.NaN); if (fillValues != null) { for (int i=0; i[] ranges = it.getSampleRanges(); + final NumberRange[] ranges = it.getSampleRanges(); // Assumes source.sampleModel == this.sampleModel. minValues = new long[ranges.length]; maxValues = new long[ranges.length]; for (int i=0; i