Program: 26221
Project: 26221
Buggy source:
/** 
 * <p> Ref: A. Muñoz-Barrutia, T. Blu, M. Unser, "Least-Squares Image Resizing Using Finite Differences," IEEE Transactions on Image Processing, vol. 10, n. 9, September 2001. Use: out(x) = input(x/scale); scale > 1 expansion; a < 1 reduction. Use n=n2 if (n1==-1) the standard method (interpolation and resampling) is applied. If (n=n1=n2), the orthogonal projection is computed. The error is the minimum in the least-squares sense. If ((n1 > -1) && (n1<n2)), the oblique projection is computed. The error is slightly greater than the case above. </p>
 * @param input input signal
 * @param n degree of the interpolation spline. It can vary from 0 to 3.
 * @param n1 degree of the analysis spline. It can vary from -1 to 3.
 * @param n2 degree of the synthesis spline. It can vary from 0 to 3. 
 * @param scale zoom factor (scale > 1 expansion; scale < 1 reduction)
 * @param coefOrSamples if working with coefficients coefOrSamples is true; if working with samples coefOrSamples is false
 * @return out signal
 */
public static double[] resize1D(double[] input,int n,int n1,int n2,double scale,boolean coefOrSamples){
  int nxIn=input.length;
  double bb=Math.round(((nxIn - 1) * scale) * 1 / scale);
  while ((nxIn - 1 - bb) != 0) {
    nxIn=nxIn + 1;
    bb=Math.round(((nxIn - 1) * scale) * 1 / scale);
  }
  int nxOut=(int)Math.round((nxIn - 1) * scale) + 1;
  double[] out=new double[nxOut];
  double[] coef=null;
  if (coefOrSamples == false) {
    if (n < 2)     coef=input;
 else {
      double[] pole=tableOfPoles(n);
      double tolerance=1e-11;
      coef=convertToInterpCoef(input,pole,tolerance);
    }
  }
  double[] integ=new double[input.length];
  double med=0;
  if (n1 == -1) {
    integ=input;
    med=0;
  }
  if (n1 == 0) {
    med=integSA(input,integ);
  }
  if (n1 == 1) {
    med=integSA(input,integ);
    integ=integAS(integ);
  }
  if (n1 == 2) {
    med=integSA(input,integ);
    integ=integAS(integ);
    integSA(integ,integ);
  }
  if (n1 == 3) {
    med=integSA(input,integ);
    integ=integAS(integ);
    integSA(integ,integ);
    integ=integAS(integ);
  }
  double[] resize=resampling(integ,nxIn,nxOut,scale,n1,n + n1 + 1);
  double[] fd=null;
  if (n1 == -1)   fd=resize;
 else   if (n1 == 0)   fd=finDiffAS(resize);
 else   if (n1 == 1) {
    fd=finDiffSA(resize);
    fd=finDiffAS(fd);
  }
 else   if (n1 == 2) {
    fd=finDiffAS(resize);
    fd=finDiffSA(fd);
    fd=finDiffAS(fd);
  }
 else   if (n1 == 3) {
    fd=finDiffSA(resize);
    fd=finDiffAS(fd);
    fd=finDiffSA(fd);
    fd=finDiffAS(fd);
  }
  final int n11=n1 + 1;
  final int val1=(n11 * 0.5 == (int)Math.floor(n11 * 0.5)) ? (int)(n11 * 0.5) : (int)Math.floor(n11 * 0.5) + 1;
  double[] fdShort=new double[nxOut];
  for (int i=0; i < nxOut; i++)   fdShort[i]=fd[val1 + i] + med;
  double[] coefFull=null;
  if ((n1 + n2 + 1) < 2)   coefFull=fdShort;
 else {
    double[] pole=tableOfPoles(n1 + n2 + 1);
    double tolerance=1e-11;
    coefFull=convertToInterpCoef(fdShort,pole,tolerance);
  }
  if (coefOrSamples == true) {
    if (n2 < 2)     out=coefFull;
 else {
      double[] samples=tableOfSamples(n2);
      out=convertToSamples(coefFull,samples);
    }
  }
  return out;
}

