nus-yam/ex-repair huggingface dataset:
Program: 150970
Project: 150970
Buggy source:
@Test public void compareToStandard_symmetric(){
  CompareToStandardConvolution a=new CompareToStandardConvolution(ConvolveImageNoBorder.class);
  a.setKernelRadius(2);
  a.setOffset(2);
  a.performTests(22);
}

Fixed version (ground truth):
@Test public void compareToStandard_symmetric(){
  CompareToStandardConvolution a=new CompareToStandardConvolution(ConvolveImageNoBorder.class);
  a.setKernelWidth(5);
  a.setOffset(2);
  a.performTests(22);
}
Program: 150971
Project: 150971
Buggy source:
@Test public void compareToStandard_UNsymmetric(){
  CompareToStandardConvolution a=new CompareToStandardConvolution(ConvolveImageNoBorder.class);
  a.setKernelRadius(2);
  a.setOffset(1);
  a.performTests(22);
}

Fixed version (ground truth):
@Test public void compareToStandard_UNsymmetric(){
  CompareToStandardConvolution a=new CompareToStandardConvolution(ConvolveImageNoBorder.class);
  a.setKernelWidth(5);
  a.setOffset(1);
  a.performTests(22);
}
Program: 150972
Project: 150972
Buggy source:
public static void main(String args[]){
  String calibDir="String_Node_Str";
  String imageDir="String_Node_Str";
  IntrinsicParameters param=UtilIO.loadXML(calibDir + "String_Node_Str");
  BufferedImage orig=UtilImageIO.loadImage(imageDir + "String_Node_Str");
  MultiSpectral<ImageFloat32> distortedImg=ConvertBufferedImage.convertFromMulti(orig,null,true,ImageFloat32.class);
  int numBands=distortedImg.getNumBands();
  ImageDistort allInside=LensDistortionOps.removeDistortion(true,null,param,null,ImageType.ms(numBands,ImageFloat32.class));
  ImageDistort fullView=LensDistortionOps.removeDistortion(false,null,param,null,ImageType.ms(numBands,ImageFloat32.class));
  displayResults(orig,distortedImg,allInside,fullView);
}

