nus-yam/ex-repair huggingface dataset:
Program: 150887
Project: 150887
Buggy source:
/** 
 * Basic tests with a single split
 */
@Test public void splitPixels(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.01,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.N=alg.contour.size();
  alg.contour.get(4).y=6;
  alg.splitPixels(0,3);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(0,4);
  assertEquals(1,alg.splits.size);
  assertEquals(3,alg.splits.data[0]);
  alg.splits.reset();
  alg.splitPixels(0,9);
  assertEquals(3,alg.splits.size);
  assertEquals(3,alg.splits.data[0]);
  assertEquals(4,alg.splits.data[1]);
  assertEquals(5,alg.splits.data[2]);
  alg.splits.reset();
  alg.splitPixels(0,1);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(9,1);
  assertEquals(0,alg.splits.size);
}

Fixed version (ground truth):
/** 
 * Basic tests with a single split
 */
@Test public void splitPixels(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.01,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.N=alg.contour.size();
  alg.contour.get(4).y=6;
  alg.splitPixels(0,3);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(0,4);
  assertEquals(1,alg.splits.size);
  assertEquals(3,alg.splits.data[0]);
  alg.splits.reset();
  alg.splitPixels(0,9);
  assertEquals(3,alg.splits.size);
  assertEquals(3,alg.splits.data[0]);
  assertEquals(4,alg.splits.data[1]);
  assertEquals(5,alg.splits.data[2]);
  alg.splits.reset();
  alg.splitPixels(0,1);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(9,1);
  assertEquals(0,alg.splits.size);
}
Program: 150888
Project: 150888
Buggy source:
/** 
 * Sees if it can segment a square.
 */
@Test public void simpleSquareAll(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(i,0));
  for (int i=1; i < 5; i++)   contour.add(new Point2D_I32(9,i));
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(9 - i,4));
  for (int i=2; i < 5; i++)   contour.add(new Point2D_I32(0,5 - i));
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,1,100);
  alg.process(contour);
  GrowQueue_I32 splits=alg.getSplits();
  matchSplitsToExpected(new int[]{0,9,13,23},splits);
}

Fixed version (ground truth):
/** 
 * Sees if it can segment a square.
 */
@Test public void simpleSquareAll(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(i,0));
  for (int i=1; i < 5; i++)   contour.add(new Point2D_I32(9,i));
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(9 - i,4));
  for (int i=2; i < 5; i++)   contour.add(new Point2D_I32(0,5 - i));
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,MINIMUM_SPLIT_FRACTION,100);
  alg.process(contour);
  GrowQueue_I32 splits=alg.getSplits();
  matchSplitsToExpected(new int[]{0,9,13,23},splits);
}
Program: 150889
Project: 150889
Buggy source:
/** 
 * Segment where no splitting is required
 */
@Test public void splitPixels_nosplit(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,5,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.N=alg.contour.size();
  alg.splitPixels(0,5);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(0,9);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(5,1);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(5,9);
  assertEquals(0,alg.splits.size);
}

Fixed version (ground truth):
/** 
 * Segment where no splitting is required
 */
@Test public void splitPixels_nosplit(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,5 * MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.N=alg.contour.size();
  alg.splitPixels(0,5);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(0,9);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(5,1);
  assertEquals(0,alg.splits.size);
  alg.splitPixels(5,9);
  assertEquals(0,alg.splits.size);
}
Program: 150890
Project: 150890
Buggy source:
@Test public void circularDistance(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,5,100);
  alg.N=15;
  assertEquals(0,alg.circularDistance(0,0));
  assertEquals(1,alg.circularDistance(0,1));
  assertEquals(14,alg.circularDistance(0,14));
  assertEquals(0,alg.circularDistance(5,5));
  assertEquals(1,alg.circularDistance(5,6));
  assertEquals(14,alg.circularDistance(5,4));
}

Fixed version (ground truth):
@Test public void circularDistance(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,5 * MINIMUM_SPLIT_FRACTION,100);
  alg.N=15;
  assertEquals(0,alg.circularDistance(0,0));
  assertEquals(1,alg.circularDistance(0,1));
  assertEquals(14,alg.circularDistance(0,14));
  assertEquals(0,alg.circularDistance(5,5));
  assertEquals(1,alg.circularDistance(5,6));
  assertEquals(14,alg.circularDistance(5,4));
}
Program: 150891
Project: 150891
Buggy source:
/** 
 * Simple case with a zig-zag pattern
 */
@Test public void simpleCase(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(i,0));
  for (int i=1; i < 5; i++)   contour.add(new Point2D_I32(9,i));
  for (int i=1; i < 10; i++)   contour.add(new Point2D_I32(9 + i,4));
  for (int i=2; i < 5; i++)   contour.add(new Point2D_I32(18,5 - i));
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,1,100);
  alg.process(contour);
  GrowQueue_I32 splits=alg.getSplits();
  assertEquals(5,splits.size);
  assertEquals(0,alg.splits.data[0]);
  assertEquals(9,alg.splits.data[1]);
  assertEquals(13,alg.splits.data[2]);
  assertEquals(22,alg.splits.data[3]);
  assertEquals(25,alg.splits.data[4]);
}

Fixed version (ground truth):
/** 
 * Simple case with a zig-zag pattern
 */
@Test public void simpleCase(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(i,0));
  for (int i=1; i < 5; i++)   contour.add(new Point2D_I32(9,i));
  for (int i=1; i < 10; i++)   contour.add(new Point2D_I32(9 + i,4));
  for (int i=2; i < 5; i++)   contour.add(new Point2D_I32(18,5 - i));
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,MIN_SPLIT,100);
  alg.process(contour);
  GrowQueue_I32 splits=alg.getSplits();
  assertEquals(5,splits.size);
  assertEquals(0,alg.splits.data[0]);
  assertEquals(9,alg.splits.data[1]);
  assertEquals(13,alg.splits.data[2]);
  assertEquals(22,alg.splits.data[3]);
  assertEquals(25,alg.splits.data[4]);
}
Program: 150892
Project: 150892
Buggy source:
@Test public void splitSegments(){
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=5;
  alg.splits.add(0);
  alg.splits.add(9);
  assertTrue(alg.splitSegments());
  assertEquals(3,alg.splits.size);
  assertEquals(0,alg.splits.data[0]);
  assertEquals(4,alg.splits.data[1]);
  assertEquals(9,alg.splits.data[2]);
}