Fixed version (ground truth):
/** 
 * <p> Ref: A. Muñoz-Barrutia, T. Blu, M. Unser, "Least-Squares Image Resizing Using Finite Differences," IEEE Transactions on Image Processing, vol. 10, n. 9, September 2001. </p> <p> Use:   {@code out(x) = input(x/scale)};   {@code scale > 1} expansion;{@code a < 1} reduction.</p> <p> Use  {@code n=n2}: </p> <ul> <li>if   {@code (n1==-1)} the standard method (interpolation and resampling)is applied.</li> <li>If  {@code (n=n1=n2)}, the orthogonal projection is computed. The error is the minimum in the least-squares sense.</li> <li>If   {@code ((n1 > -1) && (n1<n2))}, the oblique projection is computed. The error is slightly greater than the case above.</li> </ul>
 * @param input input signal
 * @param n degree of the interpolation spline. It can vary from 0 to 3.
 * @param n1 degree of the analysis spline. It can vary from -1 to 3.
 * @param n2 degree of the synthesis spline. It can vary from 0 to 3.
 * @param scale zoom factor ({@code scale > 1} expansion; {@code scale < 1}reduction)
 * @param coefOrSamples if working with coefficients coefOrSamples is true; ifworking with samples coefOrSamples is false
 * @return out signal
 */
public static double[] resize1D(double[] input,int n,int n1,int n2,double scale,boolean coefOrSamples){
  int nxIn=input.length;
  double bb=Math.round(((nxIn - 1) * scale) * 1 / scale);
  while ((nxIn - 1 - bb) != 0) {
    nxIn=nxIn + 1;
    bb=Math.round(((nxIn - 1) * scale) * 1 / scale);
  }
  int nxOut=(int)Math.round((nxIn - 1) * scale) + 1;
  double[] out=new double[nxOut];
  double[] coef=null;
  if (coefOrSamples == false) {
    if (n < 2)     coef=input;
 else {
      double[] pole=tableOfPoles(n);
      double tolerance=1e-11;
      coef=convertToInterpCoef(input,pole,tolerance);
    }
  }
  double[] integ=new double[input.length];
  double med=0;
  if (n1 == -1) {
    integ=input;
    med=0;
  }
  if (n1 == 0) {
    med=integSA(input,integ);
  }
  if (n1 == 1) {
    med=integSA(input,integ);
    integ=integAS(integ);
  }
  if (n1 == 2) {
    med=integSA(input,integ);
    integ=integAS(integ);
    integSA(integ,integ);
  }
  if (n1 == 3) {
    med=integSA(input,integ);
    integ=integAS(integ);
    integSA(integ,integ);
    integ=integAS(integ);
  }
  double[] resize=resampling(integ,nxIn,nxOut,scale,n1,n + n1 + 1);
  double[] fd=null;
  if (n1 == -1)   fd=resize;
 else   if (n1 == 0)   fd=finDiffAS(resize);
 else   if (n1 == 1) {
    fd=finDiffSA(resize);
    fd=finDiffAS(fd);
  }
 else   if (n1 == 2) {
    fd=finDiffAS(resize);
    fd=finDiffSA(fd);
    fd=finDiffAS(fd);
  }
 else   if (n1 == 3) {
    fd=finDiffSA(resize);
    fd=finDiffAS(fd);
    fd=finDiffSA(fd);
    fd=finDiffAS(fd);
  }
  final int n11=n1 + 1;
  final int val1=(n11 * 0.5 == (int)Math.floor(n11 * 0.5)) ? (int)(n11 * 0.5) : (int)Math.floor(n11 * 0.5) + 1;
  double[] fdShort=new double[nxOut];
  for (int i=0; i < nxOut; i++)   fdShort[i]=fd[val1 + i] + med;
  double[] coefFull=null;
  if ((n1 + n2 + 1) < 2)   coefFull=fdShort;
 else {
    double[] pole=tableOfPoles(n1 + n2 + 1);
    double tolerance=1e-11;
    coefFull=convertToInterpCoef(fdShort,pole,tolerance);
  }
  if (coefOrSamples == true) {
    if (n2 < 2)     out=coefFull;
 else {
      double[] samples=tableOfSamples(n2);
      out=convertToSamples(coefFull,samples);
    }
  }
  return out;
}