Fixed version (ground truth):
public static void main(String args[]){
  String calibDir="String_Node_Str";
  String imageDir="String_Node_Str";
  IntrinsicParameters param=UtilIO.loadXML(calibDir + "String_Node_Str");
  BufferedImage orig=UtilImageIO.loadImage(imageDir + "String_Node_Str");
  MultiSpectral<ImageFloat32> distortedImg=ConvertBufferedImage.convertFromMulti(orig,null,true,ImageFloat32.class);
  int numBands=distortedImg.getNumBands();
  ImageDistort allInside=LensDistortionOps.removeDistortion(true,BorderType.VALUE,param,null,ImageType.ms(numBands,ImageFloat32.class));
  ImageDistort fullView=LensDistortionOps.removeDistortion(false,BorderType.VALUE,param,null,ImageType.ms(numBands,ImageFloat32.class));
  displayResults(orig,distortedImg,allInside,fullView);
}
Program: 150973
Project: 150973
Buggy source:
public static void threshold(String imageName){
  BufferedImage image=UtilImageIO.loadImage(imageName);
  ImageFloat32 input=ConvertBufferedImage.convertFromSingle(image,null,ImageFloat32.class);
  ImageUInt8 binary=new ImageUInt8(input.width,input.height);
  ListDisplayPanel gui=new ListDisplayPanel();
  GThresholdImageOps.threshold(input,binary,ImageStatistics.mean(input),true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.threshold(input,binary,GThresholdImageOps.computeOtsu(input,0,256),true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.threshold(input,binary,GThresholdImageOps.computeEntropy(input,0,256),true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.adaptiveSquare(input,binary,28,0,true,null,null);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.adaptiveGaussian(input,binary,42,0,true,null,null);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.adaptiveSauvola(input,binary,5,0.50f,true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  gui.addImage(ConvertBufferedImage.convertTo(input,null),"String_Node_Str");
  String fileName=imageName.substring(imageName.lastIndexOf('/') + 1);
  ShowImages.showWindow(gui,fileName);
}

Fixed version (ground truth):
public static void threshold(String imageName){
  BufferedImage image=UtilImageIO.loadImage(imageName);
  ImageFloat32 input=ConvertBufferedImage.convertFromSingle(image,null,ImageFloat32.class);
  ImageUInt8 binary=new ImageUInt8(input.width,input.height);
  ListDisplayPanel gui=new ListDisplayPanel();
  GThresholdImageOps.threshold(input,binary,ImageStatistics.mean(input),true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.threshold(input,binary,GThresholdImageOps.computeOtsu(input,0,256),true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.threshold(input,binary,GThresholdImageOps.computeEntropy(input,0,256),true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.adaptiveSquare(input,binary,28,0,true,null,null);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.adaptiveGaussian(input,binary,42,0,true,null,null);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  GThresholdImageOps.adaptiveSauvola(input,binary,5,0.30f,true);
  gui.addImage(VisualizeBinaryData.renderBinary(binary,null),"String_Node_Str");
  gui.addImage(ConvertBufferedImage.convertTo(input,null),"String_Node_Str");
  String fileName=imageName.substring(imageName.lastIndexOf('/') + 1);
  ShowImages.showWindow(gui,fileName);
}
Program: 150974
Project: 150974
Buggy source:
/** 
 * Applies   {@link boofcv.alg.filter.binary.impl.ThresholdSauvola Sauvola} thresholding to the input image.Intended for use with text image.
 * @see boofcv.alg.filter.binary.impl.ThresholdSauvola
 * @param input Input image.
 * @param output (optional) Output binary image.  If null it will be declared internally.
 * @param radius Radius of local region.  Try 15
 * @param k Positive parameter used to tune threshold.  Try 0.5
 * @param down Should it threshold up or down.
 * @return binary image
 */
public static <T extends ImageSingleBand>ImageUInt8 adaptiveSauvola(T input,ImageUInt8 output,int radius,float k,boolean down){
  ThresholdSauvola alg=new ThresholdSauvola(radius,k,down);
  if (output == null)   output=new ImageUInt8(input.width,input.height);
  if (input instanceof ImageFloat32) {
    alg.process((ImageFloat32)input,output);
  }
 else {
    ImageFloat32 conv=new ImageFloat32(input.width,input.height);
    GConvertImage.convert(input,conv);
    alg.process(conv,output);
  }
  return output;
}

Fixed version (ground truth):
/** 
 * Applies   {@link boofcv.alg.filter.binary.impl.ThresholdSauvola Sauvola} thresholding to the input image.Intended for use with text image.
 * @see boofcv.alg.filter.binary.impl.ThresholdSauvola
 * @param input Input image.
 * @param output (optional) Output binary image.  If null it will be declared internally.
 * @param radius Radius of local region.  Try 15
 * @param k Positive parameter used to tune threshold.  Try 0.3
 * @param down Should it threshold up or down.
 * @return binary image
 */
public static <T extends ImageSingleBand>ImageUInt8 adaptiveSauvola(T input,ImageUInt8 output,int radius,float k,boolean down){
  ThresholdSauvola alg=new ThresholdSauvola(radius,k,down);
  if (output == null)   output=new ImageUInt8(input.width,input.height);
  if (input instanceof ImageFloat32) {
    alg.process((ImageFloat32)input,output);
  }
 else {
    ImageFloat32 conv=new ImageFloat32(input.width,input.height);
    GConvertImage.convert(input,conv);
    alg.process(conv,output);
  }
  return output;
}
Program: 150975
Project: 150975
Buggy source:
/** 
 * Configures the algorithm.
 * @param radius size of local radius.  Try 15
 * @param k User specified threshold adjustment factor.  Must be positive. Try 0.5
 * @param down Threshold down or up
 */
public ThresholdSauvola(int radius,float k,boolean down){
  this.k=k;
  this.radius=radius;
  this.down=down;
}

Fixed version (ground truth):
/** 
 * Configures the algorithm.
 * @param radius size of local radius.  Try 15
 * @param k User specified threshold adjustment factor.  Must be positive. Try 0.3
 * @param down Threshold down or up
 */
public ThresholdSauvola(int radius,float k,boolean down){
  this.k=k;
  this.radius=radius;
  this.down=down;
}
Program: 150977
Project: 150977
Buggy source:
@Override protected Object[][] createInputParam(Method candidate,Method validation){
  Class c[]=candidate.getParameterTypes();
  ImageSingleBand input=GeneralizedImageOps.createSingleBand(c[0],width,height);
  ImageSingleBand output=GeneralizedImageOps.createSingleBand(c[1],width,height);
  GImageMiscOps.fillUniform(input,rand,0,20);
  Object[][] ret=new Object[1][];
  ret[0]=new Object[]{input,output,kernelRadius};
  return ret;
}

Fixed version (ground truth):
@Override protected Object[][] createInputParam(Method candidate,Method validation){
  Class c[]=candidate.getParameterTypes();
  ImageSingleBand input=GeneralizedImageOps.createSingleBand(c[0],width,height);
  ImageSingleBand output=GeneralizedImageOps.createSingleBand(c[1],width,height);
  GImageMiscOps.fillUniform(input,rand,0,20);
  Object[][] ret=new Object[2][];
  ret[0]=new Object[]{input,output,kernelRadius};
  ret[1]=new Object[]{input,output,kernelRadius2};
  return ret;
}
Program: 150978
Project: 150978
Buggy source:
public static <T extends ImageBase>SegmentFelzenszwalbHuttenlocher04<T> fh04(ConfigFh04 config,ImageType<T> imageType){
  if (config == null)   config=new ConfigFh04();
  FhEdgeWeights<T> edgeWeights=weightsFelzenszwalb04(config.connectRule,imageType);
  SegmentFelzenszwalbHuttenlocher04<T> alg=new SegmentFelzenszwalbHuttenlocher04<T>(config.K,config.minimumRegionSize,edgeWeights);
  if (config.minimumRegionSize > 0) {
    alg.configureApproximateSort(config.approximateSortBins);
  }
  return alg;
}

Fixed version (ground truth):
public static <T extends ImageBase>SegmentFelzenszwalbHuttenlocher04<T> fh04(ConfigFh04 config,ImageType<T> imageType){
  if (config == null)   config=new ConfigFh04();
  FhEdgeWeights<T> edgeWeights=weightsFelzenszwalb04(config.connectRule,imageType);
  SegmentFelzenszwalbHuttenlocher04<T> alg=new SegmentFelzenszwalbHuttenlocher04<T>(config.K,config.minimumRegionSize,edgeWeights);
  if (config.approximateSortBins > 0) {
    alg.configureApproximateSort(config.approximateSortBins);
  }
  return alg;
}
Program: 150979
Project: 150979
Buggy source:
public SURF(){
  detector=FactoryDetectDescribe.surfFast(new ConfigFastHessian(20,2,-1,1,9,4,4),null,null,ImageType.single(imageType));
}

Fixed version (ground truth):
public SURF(){
  detector=FactoryDetectDescribe.surfFast(new ConfigFastHessian(20,2,-1,1,9,4,4),null,null,imageType);
}
Program: 150980
Project: 150980
Buggy source:
public VisualizeAssociationAlgorithmsApp(Class<T> imageType){
  super(1);
  this.imageType=imageType;
  detector=(DetectDescribePoint)FactoryDetectDescribe.surfStable(new ConfigFastHessian(5,4,200,1,9,4,4),null,null,ImageType.single(ImageFloat32.class));
  int DOF=detector.createDescription().size();
  ScoreAssociation<TupleDesc_F64> score=FactoryAssociation.scoreEuclidean(TupleDesc_F64.class,true);
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.greedy(score,Double.MAX_VALUE,false));
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.greedy(score,Double.MAX_VALUE,true));
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.kdtree(DOF,75));
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.kdRandomForest(DOF,75,10,5,1233445565));
  image0=GeneralizedImageOps.createSingleBand(imageType,1,1);
  image1=GeneralizedImageOps.createSingleBand(imageType,1,1);
  setMainGUI(panel);
}

Fixed version (ground truth):
public VisualizeAssociationAlgorithmsApp(Class<T> imageType){
  super(1);
  this.imageType=imageType;
  detector=(DetectDescribePoint)FactoryDetectDescribe.surfStable(new ConfigFastHessian(5,4,200,1,9,4,4),null,null,ImageFloat32.class);
  int DOF=detector.createDescription().size();
  ScoreAssociation<TupleDesc_F64> score=FactoryAssociation.scoreEuclidean(TupleDesc_F64.class,true);
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.greedy(score,Double.MAX_VALUE,false));
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.greedy(score,Double.MAX_VALUE,true));
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.kdtree(DOF,75));
  addAlgorithm(0,"String_Node_Str",FactoryAssociation.kdRandomForest(DOF,75,10,5,1233445565));
  image0=GeneralizedImageOps.createSingleBand(imageType,1,1);
  image1=GeneralizedImageOps.createSingleBand(imageType,1,1);
  setMainGUI(panel);
}
Program: 150981
Project: 150981
Buggy source:
public static void main(String args[]){
  Class imageType=ImageFloat32.class;
  DetectDescribePoint detDesc=FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,ImageType.single(imageType));
  ScoreAssociation scorer=FactoryAssociation.defaultScore(detDesc.getDescriptionType());
  AssociateDescription associate=FactoryAssociation.greedy(scorer,Double.MAX_VALUE,true);
  ExampleAssociatePoints app=new ExampleAssociatePoints(detDesc,associate,imageType);
  BufferedImage imageA=UtilImageIO.loadImage("String_Node_Str");
  BufferedImage imageB=UtilImageIO.loadImage("String_Node_Str");
  app.associate(imageA,imageB);
}