Fixed version (ground truth):
@Test public void splitSegments(){
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,MIN_SPLIT,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=5;
  alg.splits.add(0);
  alg.splits.add(9);
  assertTrue(alg.splitSegments());
  assertEquals(3,alg.splits.size);
  assertEquals(0,alg.splits.data[0]);
  assertEquals(4,alg.splits.data[1]);
  assertEquals(9,alg.splits.data[2]);
}
Program: 150893
Project: 150893
Buggy source:
@Test public void mergeSegments(){
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.001,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  alg.contour.add(new Point2D_I32(0,0));
  alg.contour.add(new Point2D_I32(1,0));
  alg.contour.add(new Point2D_I32(3,0));
  alg.contour.add(new Point2D_I32(3,4));
  alg.contour.add(new Point2D_I32(4,4));
  alg.contour.add(new Point2D_I32(5,4));
  for (int i=0; i < alg.contour.size(); i++) {
    alg.splits.add(i);
  }
  assertTrue(alg.mergeSegments());
  assertEquals(3,alg.splits.size);
  assertEquals(0,alg.splits.data[0]);
  assertEquals(2,alg.splits.data[1]);
  assertEquals(5,alg.splits.data[2]);
}

Fixed version (ground truth):
@Test public void mergeSegments(){
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.001,MIN_SPLIT,100);
  alg.contour=new ArrayList<Point2D_I32>();
  alg.contour.add(new Point2D_I32(0,0));
  alg.contour.add(new Point2D_I32(1,0));
  alg.contour.add(new Point2D_I32(3,0));
  alg.contour.add(new Point2D_I32(3,4));
  alg.contour.add(new Point2D_I32(4,4));
  alg.contour.add(new Point2D_I32(5,4));
  for (int i=0; i < alg.contour.size(); i++) {
    alg.splits.add(i);
  }
  assertTrue(alg.mergeSegments());
  assertEquals(3,alg.splits.size);
  assertEquals(0,alg.splits.data[0]);
  assertEquals(2,alg.splits.data[1]);
  assertEquals(5,alg.splits.data[2]);
}
Program: 150894
Project: 150894
Buggy source:
@Test public void selectSplitOffset(){
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=10;
  alg.line.slope.x=5;
  int found=alg.selectSplitBetween(0,9);
  assertEquals(4,found);
  found=alg.selectSplitBetween(0,5);
  assertEquals(4,found);
  found=alg.selectSplitBetween(0,4);
  assertTrue(found < 4);
  found=alg.selectSplitBetween(0,3);
  assertEquals(-1,found);
  found=alg.selectSplitBetween(5,9);
  assertEquals(-1,found);
  found=alg.selectSplitBetween(1,6);
  assertEquals(4,found);
}

Fixed version (ground truth):
@Test public void selectSplitOffset(){
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,MIN_SPLIT,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=10;
  alg.line.slope.x=5;
  int found=alg.selectSplitBetween(0,9);
  assertEquals(4,found);
  found=alg.selectSplitBetween(0,5);
  assertEquals(4,found);
  found=alg.selectSplitBetween(0,4);
  assertTrue(found < 4);
  found=alg.selectSplitBetween(0,3);
  assertEquals(-1,found);
  found=alg.selectSplitBetween(5,9);
  assertEquals(-1,found);
  found=alg.selectSplitBetween(1,6);
  assertEquals(4,found);
}
Program: 150895
Project: 150895
Buggy source:
/** 
 * Tests contours with zero and one points in them
 */
@Test public void checkZeroOne(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,1,100);
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
  contour.add(new Point2D_I32(2,3));
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
}

Fixed version (ground truth):
/** 
 * Tests contours with zero and one points in them
 */
@Test public void checkZeroOne(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  SplitMergeLineFitSegment alg=new SplitMergeLineFitSegment(0.15,MIN_SPLIT,100);
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
  contour.add(new Point2D_I32(2,3));
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
}
Program: 150896
Project: 150896
Buggy source:
/** 
 * Finds the point between indexStart and the end point which is the greater distance from the line (set up prior to calling).  Returns the index 0f the distance is less than tolerance, otherwise -1
 */
protected int selectSplitOffset(int indexStart,int length){
  int bestOffset=-1;
  int indexEnd=(indexStart + length) % N;
  Point2D_I32 startPt=contour.get(indexStart);
  Point2D_I32 endPt=contour.get(indexEnd);
  line.p.set(startPt.x,startPt.y);
  line.slope.set(endPt.x - startPt.x,endPt.y - startPt.y);
  double bestDistanceSq=0;
  double toleranceSplitSq=splitThresholdSq(contour.get(indexStart),contour.get(indexEnd));
  length-=2 * minimumSideLengthPixel;
  for (int i=1 + minimumSideLengthPixel; i < length; i++) {
    Point2D_I32 b=contour.get((indexStart + i) % N);
    point2D.set(b.x,b.y);
    double dist=Distance2D_F64.distanceSq(line,point2D);
    if (dist > bestDistanceSq) {
      bestDistanceSq=dist;
      bestOffset=i;
    }
  }
  if (bestDistanceSq > toleranceSplitSq) {
    return bestOffset;
  }
 else {
    return -1;
  }
}

Fixed version (ground truth):
/** 
 * Finds the point between indexStart and the end point which is the greater distance from the line (set up prior to calling).  Returns the index of the element with a distances greater than tolerance, otherwise -1
 */
