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-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit http://imagingbook.com for additional details. 008 *******************************************************************************/ 009 010package imagingbook.lib.interpolation; 011 012import imagingbook.lib.image.ImageAccessor; 013 014 015/** 016 * This is the common (abstract) superclass to all pixel interpolators 017 * for scalar-valued images. 018 * @author WB 019 * 020 */ 021public abstract class PixelInterpolator { 022 023 public static PixelInterpolator create(ImageAccessor.Scalar ia) { 024 return create(ia.getInterpolationMethod()); 025 } 026 027 public static PixelInterpolator create(InterpolationMethod method) { 028 switch (method) { 029 case NearestNeighbor : return new NearestNeighborInterpolator(); 030 case Bilinear : return new BilinearInterpolator(); 031 case Bicubic : return new BicubicInterpolator(1.00); 032 case BicubicSmooth : return new BicubicInterpolator(0.25); 033 case BicubicSharp : return new BicubicInterpolator(1.75); 034 case CatmullRom: return new SplineInterpolator(0.5, 0.0); 035 case CubicBSpline: return new SplineInterpolator(0.0, 1.0); 036 case MitchellNetravali: return new SplineInterpolator(1.0/3, 1.0/3); 037 case Lanzcos2 : return new LanczosInterpolator(2); 038 case Lanzcos3 : return new LanczosInterpolator(3); 039 case Lanzcos4 : return new LanczosInterpolator(4); 040 default : throw new IllegalArgumentException("unhandled interpolator method: " + method); 041 } 042 } 043 044 /** 045 * All interpolator classes must implement this method. 046 * @param ia Accessor to the interpolated image. 047 * @param x Continuous interpolation position (horiz.) 048 * @param y Continuous interpolation position (vert.) 049 * @return The interpolated pixel value at position (x,y). 050 */ 051 public abstract float getInterpolatedValue(ImageAccessor.Scalar ia, double x, double y); 052 053}