Fixed version (ground truth):
public static void main(String args[]){
  Class imageType=ImageFloat32.class;
  DetectDescribePoint detDesc=FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,imageType);
  ScoreAssociation scorer=FactoryAssociation.defaultScore(detDesc.getDescriptionType());
  AssociateDescription associate=FactoryAssociation.greedy(scorer,Double.MAX_VALUE,true);
  ExampleAssociatePoints app=new ExampleAssociatePoints(detDesc,associate,imageType);
  BufferedImage imageA=UtilImageIO.loadImage("String_Node_Str");
  BufferedImage imageB=UtilImageIO.loadImage("String_Node_Str");
  app.associate(imageA,imageB);
}
Program: 150982
Project: 150982
Buggy source:
/** 
 * For some features, there are pre-made implementations of DetectDescribePoint.  This has only been done in situations where there was a performance advantage or that it was a very common combination.
 */
public static <T extends ImageSingleBand,TD extends TupleDesc>DetectDescribePoint<T,TD> createFromPremade(Class<T> imageType){
  return (DetectDescribePoint)FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,ImageType.single(imageType));
}

Fixed version (ground truth):
/** 
 * For some features, there are pre-made implementations of DetectDescribePoint.  This has only been done in situations where there was a performance advantage or that it was a very common combination.
 */
public static <T extends ImageSingleBand,TD extends TupleDesc>DetectDescribePoint<T,TD> createFromPremade(Class<T> imageType){
  return (DetectDescribePoint)FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,imageType);
}
Program: 150983
Project: 150983
Buggy source:
/** 
 * Use generalized interfaces for working with SURF.  This removes much of the drudgery, but also reduces flexibility and slightly increases memory and computational requirements.
 * @param image Input image type. DOES NOT NEED TO BE ImageFloat32, ImageUInt8 works too
 */
public static void easy(ImageFloat32 image){
  DetectDescribePoint<ImageFloat32,SurfFeature> surf=FactoryDetectDescribe.surfStable(new ConfigFastHessian(0,2,200,2,9,4,4),null,null,ImageType.single(ImageFloat32.class));
  surf.detect(image);
  System.out.println("String_Node_Str" + surf.getNumberOfFeatures());
  System.out.println("String_Node_Str" + surf.getDescription(0).value[0]);
}

Fixed version (ground truth):
/** 
 * Use generalized interfaces for working with SURF.  This removes much of the drudgery, but also reduces flexibility and slightly increases memory and computational requirements.
 * @param image Input image type. DOES NOT NEED TO BE ImageFloat32, ImageUInt8 works too
 */
public static void easy(ImageFloat32 image){
  DetectDescribePoint<ImageFloat32,SurfFeature> surf=FactoryDetectDescribe.surfStable(new ConfigFastHessian(0,2,200,2,9,4,4),null,null,ImageFloat32.class);
  surf.detect(image);
  System.out.println("String_Node_Str" + surf.getNumberOfFeatures());
  System.out.println("String_Node_Str" + surf.getDescription(0).value[0]);
}
Program: 150984
Project: 150984
Buggy source:
/** 
 * Given two input images create and display an image where the two have been overlayed on top of each other.
 */
public static <T extends ImageSingleBand>void stitch(BufferedImage imageA,BufferedImage imageB,Class<T> imageType){
  T inputA=ConvertBufferedImage.convertFromSingle(imageA,null,imageType);
  T inputB=ConvertBufferedImage.convertFromSingle(imageB,null,imageType);
  DetectDescribePoint detDesc=FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,ImageType.single(imageType));
  ScoreAssociation<SurfFeature> scorer=FactoryAssociation.scoreEuclidean(SurfFeature.class,true);
  AssociateDescription<SurfFeature> associate=FactoryAssociation.greedy(scorer,2,true);
  ModelManager<Homography2D_F64> manager=new ModelManagerHomography2D_F64();
  GenerateHomographyLinear modelFitter=new GenerateHomographyLinear(true);
  DistanceHomographySq distance=new DistanceHomographySq();
  ModelMatcher<Homography2D_F64,AssociatedPair> modelMatcher=new Ransac<Homography2D_F64,AssociatedPair>(123,manager,modelFitter,distance,60,9);
  Homography2D_F64 H=computeTransform(inputA,inputB,detDesc,associate,modelMatcher);
  renderStitching(imageA,imageB,H);
}

Fixed version (ground truth):
/** 
 * Given two input images create and display an image where the two have been overlayed on top of each other.
 */
public static <T extends ImageSingleBand>void stitch(BufferedImage imageA,BufferedImage imageB,Class<T> imageType){
  T inputA=ConvertBufferedImage.convertFromSingle(imageA,null,imageType);
  T inputB=ConvertBufferedImage.convertFromSingle(imageB,null,imageType);
  DetectDescribePoint detDesc=FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,imageType);
  ScoreAssociation<SurfFeature> scorer=FactoryAssociation.scoreEuclidean(SurfFeature.class,true);
  AssociateDescription<SurfFeature> associate=FactoryAssociation.greedy(scorer,2,true);
  ModelManager<Homography2D_F64> manager=new ModelManagerHomography2D_F64();
  GenerateHomographyLinear modelFitter=new GenerateHomographyLinear(true);
  DistanceHomographySq distance=new DistanceHomographySq();
  ModelMatcher<Homography2D_F64,AssociatedPair> modelMatcher=new Ransac<Homography2D_F64,AssociatedPair>(123,manager,modelFitter,distance,60,9);
  Homography2D_F64 H=computeTransform(inputA,inputB,detDesc,associate,modelMatcher);
  renderStitching(imageA,imageB,H);
}
Program: 150985
Project: 150985
Buggy source:
/** 
 * Use the associate point feature example to create a list of   {@link AssociatedPair} for use in computing thefundamental matrix.
 */