protected int selectSplitOffset(int indexStart,int length){
  int bestOffset=-1;
  int indexEnd=(indexStart + length) % N;
  Point2D_I32 startPt=contour.get(indexStart);
  Point2D_I32 endPt=contour.get(indexEnd);
  line.p.set(startPt.x,startPt.y);
  line.slope.set(endPt.x - startPt.x,endPt.y - startPt.y);
  double bestDistanceSq=splitThresholdSq(contour.get(indexStart),contour.get(indexEnd));
  int minLength=Math.max(1,minimumSideLengthPixel);
  length-=minLength;
  for (int i=minLength; i <= length; i++) {
    Point2D_I32 b=contour.get((indexStart + i) % N);
    point2D.set(b.x,b.y);
    double dist=Distance2D_F64.distanceSq(line,point2D);
    if (dist > bestDistanceSq) {
      bestDistanceSq=dist;
      bestOffset=i;
    }
  }
  return bestOffset;
}
Program: 150897
Project: 150897
Buggy source:
@Test public void selectSplitOffset(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=10;
  alg.N=alg.contour.size();
  alg.line.slope.x=1;
  int found=alg.selectSplitOffset(0,9);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,5);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,4);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(0,3);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(3,5);
  assertEquals(1,found);
  found=alg.selectSplitOffset(5,6);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,8);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,10);
  assertEquals(9,found);
  found=alg.selectSplitOffset(9,8);
  assertEquals(5,found);
  fail("String_Node_Str");
}

Fixed version (ground truth):
@Test public void selectSplitOffset(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(9.0 / 9.0,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=10;
  alg.N=alg.contour.size();
  alg.line.slope.x=1;
  int found=alg.selectSplitOffset(0,9);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,5);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,4);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(0,3);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(3,5);
  assertEquals(1,found);
  found=alg.selectSplitOffset(5,6);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,8);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(9,8);
  assertEquals(5,found);
  alg.setSplitFraction(10.1 / 9.00);
  found=alg.selectSplitOffset(0,9);
  assertEquals(-1,found);
  alg.setSplitFraction(9.9 / 9.00);
  found=alg.selectSplitOffset(0,9);
  assertEquals(4,found);
}
Program: 150898
Project: 150898
Buggy source:
/** 
 * Makes sure the selectSplitOffset is obeying the minimumSideLengthPixel parameter
 */
@Test public void selectSplitOffset_minimumSideLengthPixel(){
  fail("String_Node_Str");
}

Fixed version (ground truth):
private void selectSplitOffset_minimumSideLengthPixel(SplitMergeLineFitLoop alg,int minimum){
  int found=alg.selectSplitOffset(5 - minimum,9);
  assertEquals(minimum,found);
  found=alg.selectSplitOffset(0,5 + minimum);
  assertEquals(5,found);
  found=alg.selectSplitOffset(5 - minimum + 1,9);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(0,5 + minimum - 1);
  assertEquals(-1,found);
}
Program: 150899
Project: 150899
Buggy source:
public PlanarDetectorChessboard(ConfigChessboard config){
  RefineBinaryPolygon<ImageFloat32> refineLine=FactoryShapeDetector.refinePolygon(config.configRefineLines,ImageFloat32.class);
  RefineBinaryPolygon<ImageFloat32> refineCorner=FactoryShapeDetector.refinePolygon(config.configRefineLines,ImageFloat32.class);
  config.square.refine=null;
  BinaryPolygonDetector<ImageFloat32> detectorSquare=FactoryShapeDetector.polygon(config.square,ImageFloat32.class);
  InputToBinary<ImageFloat32> inputToBinary=FactoryThresholdBinary.threshold(config.thresholding,ImageFloat32.class);
  alg=new DetectChessboardFiducial<ImageFloat32>(config.numCols,config.numRows,config.maximumCornerDistance,detectorSquare,refineLine,refineCorner,inputToBinary);
  layoutPoints=gridChess(config.numCols,config.numRows,config.squareWidth);
}

Fixed version (ground truth):
public PlanarDetectorChessboard(ConfigChessboard config){
  RefineBinaryPolygon<ImageFloat32> refineLine=FactoryShapeDetector.refinePolygon(config.configRefineLines,ImageFloat32.class);
  RefineBinaryPolygon<ImageFloat32> refineCorner=config.refineWithCorners ? FactoryShapeDetector.refinePolygon(config.configRefineLines,ImageFloat32.class) : null;
  config.square.refine=null;
  BinaryPolygonDetector<ImageFloat32> detectorSquare=FactoryShapeDetector.polygon(config.square,ImageFloat32.class);
  InputToBinary<ImageFloat32> inputToBinary=FactoryThresholdBinary.threshold(config.thresholding,ImageFloat32.class);
  alg=new DetectChessboardFiducial<ImageFloat32>(config.numCols,config.numRows,config.maximumCornerDistance,detectorSquare,refineLine,refineCorner,inputToBinary);
  layoutPoints=gridChess(config.numCols,config.numRows,config.squareWidth);
}
Program: 150900
Project: 150900
Buggy source:
@Override public void adjustBeforeOptimize(Polygon2D_F64 polygon){
  center.x=0;
  center.y=0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    center.x+=p.x;
    center.y+=p.y;
  }
  center.x/=4.0;
  center.y/=4.0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    double dx=p.x - center.x;
    double dy=p.y - center.y;
    double r=Math.sqrt(dx * dx + dy * dy);
    if (r > 0) {
      p.x+=1.4 * dx / r;
      p.y+=1.4 * dy / r;
    }
  }
  if (refineCorner != null) {
    double area=polygon.areaSimple();
    if (area < threshold) {
      detectorSquare.setRefinePolygon(refineLine);
    }
 else {
      detectorSquare.setRefinePolygon(refineCorner);
    }
  }
}

Fixed version (ground truth):
@Override public void adjustBeforeOptimize(Polygon2D_F64 polygon){
  center.x=0;
  center.y=0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    center.x+=p.x;
    center.y+=p.y;
  }
  center.x/=4.0;
  center.y/=4.0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    double dx=p.x - center.x;
    double dy=p.y - center.y;
    double r=Math.sqrt(dx * dx + dy * dy);
    if (r > 0) {
      p.x+=1.4 * dx / r;
      p.y+=1.4 * dy / r;
    }
  }
  if (refineCorner != null) {
    double area=polygon.areaSimple();
    if (area < threshold) {
      detectorSquare.setRefinePolygon(refineLine);
    }
 else {
      detectorSquare.setRefinePolygon(refineCorner);
    }
  }
 else {
    detectorSquare.setRefinePolygon(refineLine);
  }
}
Program: 150902
Project: 150902
Buggy source:
void sanityCheckCornerOrder(int anchor0,int numLines,int contourAnchor0){
  int previous=0;
  for (int i=1; i <= numLines; i++) {
    int contourIndex=workCorners.get(CircularIndex.addOffset(anchor0,i,workCorners.size()));
    int pixelsFromAnchor0=CircularIndex.distanceP(contourAnchor0,contourIndex,contour.size());
    if (pixelsFromAnchor0 < previous) {
      throw new RuntimeException("String_Node_Str");
    }
 else {
      previous=pixelsFromAnchor0;
    }
  }
}

