001/*******************************************************************************
002 * This software is provided as a supplement to the authors' textbooks on digital
003 * image processing published by Springer-Verlag in various languages and editions.
004 * Permission to use and distribute this software is granted under the BSD 2-Clause
005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause).
006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved.
007 * Visit https://imagingbook.com for additional details.
008 ******************************************************************************/
009
010package imagingbook.common.image.interpolation;
011
012import imagingbook.common.image.access.ScalarAccessor;
013
014/**
015 * <p>
016 * This interface defines the behavior of 2D pixel interpolators for scalar-valued images. See Ch. 22 of [1] for
017 * additional details.
018 * </p>
019 * <p>
020 * [1] W. Burger, M.J. Burge, <em>Digital Image Processing &ndash; An Algorithmic Introduction</em>, 3rd ed, Springer
021 * (2022).
022 * </p>
023 *
024 * @author WB
025 */
026public interface PixelInterpolator {
027
028        /**
029         * Returns a {@link PixelInterpolator} instance for the specified {@link InterpolationMethod}.
030         *
031         * @param method the interpolation method
032         * @return an instance of {@link PixelInterpolator}
033         */
034        public static PixelInterpolator create(InterpolationMethod method) {
035                switch (method) {
036                case NearestNeighbor :  return new NearestNeighborInterpolator();
037                case Bilinear :                 return new BilinearInterpolator();
038                case Bicubic :                  return new BicubicInterpolator(1.00);
039                case BicubicSmooth :    return new BicubicInterpolator(0.25);
040                case BicubicSharp :     return new BicubicInterpolator(1.75);
041                case CatmullRom:                return new CatmullRomInterpolator();
042                case CubicBSpline:              return new CubicBSplineInterpolator();
043                case MitchellNetravali: return new MitchellNetravaliInterpolator();
044                case Lanzcos2 :                 return new LanczosInterpolator(2);
045                case Lanzcos3 :                 return new LanczosInterpolator(3);
046                case Lanzcos4 :                 return new LanczosInterpolator(4);
047                //default : throw new IllegalArgumentException("unhandled interpolation method: " + method);
048                }
049                return null;
050        }
051        
052        /**
053         * Returns the interpolated pixel value for the specified position. 
054         * 
055         * @param ia a {@link ScalarAccessor} to the interpolated image
056         * @param x continuous interpolation position (horiz.)  
057         * @param y continuous interpolation position (vert.)  
058         * @return the interpolated pixel value at position (x,y).
059         */
060        public float getInterpolatedValue(ScalarAccessor ia, double x, double y);
061
062        /**
063         * Returns the value of the one-dimensional weight function w(x), that is the weight given to some pixel at distance
064         * x from the current interpolation point. This method is primarily used for testing.
065         *
066         * @param x the position relative to the interpolation point
067         * @return the weight for this position
068         */
069        public double getWeight(double x);
070
071        /**
072         * Returns the value of the two-dimensional weight function W(x,y), that is the weight given to some pixel at
073         * distance (x,y) relative to the current interpolation point. This method is primarily used for testing.
074         *
075         * @param x the x-position relative to the interpolation point
076         * @param y the y-position relative to the interpolation point
077         * @return the weight for this position
078         */
079        public default double getWeight(double x, double y) {
080                return getWeight(x) * getWeight(y);
081        }
082        
083        
084        
085}