public static List<AssociatedPair> computeMatches(BufferedImage left,BufferedImage right){
  DetectDescribePoint detDesc=FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,ImageType.single(ImageFloat32.class));
  ScoreAssociation<SurfFeature> scorer=FactoryAssociation.scoreEuclidean(SurfFeature.class,true);
  AssociateDescription<SurfFeature> associate=FactoryAssociation.greedy(scorer,1,true);
  ExampleAssociatePoints<ImageFloat32,SurfFeature> findMatches=new ExampleAssociatePoints<ImageFloat32,SurfFeature>(detDesc,associate,ImageFloat32.class);
  findMatches.associate(left,right);
  List<AssociatedPair> matches=new ArrayList<AssociatedPair>();
  FastQueue<AssociatedIndex> matchIndexes=associate.getMatches();
  for (int i=0; i < matchIndexes.size; i++) {
    AssociatedIndex a=matchIndexes.get(i);
    AssociatedPair p=new AssociatedPair(findMatches.pointsA.get(a.src),findMatches.pointsB.get(a.dst));
    matches.add(p);
  }
  return matches;
}

Fixed version (ground truth):
/** 
 * Use the associate point feature example to create a list of   {@link AssociatedPair} for use in computing thefundamental matrix.
 */
public static List<AssociatedPair> computeMatches(BufferedImage left,BufferedImage right){
  DetectDescribePoint detDesc=FactoryDetectDescribe.surfStable(new ConfigFastHessian(1,2,200,1,9,4,4),null,null,ImageFloat32.class);
  ScoreAssociation<SurfFeature> scorer=FactoryAssociation.scoreEuclidean(SurfFeature.class,true);
  AssociateDescription<SurfFeature> associate=FactoryAssociation.greedy(scorer,1,true);
  ExampleAssociatePoints<ImageFloat32,SurfFeature> findMatches=new ExampleAssociatePoints<ImageFloat32,SurfFeature>(detDesc,associate,ImageFloat32.class);
  findMatches.associate(left,right);
  List<AssociatedPair> matches=new ArrayList<AssociatedPair>();
  FastQueue<AssociatedIndex> matchIndexes=associate.getMatches();
  for (int i=0; i < matchIndexes.size; i++) {
    AssociatedIndex a=matchIndexes.get(i);
    AssociatedPair p=new AssociatedPair(findMatches.pointsA.get(a.src),findMatches.pointsB.get(a.dst));
    matches.add(p);
  }
  return matches;
}
Program: 150986
Project: 150986
Buggy source:
/** 
 * Creates a non-linear optimizer for refining estimates of homography matrices.
 * @param tol Tolerance for convergence.  Try 1e-8
 * @param maxIterations Maximum number of iterations it will perform.  Try 100 or more.
 * @return Homography refinement
 */
public static RefineEpipolar refineHomography(double tol,int maxIterations,EpipolarError type){
  ModelObservationResidualN residuals;
switch (type) {
case SIMPLE:
    residuals=new HomographyResidualSampson();
  break;
case SAMPSON:
residuals=new HomographyResidualTransfer();
break;
default :
throw new IllegalArgumentException("String_Node_Str" + type);
}
return new LeastSquaresHomography(tol,maxIterations,residuals);
}

Fixed version (ground truth):
/** 
 * Creates a non-linear optimizer for refining estimates of homography matrices.
 * @see HomographyResidualSampson
 * @see HomographyResidualTransfer
 * @param tol Tolerance for convergence.  Try 1e-8
 * @param maxIterations Maximum number of iterations it will perform.  Try 100 or more.
 * @return Homography refinement
 */
public static RefineEpipolar refineHomography(double tol,int maxIterations,EpipolarError type){
  ModelObservationResidualN residuals;
switch (type) {
case SIMPLE:
    residuals=new HomographyResidualSampson();
  break;
case SAMPSON:
residuals=new HomographyResidualTransfer();
break;
default :
throw new IllegalArgumentException("String_Node_Str" + type);
}
return new LeastSquaresHomography(tol,maxIterations,residuals);
}
Program: 150987
Project: 150987
Buggy source:
/** 
 * Returns an algorithm for estimating a homography matrix given a set of  {@link AssociatedPair}.
 * @param normalize If input is in pixel coordinates set to true.  False if in normalized image coordinates.
 * @return Homography estimator.
 */
public static Estimate1ofEpipolar computeHomography(boolean normalize){
  HomographyLinear4 alg=new HomographyLinear4(normalize);
  return new WrapHomographyLinear(alg);
}

Fixed version (ground truth):
/** 
 * Returns an algorithm for estimating a homography matrix given a set of  {@link AssociatedPair}.
 * @see HomographyLinear4
 * @param normalize If input is in pixel coordinates set to true.  False if in normalized image coordinates.
 * @return Homography estimator.
 */
public static Estimate1ofEpipolar computeHomography(boolean normalize){
  HomographyLinear4 alg=new HomographyLinear4(normalize);
  return new WrapHomographyLinear(alg);
}
Program: 150988
Project: 150988
Buggy source:
/** 
 * Computes the value of the specified fern at the specified location in the image.
 */
protected int computeFernValue(float c_x,float c_y,float rectWidth,float rectHeight,TldFernDescription fern){
  int desc=0;
  for (int i=0; i < fern.pairs.length; i++) {
    Point2D_F32 p_a=fern.pairs[i].a;
    Point2D_F32 p_b=fern.pairs[i].b;
    float valA=interpolate.get_fast(c_x + p_a.x * rectWidth,c_y + p_a.y * rectHeight);
    float valB=interpolate.get_fast(c_x + p_b.x * rectWidth,c_y + p_b.y * rectHeight);
    desc*=2;
    if (valA < valB) {
      desc+=1;
    }
  }
  return desc;
}

Fixed version (ground truth):
/** 
 * Computes the value of the specified fern at the specified location in the image.
 */
protected int computeFernValue(float c_x,float c_y,float rectWidth,float rectHeight,TldFernDescription fern){
  rectWidth-=1;
  rectHeight-=1;
  int desc=0;
  for (int i=0; i < fern.pairs.length; i++) {
    Point2D_F32 p_a=fern.pairs[i].a;
    Point2D_F32 p_b=fern.pairs[i].b;
    float valA=interpolate.get_fast(c_x + p_a.x * rectWidth,c_y + p_a.y * rectHeight);
    float valB=interpolate.get_fast(c_x + p_b.x * rectWidth,c_y + p_b.y * rectHeight);
    desc*=2;
    if (valA < valB) {
      desc+=1;
    }
  }
  return desc;
}
Program: 150989
Project: 150989
Buggy source:
/** 
 * Computes the value of a fern after adding noise to the image being sampled.
 */