Fixed version (ground truth):
/** 
 * All the corners should be in increasing order from the first anchor.
 */
boolean sanityCheckCornerOrder(int numLines,GrowQueue_I32 corners){
  int contourAnchor0=corners.get(anchor0);
  int previous=0;
  for (int i=1; i < numLines; i++) {
    int contourIndex=corners.get(CircularIndex.addOffset(anchor0,i,corners.size()));
    int pixelsFromAnchor0=CircularIndex.distanceP(contourAnchor0,contourIndex,contour.size());
    if (pixelsFromAnchor0 < previous) {
      return false;
    }
 else {
      previous=pixelsFromAnchor0;
    }
  }
  return true;
}
Program: 150903
Project: 150903
Buggy source:
int closestPoint(Point2D_F64 target){
  double bestDistance=Double.MAX_VALUE;
  int bestIndex=-1;
  for (int i=0; i < contour.size(); i++) {
    Point2D_I32 c=contour.get(i);
    double d=UtilPoint2D_F64.distanceSq(target.x,target.y,c.x,c.y);
    if (d < bestDistance) {
      bestDistance=d;
      bestIndex=i;
    }
  }
  return bestIndex;
}

Fixed version (ground truth):
/** 
 * Returns the closest point on the contour to the provided point in space
 * @return index of closest point
 */
int closestPoint(Point2D_F64 target){
  double bestDistance=Double.MAX_VALUE;
  int bestIndex=-1;
  for (int i=0; i < contour.size(); i++) {
    Point2D_I32 c=contour.get(i);
    double d=UtilPoint2D_F64.distanceSq(target.x,target.y,c.x,c.y);
    if (d < bestDistance) {
      bestDistance=d;
      bestIndex=i;
    }
  }
  return bestIndex;
}
Program: 150904
Project: 150904
Buggy source:
void fitLinesUsingCorners(int anchor0,int numLines){
  for (int i=1; i <= numLines; i++) {
    int index0=workCorners.get(CircularIndex.addOffset(anchor0,i - 1,workCorners.size));
    int index1=workCorners.get(CircularIndex.addOffset(anchor0,i,workCorners.size));
    if (!fitLine(workCorners.get(index0),workCorners.get(index1),lines.get(i - 1))) {
      throw new RuntimeException("String_Node_Str");
    }
  }
}

Fixed version (ground truth):
/** 
 * Fits lines across the sequence of corners
 * @param numLines number of lines it will fit
 */
boolean fitLinesUsingCorners(int numLines,GrowQueue_I32 cornerIndexes){
  for (int i=1; i <= numLines; i++) {
    int index0=cornerIndexes.get(CircularIndex.addOffset(anchor0,i - 1,cornerIndexes.size));
    int index1=cornerIndexes.get(CircularIndex.addOffset(anchor0,i,cornerIndexes.size));
    if (index0 == index1)     return false;
    if (!fitLine(index0,index1,lines.get(i - 1))) {
      throw new RuntimeException("String_Node_Str");
    }
    LineGeneral2D_F64 l=lines.get(i - 1);
    if (Double.isNaN(l.A) || Double.isNaN(l.B) || Double.isNaN(l.C)) {
      Point2D_I32 c0=contour.get(index0);
      Point2D_I32 c1=contour.get(index1);
      throw new RuntimeException("String_Node_Str");
    }
  }
  return true;
}
Program: 150905
Project: 150905
Buggy source:
boolean fitLine(int contourIndex0,int contourIndex1,LineGeneral2D_F64 line){
  int numPixels=CircularIndex.distanceP(contourIndex0,contourIndex1,contour.size());
  Point2D_I32 c0=contour.get(contourIndex0);
  Point2D_I32 c1=contour.get(contourIndex1);
  double scale=c0.distance(c1);
  double centerX=(c1.x + c0.x) / 2.0;
  double centerY=(c1.y + c0.y) / 2.0;
  pointsFit.reset();
  for (int i=0; i < numPixels; i++) {
    Point2D_I32 c=contour.get(CircularIndex.addOffset(contourIndex0,i,contour.size()));
    Point2D_F64 p=pointsFit.grow();
    p.x=(c.x - centerX) / scale;
    p.y=(c.y - centerY) / scale;
  }
  if (null == FitLine_F64.polar(pointsFit.toList(),linePolar)) {
    return false;
  }
  UtilLine2D_F64.convert(linePolar,line);
  line.C=scale * line.C - centerX * line.A - centerY * line.B;
  return true;
}

Fixed version (ground truth):
/** 
 * Given a sequence of points on the contour find the best fit line.
 * @param contourIndex0 contour index of first point in the sequence
 * @param contourIndex1 contour index of last point (exclusive) in the sequence
 * @param line storage for the found line
 * @return true if successful or false if it failed
 */
boolean fitLine(int contourIndex0,int contourIndex1,LineGeneral2D_F64 line){
  int numPixels=CircularIndex.distanceP(contourIndex0,contourIndex1,contour.size());
  Point2D_I32 c0=contour.get(contourIndex0);
  Point2D_I32 c1=contour.get(contourIndex1);
  double scale=c0.distance(c1);
  double centerX=(c1.x + c0.x) / 2.0;
  double centerY=(c1.y + c0.y) / 2.0;
  pointsFit.reset();
  for (int i=0; i < numPixels; i++) {
    Point2D_I32 c=contour.get(CircularIndex.addOffset(contourIndex0,i,contour.size()));
    Point2D_F64 p=pointsFit.grow();
    p.x=(c.x - centerX) / scale;
    p.y=(c.y - centerY) / scale;
  }
  if (null == FitLine_F64.polar(pointsFit.toList(),linePolar)) {
    return false;
  }
  UtilLine2D_F64.convert(linePolar,line);
  line.C=scale * line.C - centerX * line.A - centerY * line.B;
  return true;
}
Program: 150906
Project: 150906
Buggy source:
void linesIntoCorners(int anchor0,int numLines){
  for (int i=1; i < numLines; i++) {
    LineGeneral2D_F64 line0=lines.get(i - 1);
    LineGeneral2D_F64 line1=lines.get(i);
    if (null == Intersection2D_F64.intersection(line0,line1,intersection)) {
      throw new RuntimeException("String_Node_Str");
    }
    int contourIndex=closestPoint(intersection);
    int cornerIndex=CircularIndex.addOffset(anchor0,i,workCorners.size);
    workCorners.set(contourIndex,cornerIndex);
  }
}

