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; 011import imagingbook.lib.image.ImageAccessor; 012 013public class BilinearInterpolator extends PixelInterpolator { 014 015 public BilinearInterpolator() { 016 } 017 018 @Override 019 public float getInterpolatedValue(ImageAccessor.Scalar ia, double x, double y) { 020 final int u = (int) Math.floor(x); 021 final int v = (int) Math.floor(y); 022 final double a = x - u; 023 final double b = y - v; 024 final double A = ia.getVal(u, v); 025 final double B = ia.getVal(u + 1, v); 026 final double C = ia.getVal(u, v + 1); 027 final double D = ia.getVal(u + 1, v + 1); 028 final double E = A + a * (B - A); 029 final double F = C + a * (D - C); 030 final double G = E + b * (F - E); 031 return (float) G; 032 } 033 034}