protected int computeFernValueRand(float c_x,float c_y,float rectWidth,float rectHeight,TldFernDescription fern){
  int desc=0;
  for (int i=0; i < fern.pairs.length; i++) {
    Point2D_F32 p_a=fern.pairs[i].a;
    Point2D_F32 p_b=fern.pairs[i].b;
    float valA=interpolate.get_fast(c_x + p_a.x * rectWidth,c_y + p_a.y * rectHeight);
    float valB=interpolate.get_fast(c_x + p_b.x * rectWidth,c_y + p_b.y * rectHeight);
    valA+=rand.nextGaussian() * fernLearnNoise;
    valB+=rand.nextGaussian() * fernLearnNoise;
    desc*=2;
    if (valA < valB) {
      desc+=1;
    }
  }
  return desc;
}

Fixed version (ground truth):
/** 
 * Computes the value of a fern after adding noise to the image being sampled.
 */
protected int computeFernValueRand(float c_x,float c_y,float rectWidth,float rectHeight,TldFernDescription fern){
  rectWidth-=1;
  rectHeight-=1;
  int desc=0;
  for (int i=0; i < fern.pairs.length; i++) {
    Point2D_F32 p_a=fern.pairs[i].a;
    Point2D_F32 p_b=fern.pairs[i].b;
    float valA=interpolate.get_fast(c_x + p_a.x * rectWidth,c_y + p_a.y * rectHeight);
    float valB=interpolate.get_fast(c_x + p_b.x * rectWidth,c_y + p_b.y * rectHeight);
    valA+=rand.nextGaussian() * fernLearnNoise;
    valB+=rand.nextGaussian() * fernLearnNoise;
    desc*=2;
    if (valA < valB) {
      desc+=1;
    }
  }
  return desc;
}
Program: 150990
Project: 150990
Buggy source:
/** 
 * Call for the first image being tracked
 * @param image Most recent video image.
 */
public void initialize(PyramidDiscrete<Image> image){
  if (previousDerivX == null || previousDerivX.length != image.getNumLayers()) {
    declareDataStructures(image);
  }
  for (int i=0; i < image.getNumLayers(); i++) {
    gradient.process(image.getLayer(i),previousDerivX[i],previousDerivY[i]);
  }
  previousImage.setTo(image);
}

Fixed version (ground truth):
/** 
 * Call for the first image being tracked
 * @param image Most recent video image.
 */
public void initialize(PyramidDiscrete<Image> image){
  if (previousDerivX == null || previousDerivX.length != image.getNumLayers() || previousImage.getInputWidth() != image.getInputWidth() || previousImage.getInputHeight() != image.getInputHeight()) {
    declareDataStructures(image);
  }
  for (int i=0; i < image.getNumLayers(); i++) {
    gradient.process(image.getLayer(i),previousDerivX[i],previousDerivY[i]);
  }
  previousImage.setTo(image);
}
Program: 150991
Project: 150991
Buggy source:
/** 
 * Starts tracking the rectangular region.
 * @param image First image in the sequence.
 * @param x0 Top-left corner of rectangle. x-axis
 * @param y0 Top-left corner of rectangle. y-axis
 * @param x1 Bottom-right corner of rectangle. x-axis
 * @param y1 Bottom-right corner of rectangle. y-axis
 */
public void initialize(T image,int x0,int y0,int x1,int y1){
  if (imagePyramid == null) {
    int minSize=(config.trackerFeatureRadius * 2 + 1) * 5;
    int scales[]=selectPyramidScale(image.width,image.height,minSize);
    imagePyramid=FactoryPyramid.discreteGaussian(scales,-1,1,true,(Class<T>)image.getClass());
  }
  imagePyramid.process(image);
  reacquiring=false;
  targetRegion.set(x0,y0,x1,y1);
  createCascadeRegion(image.width,image.height);
  template.reset();
  fern.reset();
  tracking.initialize(imagePyramid);
  variance.setImage(image);
  template.setImage(image);
  fern.setImage(image);
  adjustRegion.init(image.width,image.height);
  learning.initialLearning(targetRegion,cascadeRegions);
  strongMatch=true;
  previousTrackArea=targetRegion.area();
}

Fixed version (ground truth):
/** 
 * Starts tracking the rectangular region.
 * @param image First image in the sequence.
 * @param x0 Top-left corner of rectangle. x-axis
 * @param y0 Top-left corner of rectangle. y-axis
 * @param x1 Bottom-right corner of rectangle. x-axis
 * @param y1 Bottom-right corner of rectangle. y-axis
 */
public void initialize(T image,int x0,int y0,int x1,int y1){
  if (imagePyramid == null || imagePyramid.getInputWidth() != image.width || imagePyramid.getInputHeight() != image.height) {
    int minSize=(config.trackerFeatureRadius * 2 + 1) * 5;
    int scales[]=selectPyramidScale(image.width,image.height,minSize);
    imagePyramid=FactoryPyramid.discreteGaussian(scales,-1,1,true,(Class<T>)image.getClass());
  }
  imagePyramid.process(image);
  reacquiring=false;
  targetRegion.set(x0,y0,x1,y1);
  createCascadeRegion(image.width,image.height);
  template.reset();
  fern.reset();
  tracking.initialize(imagePyramid);
  variance.setImage(image);
  template.setImage(image);
  fern.setImage(image);
  adjustRegion.init(image.width,image.height);
  learning.initialLearning(targetRegion,cascadeRegions);
  strongMatch=true;
  previousTrackArea=targetRegion.area();
}
Program: 150992
Project: 150992
Buggy source:
/** 
 * Returns true if the features is entirely outside of the image.
 */
public boolean isFullyOutside(float x,float y){
  if (x < outsideLeft || x >= outsideRight)   return true;
  if (y < outsideTop || y >= outsideBottom)   return true;
  return false;
}

Fixed version (ground truth):
/** 
 * Returns true if the features is entirely outside of the image.  A region is entirely outside if not an entire pixel is contained inside the image.  So if only  0.999 of a pixel is inside then the whole region is considered to be outside.  Can't interpolate nothing...
 */
public boolean isFullyOutside(float x,float y){
  if (x < outsideLeft || x > outsideRight)   return true;
  if (y < outsideTop || y > outsideBottom)   return true;
  return false;
}
Program: 150993
Project: 150993
Buggy source:
private void computeE(KltFeature feature,float x,float y){
  interpInput.region(x - feature.radius,y - feature.radius,descFeature);
  Ex=0;
  Ey=0;
  for (int i=0; i < lengthFeature; i++) {
    float d=feature.desc.data[i] - descFeature.data[i];
    Ex+=d * feature.derivX.data[i];
    Ey+=d * feature.derivY.data[i];
  }
}