Fixed version (ground truth):
/** 
 * finds the intersection of a line and update the corner index
 */
boolean linesIntoCorners(int numLines,GrowQueue_I32 contourCorners){
  GrowQueue_I32 skippedCorners=new GrowQueue_I32();
  int contourIndexPrevious=contourCorners.get(anchor0);
  for (int i=1; i < numLines; i++) {
    LineGeneral2D_F64 line0=lines.get(i - 1);
    LineGeneral2D_F64 line1=lines.get(i);
    int cornerIndex=CircularIndex.addOffset(anchor0,i,contourCorners.size);
    boolean skipped=false;
    if (null == Intersection2D_F64.intersection(line0,line1,intersection)) {
      if (verbose)       System.out.println("String_Node_Str");
      skipped=true;
    }
 else {
      int contourIndex=closestPoint(intersection);
      if (contourIndex != contourIndexPrevious) {
        Point2D_I32 a=contour.get(contourIndexPrevious);
        Point2D_I32 b=contour.get(contourIndex);
        if (a.x == b.x && a.y == b.y) {
          if (verbose)           System.out.println("String_Node_Str");
          skipped=true;
        }
 else {
          contourCorners.set(cornerIndex,contourIndex);
          contourIndexPrevious=contourIndex;
        }
      }
 else {
        if (verbose)         System.out.println("String_Node_Str");
        skipped=true;
      }
    }
    if (skipped) {
      skippedCorners.add(cornerIndex);
    }
  }
  int cornerIndex=CircularIndex.addOffset(anchor0,numLines,contourCorners.size);
  Point2D_I32 a=contour.get(contourIndexPrevious);
  Point2D_I32 b=contour.get(contourCorners.get(cornerIndex));
  if (a.x == b.x && a.y == b.y) {
    skippedCorners.add(cornerIndex);
  }
  Arrays.sort(skippedCorners.data,0,skippedCorners.size);
  for (int i=skippedCorners.size - 1; i >= 0; i--) {
    int index=skippedCorners.get(i);
    contourCorners.remove(index);
    if (anchor0 >= index) {
      anchor0--;
    }
    if (anchor1 >= index) {
      anchor1--;
    }
  }
  for (int i=0; i < contourCorners.size(); i++) {
    int j=(i + 1) % contourCorners.size();
    a=contour.get(contourCorners.get(i));
    b=contour.get(contourCorners.get(j));
    if (a.x == b.x && a.y == b.y) {
      throw new RuntimeException("String_Node_Str");
    }
  }
  return contourCorners.size() >= 3;
}
Program: 150907
Project: 150907
Buggy source:
/** 
 * Fits line segments along the contour with the first and last corner fixed at the original corners.  The output will be a new set of corner indexes.  Since the corner list is circular, it is assumed that anchor1 comes after anchor0.  The same index can be specified for an anchor, it will just go around the entire circle
 * @param anchor0 corner index of the first end point
 * @param anchor1 corner index of the second end point.
 * @param corners Initial location of the corners
 * @param output Optimized location of the corners
 */
public void fitAnchored(int anchor0,int anchor1,GrowQueue_I32 corners,GrowQueue_I32 output){
  int numLines=anchor0 == anchor1 ? corners.size() : CircularIndex.distanceP(anchor0,anchor1,corners.size);
  if (numLines < 2) {
    throw new RuntimeException("String_Node_Str");
  }
  int contourAnchor0=corners.get(anchor0);
  workCorners.setTo(corners);
  for (int iteration=0; iteration < maxIterations; iteration++) {
    fitLinesUsingCorners(anchor0,numLines);
    linesIntoCorners(anchor0,numLines);
    sanityCheckCornerOrder(anchor0,numLines,contourAnchor0);
  }
  output.setTo(workCorners);
}

Fixed version (ground truth):
/** 
 * Fits line segments along the contour with the first and last corner fixed at the original corners.  The output will be a new set of corner indexes.  Since the corner list is circular, it is assumed that anchor1 comes after anchor0.  The same index can be specified for an anchor, it will just go around the entire circle
 * @param anchor0 corner index of the first end point
 * @param anchor1 corner index of the second end point.
 * @param corners Initial location of the corners
 * @param output Optimized location of the corners
 */
public boolean fitAnchored(int anchor0,int anchor1,GrowQueue_I32 corners,GrowQueue_I32 output){
  this.anchor0=anchor0;
  this.anchor1=anchor1;
  int numLines=anchor0 == anchor1 ? corners.size() : CircularIndex.distanceP(anchor0,anchor1,corners.size);
  if (numLines < 2) {
    throw new RuntimeException("String_Node_Str");
  }
  lines.resize(numLines);
  Point2D_I32 hack=contour.get(corners.get(0));
  verbose=hack.x == 52 && hack.y == 61;
  if (verbose)   System.out.println("String_Node_Str");
  for (int i=0; i < corners.size(); ) {
    int j=(i + 1) % corners.size();
    int index0=corners.get(i);
    int index1=corners.get(j);
    Point2D_I32 a=contour.get(index0);
    Point2D_I32 b=contour.get(index1);
    if (a.x == b.x && a.y == b.y) {
      throw new RuntimeException("String_Node_Str");
    }
 else {
      i++;
    }
  }
  workCorners.setTo(corners);
  for (int iteration=0; iteration < maxIterations; iteration++) {
    if (!fitLinesUsingCorners(numLines,workCorners)) {
      return false;
    }
    if (!linesIntoCorners(numLines,workCorners)) {
      return false;
    }
    if (!sanityCheckCornerOrder(numLines,workCorners)) {
      return false;
    }
  }
  if (verbose)   System.out.println("String_Node_Str" + corners.size() + "String_Node_Str"+ workCorners.size());
  output.setTo(workCorners);
  return true;
}
Program: 150909
Project: 150909
Buggy source:
private void box(PrintStream out,final int bit){
  final int transitionBits[];
switch (gridSize) {
case THREE_BY_THREE:
    transitionBits=new int[]{0,3,4};
  break;
case FOUR_BY_FOUR:
transitionBits=new int[]{1,9,11};
break;
case FIVE_BY_FIVE:
transitionBits=new int[]{1,17,20};
break;
default :
throw new RuntimeException("String_Node_Str");
}
final int adjustedBit;
if (bit < transitionBits[0]) adjustedBit=bit + 1;
 else if (bit < transitionBits[1]) adjustedBit=bit + 2;
 else if (bit < transitionBits[2]) adjustedBit=bit + 3;
 else throw new RuntimeException("String_Node_Str" + transitionBits[2]);
int x=adjustedBit % gridSize.getWidth();
int y=adjustedBit / gridSize.getWidth();
out.print("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str");
}