Fixed version (ground truth):
protected void computeE(KltFeature feature,float x,float y){
  interpInput.region(x - feature.radius,y - feature.radius,descFeature);
  Ex=0;
  Ey=0;
  for (int i=0; i < lengthFeature; i++) {
    float d=feature.desc.data[i] - descFeature.data[i];
    Ex+=d * feature.derivX.data[i];
    Ey+=d * feature.derivY.data[i];
  }
}
Program: 150994
Project: 150994
Buggy source:
/** 
 * Sets the features description using the current image and the location of the feature stored in the feature. If the feature is an illegal location and cannot be set then false is returned.
 * @param feature Feature description which is to be set.  Location must be specified.
 * @return true if the feature's description was modified.
 */
@SuppressWarnings({"String_Node_Str"}) public boolean setDescription(KltFeature feature){
  if (derivX == null || derivY == null)   throw new IllegalArgumentException("String_Node_Str");
  setAllowedBounds(feature);
  if (!isFullyInside(feature.x,feature.y)) {
    if (isFullyOutside(feature.x,feature.y))     return false;
 else     return internalSetDescriptionBorder(feature);
  }
  return internalSetDescription(feature);
}

Fixed version (ground truth):
/** 
 * Sets the features description using the current image and the location of the feature stored in the feature. If the feature is an illegal location and cannot be set then false is returned.
 * @param feature Feature description which is to be set.  Location must be specified.
 * @return true if the feature's description was modified.
 */
@SuppressWarnings({"String_Node_Str"}) public boolean setDescription(KltFeature feature){
  setAllowedBounds(feature);
  if (!isFullyInside(feature.x,feature.y)) {
    if (isFullyOutside(feature.x,feature.y))     return false;
 else     return internalSetDescriptionBorder(feature);
  }
  return internalSetDescription(feature);
}
Program: 150995
Project: 150995
Buggy source:
/** 
 * When part of the region is outside the image G and E need to be recomputed
 */
private int computeGandE_border(KltFeature feature,float cx,float cy){
  int total=0;
  Gxx=0;
  Gyy=0;
  Gxy=0;
  Ex=0;
  Ey=0;
  int i=0;
  for (int y=0; y < widthFeature; y++) {
    float pixelY=cy - feature.radius + y;
    for (int x=0; x < widthFeature; x++, i++) {
      if (Float.isNaN(feature.desc.data[i]))       continue;
      float pixelX=cx - feature.radius + x;
      float dX, dY, value;
      if (interpPixelDX.isInFastBounds(pixelX,pixelY)) {
        value=interpPixelI.get_fast(pixelX,pixelY);
        dX=interpPixelDX.get_fast(pixelX,pixelY);
        dY=interpPixelDY.get_fast(pixelX,pixelY);
      }
 else       if (image.isInBounds((int)pixelX,(int)pixelY)) {
        value=interpPixelI.get(pixelX,pixelY);
        dX=interpPixelDX.get(pixelX,pixelY);
        dY=interpPixelDY.get(pixelX,pixelY);
      }
 else {
        descFeature.data[i]=Float.NaN;
        continue;
      }
      descFeature.data[i]=value;
      total++;
      float d=feature.desc.data[i] - value;
      Ex+=d * feature.derivX.data[i];
      Ey+=d * feature.derivY.data[i];
      Gxx+=dX * dX;
      Gyy+=dY * dY;
      Gxy+=dX * dY;
    }
  }
  return total;
}

Fixed version (ground truth):
/** 
 * When part of the region is outside the image G and E need to be recomputed
 */
protected int computeGandE_border(KltFeature feature,float cx,float cy){
  int total=0;
  Gxx=0;
  Gyy=0;
  Gxy=0;
  Ex=0;
  Ey=0;
  int i=0;
  for (int y=0; y < widthFeature; y++) {
    float pixelY=cy - feature.radius + y;
    for (int x=0; x < widthFeature; x++, i++) {
      if (Float.isNaN(feature.desc.data[i]))       continue;
      float pixelX=cx - feature.radius + x;
      float dX, dY, value;
      if (interpPixelI.isInFastBounds(pixelX,pixelY)) {
        value=interpPixelI.get_fast(pixelX,pixelY);
      }
 else       if (image.isInBounds((int)pixelX,(int)pixelY)) {
        value=interpPixelI.get(pixelX,pixelY);
      }
 else {
        descFeature.data[i]=Float.NaN;
        continue;
      }
      descFeature.data[i]=value;
      total++;
      dX=feature.derivX.data[i];
      dY=feature.derivY.data[i];
      float d=feature.desc.data[i] - value;
      Ex+=d * dX;
      Ey+=d * dY;
      Gxx+=dX * dX;
      Gyy+=dY * dY;
      Gxy+=dX * dY;
    }
  }
  return total;
}
Program: 150996
Project: 150996
Buggy source:
private void setAllowedBounds(KltFeature feature){
  allowedLeft=feature.radius + config.forbiddenBorder;
  allowedTop=feature.radius + config.forbiddenBorder;
  allowedRight=image.width - (feature.radius + config.forbiddenBorder);
  allowedBottom=image.height - (feature.radius + config.forbiddenBorder);
  outsideLeft=-feature.radius + config.forbiddenBorder;
  outsideTop=-feature.radius + config.forbiddenBorder;
  outsideRight=image.width + (feature.radius - config.forbiddenBorder);
  outsideBottom=image.height + (feature.radius - config.forbiddenBorder);
}

Fixed version (ground truth):
/** 
 * Precompute image bounds that the feature is allowed inside of
 */
protected void setAllowedBounds(KltFeature feature){
  widthFeature=feature.radius * 2 + 1;
  lengthFeature=widthFeature * widthFeature;
  allowedLeft=feature.radius;
  allowedTop=feature.radius;
  allowedRight=image.width - feature.radius - 1;
  allowedBottom=image.height - feature.radius - 1;
  outsideLeft=-feature.radius;
  outsideTop=-feature.radius;
  outsideRight=image.width + feature.radius - 1;
  outsideBottom=image.height + feature.radius - 1;
}
Program: 150997
Project: 150997
Buggy source:
/** 
 * Returns true if the features is entirely enclosed inside of the image.
 */
public boolean isFullyInside(float x,float y){
  if (x < allowedLeft || x >= allowedRight)   return false;
  if (y < allowedTop || y >= allowedBottom)   return false;
  return true;
}

Fixed version (ground truth):
/** 
 * Returns true if the features is entirely enclosed inside of the image.
 */
public boolean isFullyInside(float x,float y){
  if (x < allowedLeft || x > allowedRight)   return false;
  if (y < allowedTop || y > allowedBottom)   return false;
  return true;
}
Program: 150998
Project: 150998
Buggy source:
/** 
 * Computes the descriptor for border features.  All it needs to do is save the pixel value, but derivative information is also computed so that it can reject bad features immediately.
 */
private boolean internalSetDescriptionBorder(KltFeature feature){
  int total=0;
  Gxx=Gyy=Gxy=0;
  int i=0;
  for (int y=0; y < widthFeature; y++) {
    float pixelY=feature.y - feature.radius + y;
    for (int x=0; x < widthFeature; x++, i++) {
      float pixelX=feature.x - feature.radius + x;
      float dX, dY, value;
      if (interpPixelDX.isInFastBounds(pixelX,pixelY)) {
        value=interpPixelI.get_fast(pixelX,pixelY);
        dX=interpPixelDX.get_fast(pixelX,pixelY);
        dY=interpPixelDY.get_fast(pixelX,pixelY);
      }
 else       if (image.isInBounds((int)pixelX,(int)pixelY)) {
        value=interpPixelI.get(pixelX,pixelY);
        dX=interpPixelDX.get(pixelX,pixelY);
        dY=interpPixelDY.get(pixelX,pixelY);
      }
 else {
        feature.desc.data[i]=Float.NaN;
        continue;
      }
      total++;
      feature.desc.data[i]=value;
      Gxx+=dX * dX;
      Gyy+=dY * dY;
      Gxy+=dX * dY;
    }
  }
  feature.Gxx=Gxx;
  feature.Gyy=Gyy;
  feature.Gxy=Gxy;
  float det=Gxx * Gyy - Gxy * Gxy;
  return (det >= config.minDeterminant * total);
}

Fixed version (ground truth):
/** 
 * Computes the descriptor for border features.  All it needs to do is save the pixel value, but derivative information is also computed so that it can reject bad features immediately.
 */
private boolean internalSetDescriptionBorder(KltFeature feature){
  int total=0;
  Gxx=Gyy=Gxy=0;
  int i=0;
  for (int y=0; y < widthFeature; y++) {
    float pixelY=feature.y - feature.radius + y;
    for (int x=0; x < widthFeature; x++, i++) {
      float pixelX=feature.x - feature.radius + x;
      float dX, dY, value;
      if (interpPixelI.isInFastBounds(pixelX,pixelY)) {
        value=interpPixelI.get_fast(pixelX,pixelY);
        dX=interpPixelDX.get_fast(pixelX,pixelY);
        dY=interpPixelDY.get_fast(pixelX,pixelY);
      }
 else       if (image.isInBounds((int)pixelX,(int)pixelY)) {
        value=interpPixelI.get(pixelX,pixelY);
        dX=interpPixelDX.get(pixelX,pixelY);
        dY=interpPixelDY.get(pixelX,pixelY);
      }
 else {
        feature.desc.data[i]=Float.NaN;
        continue;
      }
      total++;
      feature.desc.data[i]=value;
      feature.derivX.data[i]=dX;
      feature.derivY.data[i]=dY;
      Gxx+=dX * dX;
      Gyy+=dY * dY;
      Gxy+=dX * dY;
    }
  }
  feature.Gxx=Gxx;
  feature.Gyy=Gyy;
  feature.Gxy=Gxy;
  float det=Gxx * Gyy - Gxy * Gxy;
  return (det >= config.minDeterminant * total);
}
Program: 151000
Project: 151000
Buggy source:
/** 
 * Sets the current image it should be tracking with.
 * @param image  Original input image.
 * @param derivX Image derivative along the x-axis
 * @param derivY Image derivative along the y-axis
 */
public void setImage(InputImage image,DerivativeImage derivX,DerivativeImage derivY){
  if (derivX != null && derivY != null)   InputSanityCheck.checkSameShape(image,derivX,derivY);
  this.image=image;
  interpInput.setImage(image);
  this.derivX=derivX;
  this.derivY=derivY;
  interpPixelI.setImage(image);
  interpPixelDX.setImage(derivX);
  interpPixelDY.setImage(derivY);
}

Fixed version (ground truth):
/** 
 * Sets the current image it should be tracking with.
 * @param image  Original input image.
 * @param derivX Image derivative along the x-axis
 * @param derivY Image derivative along the y-axis
 */
public void setImage(InputImage image,DerivativeImage derivX,DerivativeImage derivY){
  InputSanityCheck.checkSameShape(image,derivX,derivY);
  this.image=image;
  interpInput.setImage(image);
  this.derivX=derivX;
  this.derivY=derivY;
  interpPixelI.setImage(image);
  interpPixelDX.setImage(derivX);
  interpPixelDY.setImage(derivY);
}
Program: 151001
Project: 151001
Buggy source:
/** 
 * Computes a transform which is used to rescale an image.  The scale is computed directly from the size of the two input images and independently scales the x and y axises.
 */
public static PixelTransformAffine_F32 transformScale(ImageBase from,ImageBase to){
  float scaleX=(float)to.width / (float)from.width;
  float scaleY=(float)to.height / (float)from.height;
  Affine2D_F32 affine=new Affine2D_F32(scaleX,0,0,scaleY,0,0);
  PixelTransformAffine_F32 distort=new PixelTransformAffine_F32();
  distort.set(affine);
  return distort;
}

Fixed version (ground truth):
/** 
 * Computes a transform which is used to rescale an image.  The scale is computed directly from the size of the two input images and independently scales the x and y axises.
 */
public static PixelTransformAffine_F32 transformScale(ImageBase from,ImageBase to){
  float scaleX=(float)(to.width - 1) / (float)(from.width - 1);
  float scaleY=(float)(to.height - 1) / (float)(from.height - 1);
  Affine2D_F32 affine=new Affine2D_F32(scaleX,0,0,scaleY,0,0);
  PixelTransformAffine_F32 distort=new PixelTransformAffine_F32();
  distort.set(affine);
  return distort;
}
Program: 151002
Project: 151002
Buggy source:
@Test public void distortScale(){
  ImageFloat32 a=new ImageFloat32(25,30);
  ImageFloat32 b=new ImageFloat32(15,25);
  PixelTransform_F32 tran=DistortSupport.transformScale(a,b);
  tran.compute(5,6);
  assertEquals(5.0 * 15.0 / 25.0,tran.distX,1e-4);
  assertEquals(6.0 * 25.0 / 30.0,tran.distY,1e-4);
}