Fixed version (ground truth):
private void box(PrintStream out,final int bit){
  final int transitionBits[];
switch (gridSize) {
case THREE_BY_THREE:
    transitionBits=new int[]{0,3,4};
  break;
case FOUR_BY_FOUR:
transitionBits=new int[]{1,9,11};
break;
case FIVE_BY_FIVE:
transitionBits=new int[]{1,17,20};
break;
default :
throw new RuntimeException("String_Node_Str");
}
final int adjustedBit;
if (bit <= transitionBits[0]) adjustedBit=bit + 1;
 else if (bit <= transitionBits[1]) adjustedBit=bit + 2;
 else if (bit <= transitionBits[2]) adjustedBit=bit + 3;
 else throw new RuntimeException("String_Node_Str" + transitionBits[2]);
int x=adjustedBit % gridSize.getWidth();
int y=adjustedBit / gridSize.getWidth();
out.print("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str");
}
Program: 150910
Project: 150910
Buggy source:
/** 
 * Configures the fiducial detector, specifying the grid type.
 * @param inputType Type of image it's processing
 */
public DetectFiducialSquareBinary(final BinaryFiducialGridSize gridSize,final InputToBinary<T> inputToBinary,final BinaryPolygonDetector<T> quadDetector,Class<T> inputType){
  super(inputToBinary,quadDetector,(w * gridSize.getWidth() + 4 * w),inputType);
  this.gridSize=gridSize;
  final int elCount=gridSize.getWidth();
  binaryInner.reshape(w * elCount,w * elCount);
  counts=new int[elCount];
  classified=new int[elCount];
  tmp=new int[elCount];
}

Fixed version (ground truth):
/** 
 * Configures the fiducial detector, specifying the grid type.
 * @param inputType Type of image it's processing
 */
public DetectFiducialSquareBinary(final BinaryFiducialGridSize gridSize,final InputToBinary<T> inputToBinary,final BinaryPolygonDetector<T> quadDetector,Class<T> inputType){
  super(inputToBinary,quadDetector,(w * gridSize.getWidth() + 4 * w),inputType);
  this.gridSize=gridSize;
  binaryInner.reshape(w * gridSize.getWidth(),w * gridSize.getWidth());
  counts=new int[gridSize.getNumberOfElements()];
  classified=new int[gridSize.getNumberOfElements()];
  tmp=new int[gridSize.getNumberOfElements()];
}
Program: 150911
Project: 150911
Buggy source:
private void box(PrintStream out,final int bit){
  final int transitionBits[];
switch (gridSize) {
case THREE_BY_THREE:
    transitionBits=new int[]{0,3,4};
  break;
case FOUR_BY_FOUR:
transitionBits=new int[]{1,9,11};
break;
case FIVE_BY_FIVE:
transitionBits=new int[]{1,17,20};
break;
default :
throw new RuntimeException("String_Node_Str");
}
final int adjustedBit;
if (bit <= transitionBits[0]) adjustedBit=bit + 1;
 else if (bit <= transitionBits[1]) adjustedBit=bit + 2;
 else if (bit <= transitionBits[2]) adjustedBit=bit + 3;
 else throw new RuntimeException("String_Node_Str" + transitionBits[2]);
int x=adjustedBit % gridSize.getWidth();
int y=adjustedBit / gridSize.getWidth();
out.print("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str");
}

Fixed version (ground truth):
private void box(PrintStream out,final int bit){
  final int transitionBits[];
switch (gridSize) {
case THREE_BY_THREE:
    transitionBits=new int[]{0,3,4};
  break;
case FOUR_BY_FOUR:
transitionBits=new int[]{1,9,11};
break;
case FIVE_BY_FIVE:
transitionBits=new int[]{2,17,20};
break;
default :
throw new RuntimeException("String_Node_Str");
}
final int adjustedBit;
if (bit <= transitionBits[0]) adjustedBit=bit + 1;
 else if (bit <= transitionBits[1]) adjustedBit=bit + 2;
 else if (bit <= transitionBits[2]) adjustedBit=bit + 3;
 else throw new RuntimeException("String_Node_Str" + transitionBits[2]);
int x=adjustedBit % gridSize.getWidth();
int y=adjustedBit / gridSize.getWidth();
out.print("String_Node_Str" + x + "String_Node_Str"+ y+ "String_Node_Str");
}
Program: 150912
Project: 150912
Buggy source:
@Override public void adjustBeforeOptimize(Polygon2D_F64 polygon){
  center.x=0;
  center.y=0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    center.x+=p.x;
    center.y+=p.y;
  }
  center.x/=4.0;
  center.y/=4.0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    double dx=p.x - center.x;
    double dy=p.y - center.y;
    double r=Math.sqrt(dx * dx + dy * dy);
    p.x+=1.4 * dx / r;
    p.y+=1.4 * dy / r;
  }
}

Fixed version (ground truth):
@Override public void adjustBeforeOptimize(Polygon2D_F64 polygon){
  center.x=0;
  center.y=0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    center.x+=p.x;
    center.y+=p.y;
  }
  center.x/=4.0;
  center.y/=4.0;
  for (int j=0; j < 4; j++) {
    Point2D_F64 p=polygon.get(j);
    double dx=p.x - center.x;
    double dy=p.y - center.y;
    double r=Math.sqrt(dx * dx + dy * dy);
    if (r > 0) {
      p.x+=1.4 * dx / r;
      p.y+=1.4 * dy / r;
    }
  }
}
Program: 150913
Project: 150913
Buggy source:
public static void main(String args[]){
  String directory="String_Node_Str";
  BufferedImage orig=UtilImageIO.loadImage(directory + "String_Node_Str");
  ImageFloat32 input=ConvertBufferedImage.convertFrom(orig,(ImageFloat32)null);
  PlanarCalibrationDetector detector;
  detector=FactoryPlanarCalibrationTarget.detectorChessboard(new ConfigChessboard(5,7,30));
  if (!detector.process(input))   throw new RuntimeException("String_Node_Str");
  List<Point2D_F64> points=detector.getDetectedPoints();
  Graphics2D g2=orig.createGraphics();
  for (  Point2D_F64 p : points)   VisualizeFeatures.drawPoint(g2,(int)p.x,(int)p.y,3,Color.RED);
  ShowImages.showWindow(orig,"String_Node_Str");
}

Fixed version (ground truth):
public static void main(String args[]){
  String directory="String_Node_Str";
  BufferedImage orig=UtilImageIO.loadImage(directory + "String_Node_Str");
  ImageFloat32 input=ConvertBufferedImage.convertFrom(orig,(ImageFloat32)null);
  PlanarCalibrationDetector detector;
  detector=FactoryPlanarCalibrationTarget.detectorChessboard(new ConfigChessboard(5,7,30));
  if (!detector.process(input))   throw new RuntimeException("String_Node_Str");
  List<Point2D_F64> points=detector.getDetectedPoints();
  Graphics2D g2=orig.createGraphics();
  for (  Point2D_F64 p : points)   VisualizeFeatures.drawPoint(g2,(int)p.x,(int)p.y,3,Color.RED);
  ShowImages.showWindow(orig,"String_Node_Str",true);
}
Program: 150916
Project: 150916
Buggy source:
public static void main(String args[]){
  BufferedImage input=UtilImageIO.loadImage("String_Node_Str");
  MultiSpectral<ImageUInt8> imageRGB=ConvertBufferedImage.convertFromMulti(input,null,true,ImageUInt8.class);
  StereoParameters stereoParam=UtilIO.loadXML("String_Node_Str");
  Se3_F64 groundToLeft=UtilIO.loadXML("String_Node_Str");
  CreateSyntheticOverheadView<MultiSpectral<ImageUInt8>> generateOverhead=new CreateSyntheticOverheadViewMS<ImageUInt8>(TypeInterpolate.BILINEAR,3,ImageUInt8.class);
  double cellSize=0.05;
  SelectOverheadParameters selectMapSize=new SelectOverheadParameters(cellSize,20,0.5);
  selectMapSize.process(stereoParam.left,groundToLeft);
  int overheadWidth=selectMapSize.getOverheadWidth();
  int overheadHeight=selectMapSize.getOverheadHeight();
  MultiSpectral<ImageUInt8> overheadRGB=new MultiSpectral<ImageUInt8>(ImageUInt8.class,overheadWidth,overheadHeight,3);
  generateOverhead.configure(stereoParam.left,groundToLeft,selectMapSize.getCenterX(),selectMapSize.getCenterY(),cellSize,overheadRGB.width,overheadRGB.height);
  generateOverhead.process(imageRGB,overheadRGB);
  BufferedImage output=ConvertBufferedImage.convertTo(overheadRGB,null,true);
  ShowImages.showWindow(input,"String_Node_Str");
  ShowImages.showWindow(output,"String_Node_Str");
}

Fixed version (ground truth):
public static void main(String args[]){
  BufferedImage input=UtilImageIO.loadImage("String_Node_Str");
  MultiSpectral<ImageUInt8> imageRGB=ConvertBufferedImage.convertFromMulti(input,null,true,ImageUInt8.class);
  StereoParameters stereoParam=UtilIO.loadXML("String_Node_Str");
  Se3_F64 groundToLeft=UtilIO.loadXML("String_Node_Str");
  CreateSyntheticOverheadView<MultiSpectral<ImageUInt8>> generateOverhead=new CreateSyntheticOverheadViewMS<ImageUInt8>(TypeInterpolate.BILINEAR,3,ImageUInt8.class);
  double cellSize=0.05;
  SelectOverheadParameters selectMapSize=new SelectOverheadParameters(cellSize,20,0.5);
  selectMapSize.process(stereoParam.left,groundToLeft);
  int overheadWidth=selectMapSize.getOverheadWidth();
  int overheadHeight=selectMapSize.getOverheadHeight();
  MultiSpectral<ImageUInt8> overheadRGB=new MultiSpectral<ImageUInt8>(ImageUInt8.class,overheadWidth,overheadHeight,3);
  generateOverhead.configure(stereoParam.left,groundToLeft,selectMapSize.getCenterX(),selectMapSize.getCenterY(),cellSize,overheadRGB.width,overheadRGB.height);
  generateOverhead.process(imageRGB,overheadRGB);
  BufferedImage output=ConvertBufferedImage.convertTo(overheadRGB,null,true);
  ShowImages.showWindow(input,"String_Node_Str",true);
  ShowImages.showWindow(output,"String_Node_Str",true);
}
Program: 150917
Project: 150917
Buggy source:
public static void main(String[] args){
  BufferedImage buffered=UtilImageIO.loadImage("String_Node_Str");
  MultiSpectral<ImageFloat32> input=ConvertBufferedImage.convertFromMulti(buffered,null,true,ImageFloat32.class);
  MultiSpectral<ImageFloat32> output=input._createNew(400,500);
  Estimate1ofEpipolar computeHomography=FactoryMultiView.computeHomography(true);
  ArrayList<AssociatedPair> associatedPairs=new ArrayList<AssociatedPair>();
  associatedPairs.add(new AssociatedPair(new Point2D_F64(0,0),new Point2D_F64(267,182)));
  associatedPairs.add(new AssociatedPair(new Point2D_F64(output.width - 1,0),new Point2D_F64(542,68)));
  associatedPairs.add(new AssociatedPair(new Point2D_F64(output.width - 1,output.height - 1),new Point2D_F64(519,736)));
  associatedPairs.add(new AssociatedPair(new Point2D_F64(0,output.height - 1),new Point2D_F64(276,570)));
  DenseMatrix64F H=new DenseMatrix64F(3,3);
  computeHomography.process(associatedPairs,H);
  PointTransformHomography_F32 homography=new PointTransformHomography_F32(H);
  PixelTransform_F32 pixelTransform=new PointToPixelTransform_F32(homography);
  DistortImageOps.distortMS(input,output,pixelTransform,null,TypeInterpolate.BILINEAR);
  BufferedImage flat=ConvertBufferedImage.convertTo_F32(output,null,true);
  ShowImages.showWindow(buffered,"String_Node_Str");
  ShowImages.showWindow(flat,"String_Node_Str");
}