Fixed version (ground truth):
@Test public void distortScale(){
  ImageFloat32 a=new ImageFloat32(25,30);
  ImageFloat32 b=new ImageFloat32(15,25);
  PixelTransform_F32 tran=DistortSupport.transformScale(a,b);
  tran.compute(0,0);
  assertEquals(0,tran.distX,1e-8);
  assertEquals(0,tran.distY,1e-8);
  tran.compute(24,29);
  assertEquals(14,tran.distX,1e-8);
  assertEquals(24,tran.distY,1e-8);
  tran.compute(5,6);
  assertEquals(5.0 * 14.0 / 24.0,tran.distX,1e-4);
  assertEquals(6.0 * 24.0 / 29.0,tran.distY,1e-4);
}
Program: 151003
Project: 151003
Buggy source:
/** 
 * Returns true if the features is entirely outside of the image.
 */
public boolean isFullyOutside(float x,float y){
  if (x < outsideLeft || x >= outsideRight)   return true;
  if (y < outsideTop || y >= outsideBottom)   return true;
  return false;
}

Fixed version (ground truth):
/** 
 * Returns true if the features is entirely outside of the image.  A region is entirely outside if not an entire pixel is contained inside the image.  So if only  0.999 of a pixel is inside then the whole region is considered to be outside.  Can't interpolate nothing...
 */
public boolean isFullyOutside(float x,float y){
  if (x < outsideLeft || x > outsideRight)   return true;
  if (y < outsideTop || y > outsideBottom)   return true;
  return false;
}
Program: 151004
Project: 151004
Buggy source:
private void computeE(KltFeature feature,float x,float y){
  interpInput.region(x - feature.radius,y - feature.radius,descFeature);
  Ex=0;
  Ey=0;
  for (int i=0; i < lengthFeature; i++) {
    float d=feature.desc.data[i] - descFeature.data[i];
    Ex+=d * feature.derivX.data[i];
    Ey+=d * feature.derivY.data[i];
  }
}

Fixed version (ground truth):
protected void computeE(KltFeature feature,float x,float y){
  interpInput.region(x - feature.radius,y - feature.radius,descFeature);
  Ex=0;
  Ey=0;
  for (int i=0; i < lengthFeature; i++) {
    float d=feature.desc.data[i] - descFeature.data[i];
    Ex+=d * feature.derivX.data[i];
    Ey+=d * feature.derivY.data[i];
  }
}
Program: 151005
Project: 151005
Buggy source:
/** 
 * Sets the features description using the current image and the location of the feature stored in the feature. If the feature is an illegal location and cannot be set then false is returned.
 * @param feature Feature description which is to be set.  Location must be specified.
 * @return true if the feature's description was modified.
 */
@SuppressWarnings({"String_Node_Str"}) public boolean setDescription(KltFeature feature){
  if (derivX == null || derivY == null)   throw new IllegalArgumentException("String_Node_Str");
  setAllowedBounds(feature);
  if (!isFullyInside(feature.x,feature.y)) {
    if (isFullyOutside(feature.x,feature.y))     return false;
 else     return internalSetDescriptionBorder(feature);
  }
  return internalSetDescription(feature);
}

Fixed version (ground truth):
/** 
 * Sets the features description using the current image and the location of the feature stored in the feature. If the feature is an illegal location and cannot be set then false is returned.
 * @param feature Feature description which is to be set.  Location must be specified.
 * @return true if the feature's description was modified.
 */
@SuppressWarnings({"String_Node_Str"}) public boolean setDescription(KltFeature feature){
  setAllowedBounds(feature);
  if (!isFullyInside(feature.x,feature.y)) {
    if (isFullyOutside(feature.x,feature.y))     return false;
 else     return internalSetDescriptionBorder(feature);
  }
  return internalSetDescription(feature);
}
Program: 151006
Project: 151006
Buggy source:
/** 
 * When part of the region is outside the image G and E need to be recomputed
 */
private int computeGandE_border(KltFeature feature,float cx,float cy){
  int total=0;
  Gxx=0;
  Gyy=0;
  Gxy=0;
  Ex=0;
  Ey=0;
  int i=0;
  for (int y=0; y < widthFeature; y++) {
    float pixelY=cy - feature.radius + y;
    for (int x=0; x < widthFeature; x++, i++) {
      if (Float.isNaN(feature.desc.data[i]))       continue;
      float pixelX=cx - feature.radius + x;
      float dX, dY, value;
      if (interpPixelDX.isInFastBounds(pixelX,pixelY)) {
        value=interpPixelI.get_fast(pixelX,pixelY);
        dX=interpPixelDX.get_fast(pixelX,pixelY);
        dY=interpPixelDY.get_fast(pixelX,pixelY);
      }
 else       if (image.isInBounds((int)pixelX,(int)pixelY)) {
        value=interpPixelI.get(pixelX,pixelY);
        dX=interpPixelDX.get(pixelX,pixelY);
        dY=interpPixelDY.get(pixelX,pixelY);
      }
 else {
        descFeature.data[i]=Float.NaN;
        continue;
      }
      descFeature.data[i]=value;
      total++;
      float d=feature.desc.data[i] - value;
      Ex+=d * feature.derivX.data[i];
      Ey+=d * feature.derivY.data[i];
      Gxx+=dX * dX;
      Gyy+=dY * dY;
      Gxy+=dX * dY;
    }
  }
  return total;
}

Fixed version (ground truth):
/** 
 * When part of the region is outside the image G and E need to be recomputed
 */
protected int computeGandE_border(KltFeature feature,float cx,float cy){
  int total=0;
  Gxx=0;
  Gyy=0;
  Gxy=0;
  Ex=0;
  Ey=0;
  int i=0;
  for (int y=0; y < widthFeature; y++) {
    float pixelY=cy - feature.radius + y;
    for (int x=0; x < widthFeature; x++, i++) {
      if (Float.isNaN(feature.desc.data[i]))       continue;
      float pixelX=cx - feature.radius + x;
      float dX, dY, value;
      if (interpPixelI.isInFastBounds(pixelX,pixelY)) {
        value=interpPixelI.get_fast(pixelX,pixelY);
      }
 else       if (image.isInBounds((int)pixelX,(int)pixelY)) {
        value=interpPixelI.get(pixelX,pixelY);
      }
 else {
        descFeature.data[i]=Float.NaN;
        continue;
      }
      descFeature.data[i]=value;
      total++;
      dX=feature.derivX.data[i];
      dY=feature.derivY.data[i];
      float d=feature.desc.data[i] - value;
      Ex+=d * dX;
      Ey+=d * dY;
      Gxx+=dX * dX;
      Gyy+=dY * dY;
      Gxy+=dX * dY;
    }
  }
  return total;
}