Fixed version (ground truth):
public static void main(String[] args){
  BufferedImage buffered=UtilImageIO.loadImage("String_Node_Str");
  MultiSpectral<ImageFloat32> input=ConvertBufferedImage.convertFromMulti(buffered,null,true,ImageFloat32.class);
  MultiSpectral<ImageFloat32> output=input._createNew(400,500);
  Estimate1ofEpipolar computeHomography=FactoryMultiView.computeHomography(true);
  ArrayList<AssociatedPair> associatedPairs=new ArrayList<AssociatedPair>();
  associatedPairs.add(new AssociatedPair(new Point2D_F64(0,0),new Point2D_F64(267,182)));
  associatedPairs.add(new AssociatedPair(new Point2D_F64(output.width - 1,0),new Point2D_F64(542,68)));
  associatedPairs.add(new AssociatedPair(new Point2D_F64(output.width - 1,output.height - 1),new Point2D_F64(519,736)));
  associatedPairs.add(new AssociatedPair(new Point2D_F64(0,output.height - 1),new Point2D_F64(276,570)));
  DenseMatrix64F H=new DenseMatrix64F(3,3);
  computeHomography.process(associatedPairs,H);
  PointTransformHomography_F32 homography=new PointTransformHomography_F32(H);
  PixelTransform_F32 pixelTransform=new PointToPixelTransform_F32(homography);
  DistortImageOps.distortMS(input,output,pixelTransform,null,TypeInterpolate.BILINEAR);
  BufferedImage flat=ConvertBufferedImage.convertTo_F32(output,null,true);
  ShowImages.showWindow(buffered,"String_Node_Str",true);
  ShowImages.showWindow(flat,"String_Node_Str",true);
}
Program: 150918
Project: 150918
Buggy source:
@Override public <T extends ImageBase>SimpleImageSequence<T> load(String fileName,ImageType<T> imageType){
  if (xuggler != null) {
    return xuggler.load(fileName,imageType);
  }
 else   if (jcodec != null) {
    if (fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str")) {
      return jcodec.load(fileName,imageType);
    }
  }
  if (fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str")|| fileName.endsWith("String_Node_Str")) {
    try {
      VideoMjpegCodec codec=new VideoMjpegCodec();
      List<byte[]> data=codec.read(new FileInputStream(fileName));
      return new JpegByteImageSequence<T>(imageType,data,false);
    }
 catch (    FileNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
 else   if (fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str")) {
    try {
      return new ImageStreamSequence<T>(fileName,true,imageType);
    }
 catch (    FileNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
  throw new IllegalArgumentException("String_Node_Str");
}

Fixed version (ground truth):
@Override public <T extends ImageBase>SimpleImageSequence<T> load(String fileName,ImageType<T> imageType){
  try {
    if (xuggler != null) {
      return xuggler.load(fileName,imageType);
    }
  }
 catch (  RuntimeException ignore) {
  }
  try {
    if (jcodec != null) {
      if (fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str")) {
        return jcodec.load(fileName,imageType);
      }
    }
  }
 catch (  RuntimeException ignore) {
  }
  if (fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str")|| fileName.endsWith("String_Node_Str")) {
    try {
      VideoMjpegCodec codec=new VideoMjpegCodec();
      List<byte[]> data=codec.read(new FileInputStream(fileName));
      return new JpegByteImageSequence<T>(imageType,data,false);
    }
 catch (    FileNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
 else   if (fileName.endsWith("String_Node_Str") || fileName.endsWith("String_Node_Str")) {
    try {
      return new ImageStreamSequence<T>(fileName,true,imageType);
    }
 catch (    FileNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
  throw new IllegalArgumentException("String_Node_Str");
}
Program: 150920
Project: 150920
Buggy source:
@Override protected void updateBackground(int x0,int y0,int x1,int y1,T frame){
  transform.setModel(worldToCurrent);
  interpolationInput.setImage(frame);
  final int numBands=frame.getNumBands();
  float minusLearn=1.0f - learnRate;
  for (int y=y0; y < y1; y++) {
    int indexBG=background.startIndex + y * background.stride + x0 * numBands;
    for (int x=x0; x < x1; x++) {
      transform.compute(x,y,work);
      if (work.x >= 0 && work.x < frame.width && work.y >= 0 && work.y < frame.height) {
        interpolationInput.get(work.x,work.y,pixelInput);
        for (int band=0; band < numBands; band++, indexBG++) {
          float value=pixelInput[band];
          float bg=background.data[indexBG];
          if (bg == Float.MAX_VALUE) {
            background.data[indexBG]=value;
          }
 else {
            background.data[indexBG]=minusLearn * bg + learnRate * value;
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override protected void updateBackground(int x0,int y0,int x1,int y1,T frame){
  transform.setModel(worldToCurrent);
  interpolationInput.setImage(frame);
  final int numBands=frame.getNumBands();
  float minusLearn=1.0f - learnRate;
  for (int y=y0; y < y1; y++) {
    int indexBG=background.startIndex + y * background.stride + x0 * numBands;
    for (int x=x0; x < x1; x++) {
      transform.compute(x,y,work);
      if (work.x >= 0 && work.x < frame.width && work.y >= 0 && work.y < frame.height) {
        interpolationInput.get(work.x,work.y,pixelInput);
        for (int band=0; band < numBands; band++, indexBG++) {
          float value=pixelInput[band];
          float bg=background.data[indexBG];
          if (bg == Float.MAX_VALUE) {
            background.data[indexBG]=value;
          }
 else {
            background.data[indexBG]=minusLearn * bg + learnRate * value;
          }
        }
      }
 else {
        indexBG+=numBands;
      }
    }
  }
}