nus-yam/ex-repair huggingface dataset:
Program: 22677
Project: 22677
Buggy source:
public static void writeLine(DataOutputStream out,String line) throws IOException {
  for (int i=0; i < line.length(); i++) {
    byte charByte=(byte)line.charAt(i);
    out.writeByte(charByte);
  }
}

Fixed version (ground truth):
public static void writeLine(DataOutput out,String line) throws IOException {
  for (int i=0; i < line.length(); i++) {
    byte charByte=(byte)line.charAt(i);
    out.writeByte(charByte);
  }
}
Program: 22678
Project: 22678
Buggy source:
public static String readLine(DataInputStream in,char character) throws IOException {
  StringBuilder out=new StringBuilder();
  while (true) {
    char c=(char)in.readByte();
    if (c == character) {
      break;
    }
    out.append(c);
  }
  return out.toString();
}

Fixed version (ground truth):
public static String readLine(DataInput in,char character) throws IOException {
  StringBuilder out=new StringBuilder();
  while (true) {
    char c=(char)in.readByte();
    if (c == character) {
      break;
    }
    out.append(c);
  }
  return out.toString();
}
Program: 22679
Project: 22679
Buggy source:
public CharSequence subSequence(int start,int end){
  if (start < 0 || end >= (this.length())) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start];
  System.arraycopy(data,start,newdata,0,end - start);
  return new CompactString(newdata);
}

Fixed version (ground truth):
public CharSequence subSequence(int start,int end){
  if (start < 0 || end >= (this.length())) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start + 1];
  System.arraycopy(data,start,newdata,0,end - start + 1);
  return new CompactString(newdata);
}
Program: 22680
Project: 22680
Buggy source:
@Override public CharSequence subSequence(int start,int end){
  if (start < 0 || end >= (this.length())) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start];
  System.arraycopy(buffer,start,newdata,0,end - start);
  return new ReplazableString(newdata);
}

Fixed version (ground truth):
@Override public CharSequence subSequence(int start,int end){
  if (start < 0 || end >= (this.length())) {
    throw new IllegalArgumentException("String_Node_Str" + start + "String_Node_Str"+ end+ "String_Node_Str"+ length());
  }
  byte[] newdata=new byte[end - start + 1];
  System.arraycopy(buffer,start,newdata,0,end - start + 1);
  return new ReplazableString(newdata);
}
Program: 22681
Project: 22681
Buggy source:
public void append(byte[] data,int offset,int len){
  this.replace(used,data,offset,len);
}

Fixed version (ground truth):
public void append(CharSequence other){
  ensureSize(this.used + other.length());
  for (int i=0; i < other.length(); i++) {
    buffer[this.used + i]=(byte)other.charAt(i);
  }
  used+=other.length();
}
Program: 22683
Project: 22683
Buggy source:
/** 
 * Get Laplacian features (to be submitted in an ExecutorService)
 * @param originalImage input image
 * @param sigma isotropic smoothing scale	
 * @return filter Laplacian filter image
 */
public Callable<ArrayList<ImagePlus>> getLaplacian(final ImagePlus originalImage,final double sigma){
  if (Thread.currentThread().isInterrupted())   return null;
  return new Callable<ArrayList<ImagePlus>>(){
    public ArrayList<ImagePlus> call(){
      ImagePlus[] channels=extractChannels(originalImage);
      ArrayList<ImagePlus>[] results=new ArrayList[channels.length];
      for (int ch=0; ch < channels.length; ch++) {
        results[ch]=new ArrayList<ImagePlus>();
        final ImagePlus channel=channels[ch].duplicate();
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(channels[ch].getImageStackSize()));
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(1),1);
        Calibration c=channel.getCalibration();
        c.pixelWidth=scaleFactor[0];
        c.pixelHeight=scaleFactor[1];
        c.pixelDepth=scaleFactor[2];
        final ImagePlus ip=ImageScience.computeLaplacianImage(sigma,channel);
        ip.setTitle(availableFeatures[LAPLACIAN] + "String_Node_Str" + sigma);
        ip.getImageStack().deleteLastSlice();
        ip.getImageStack().deleteSlice(1);
        results[ch].add(ip);
      }
      return mergeResultChannels(results);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Get Laplacian features (to be submitted in an ExecutorService)
 * @param originalImage input image
 * @param sigma isotropic smoothing scale	
 * @return filter Laplacian filter image
 */
public Callable<ArrayList<ImagePlus>> getLaplacian(final ImagePlus originalImage,final double sigma){
  if (Thread.currentThread().isInterrupted())   return null;
  return new Callable<ArrayList<ImagePlus>>(){
    public ArrayList<ImagePlus> call(){
      ImagePlus[] channels=extractChannels(originalImage);
      ArrayList<ImagePlus>[] results=new ArrayList[channels.length];
      for (int ch=0; ch < channels.length; ch++) {
        results[ch]=new ArrayList<ImagePlus>();
        final ImagePlus channel=channels[ch].duplicate();
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(channels[ch].getImageStackSize()));
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(1),1);
        Calibration c=channel.getCalibration();
        c.pixelWidth=1.0 / scaleFactor[0];
        c.pixelHeight=1.0 / scaleFactor[1];
        c.pixelDepth=1.0 / scaleFactor[2];
        final ImagePlus ip=ImageScience.computeLaplacianImage(sigma,channel);
        ip.setTitle(availableFeatures[LAPLACIAN] + "String_Node_Str" + sigma);
        ip.getImageStack().deleteLastSlice();
        ip.getImageStack().deleteSlice(1);
        results[ch].add(ip);
      }
      return mergeResultChannels(results);
    }
  }
;
}
Program: 22687
Project: 22687
Buggy source:
/** 
 * Get Edges features (to be submitted in an ExecutorService)
 * @param originalImage input image
 * @param sigma isotropic smoothing scale	
 * @return filter Edges filter image
 */
public Callable<ArrayList<ImagePlus>> getEdges(final ImagePlus originalImage,final double sigma){
  if (Thread.currentThread().isInterrupted())   return null;
  return new Callable<ArrayList<ImagePlus>>(){
    public ArrayList<ImagePlus> call(){
      ImagePlus[] channels=extractChannels(originalImage);
      ArrayList<ImagePlus>[] results=new ArrayList[channels.length];
      for (int ch=0; ch < channels.length; ch++) {
        results[ch]=new ArrayList<ImagePlus>();
        final ImagePlus channel=channels[ch].duplicate();
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(channels[ch].getImageStackSize()));
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(1),1);
        Calibration c=channel.getCalibration();
        c.pixelWidth=scaleFactor[0];
        c.pixelHeight=scaleFactor[1];
        c.pixelDepth=scaleFactor[2];
        final ImagePlus ip=ImageScience.computeEdgesImage(sigma,channel);
        ip.setTitle(availableFeatures[EDGES] + "String_Node_Str" + sigma);
        ip.getImageStack().deleteLastSlice();
        ip.getImageStack().deleteSlice(1);
        results[ch].add(ip);
      }
      return mergeResultChannels(results);
    }
  }
;
}

Fixed version (ground truth):
/** 
 * Get Edges features (to be submitted in an ExecutorService)
 * @param originalImage input image
 * @param sigma isotropic smoothing scale	
 * @return filter Edges filter image
 */
public Callable<ArrayList<ImagePlus>> getEdges(final ImagePlus originalImage,final double sigma){
  if (Thread.currentThread().isInterrupted())   return null;
  return new Callable<ArrayList<ImagePlus>>(){
    public ArrayList<ImagePlus> call(){
      ImagePlus[] channels=extractChannels(originalImage);
      ArrayList<ImagePlus>[] results=new ArrayList[channels.length];
      for (int ch=0; ch < channels.length; ch++) {
        results[ch]=new ArrayList<ImagePlus>();
        final ImagePlus channel=channels[ch].duplicate();
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(channels[ch].getImageStackSize()));
        channel.getImageStack().addSlice("String_Node_Str",channels[ch].getImageStack().getProcessor(1),1);
        Calibration c=channel.getCalibration();
        c.pixelWidth=1.0 / scaleFactor[0];
        c.pixelHeight=1.0 / scaleFactor[1];
        c.pixelDepth=1.0 / scaleFactor[2];
        final ImagePlus ip=ImageScience.computeEdgesImage(sigma,channel);
        ip.setTitle(availableFeatures[EDGES] + "String_Node_Str" + sigma);
        ip.getImageStack().deleteLastSlice();
        ip.getImageStack().deleteSlice(1);
        results[ch].add(ip);
      }
      return mergeResultChannels(results);
    }
  }
;
}
Program: 22688
Project: 22688
Buggy source:
/** 
 * Display the current probability maps
 */
public static void getProbability(){
  final ImageWindow iw=WindowManager.getCurrentImage().getWindow();
  if (iw instanceof CustomWindow) {
    final CustomWindow win=(CustomWindow)iw;
    final WekaSegmentation wekaSegmentation=win.getWekaSegmentation();
    IJ.showStatus("String_Node_Str");
    IJ.log("String_Node_Str");
    win.setButtonsEnabled(false);
    wekaSegmentation.applyClassifier(true);
    final ImagePlus probImage=wekaSegmentation.getClassifiedImage();
    if (null != probImage) {
      probImage.setOpenAsHyperStack(true);
      probImage.show();
    }
    win.updateButtonsEnabling();
    IJ.showStatus("String_Node_Str");
    IJ.log("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Display the current probability maps
 */
public static void getProbability(){
  final ImageWindow iw=WindowManager.getCurrentImage().getWindow();
  if (iw instanceof CustomWindow) {
    final CustomWindow win=(CustomWindow)iw;
    final WekaSegmentation wekaSegmentation=win.getWekaSegmentation();
    IJ.showStatus("String_Node_Str");
    IJ.log("String_Node_Str");
    win.setButtonsEnabled(false);
    wekaSegmentation.applyClassifier(true);
    final ImagePlus probImage=wekaSegmentation.getClassifiedImage();
    if (null != probImage) {
      probImage.setDimensions(wekaSegmentation.getNumOfClasses(),win.getTrainingImage().getNSlices(),win.getTrainingImage().getNFrames());
      if (win.getTrainingImage().getNSlices() * win.getTrainingImage().getNFrames() > 1)       probImage.setOpenAsHyperStack(true);
      probImage.show();
    }
    win.updateButtonsEnabling();
    IJ.showStatus("String_Node_Str");
    IJ.log("String_Node_Str");
  }
}
Program: 22691
Project: 22691
Buggy source:
/** 
 * Parses a given list of options. <p/> <!-- options-start --> Valid options are: <p/> <pre> -I &lt;number of trees&gt; Number of trees to build.</pre> <pre> -K &lt;number of features&gt; Number of features to consider (&lt;1=int(logM+1)).</pre> <pre> -S Seed for random number generator. (default 1)</pre> <pre> -D If set, classifier is run in debug mode and may output additional info to the console</pre> <!-- options-end -->
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
  String tmpStr;
  tmpStr=Utils.getOption('I',options);
  if (tmpStr.length() != 0) {
    this.numTrees=Integer.parseInt(tmpStr);
  }
 else {
    this.numTrees=100;
  }
  tmpStr=Utils.getOption('K',options);
  if (tmpStr.length() != 0) {
    this.numFeatures=Integer.parseInt(tmpStr);
  }
 else {
    this.numFeatures=0;
  }
  tmpStr=Utils.getOption('S',options);
  if (tmpStr.length() != 0) {
    setSeed(Integer.parseInt(tmpStr));
  }
 else {
    setSeed(1);
  }
  super.setOptions(options);
  Utils.checkForRemainingOptions(options);
}

Fixed version (ground truth):
/** 
 * Parses a given list of options. <!-- options-start --> <p> Valid options are: </p> <pre> -I &lt;number of trees&gt; Number of trees to build.</pre> <pre> -K &lt;number of features&gt; Number of features to consider (&lt;1=int(logM+1)).</pre> <pre> -S Seed for random number generator. (default 1)</pre> <pre> -D If set, classifier is run in debug mode and may output additional info to the console</pre> <!-- options-end -->
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
public void setOptions(String[] options) throws Exception {
  String tmpStr;
  tmpStr=Utils.getOption('I',options);
  if (tmpStr.length() != 0) {
    this.numTrees=Integer.parseInt(tmpStr);
  }
 else {
    this.numTrees=100;
  }
  tmpStr=Utils.getOption('K',options);
  if (tmpStr.length() != 0) {
    this.numFeatures=Integer.parseInt(tmpStr);
  }
 else {
    this.numFeatures=0;
  }
  tmpStr=Utils.getOption('S',options);
  if (tmpStr.length() != 0) {
    setSeed(Integer.parseInt(tmpStr));
  }
 else {
    setSeed(1);
  }
  super.setOptions(options);
  Utils.checkForRemainingOptions(options);
}
Program: 22693
Project: 22693
Buggy source:
/** 
 * Parses a given list of options. <p/> <p/> <!-- options-start --> Valid options are: <p/> <p/> <pre> -P Size of each bag, as a percentage of the training set size. (default 100)</pre> <p/> <pre> -O Calculate the out of bag error.</pre> <p/> <pre> -S &lt;num&gt; Random number seed. (default 1)</pre> <p/> <pre> -I &lt;num&gt; Number of iterations. (default 10)</pre> <p/> <pre> -D If set, classifier is run in debug mode and may output additional info to the console</pre> <p/> <pre> -W Full name of base classifier. (default: fastRandomForest.classifiers.FastRandomTree)</pre> <p/> <!-- options-end --> <p/> Options after -- are passed to the designated classifier.<p>
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
@Override public void setOptions(String[] options) throws Exception {
  String bagSize=Utils.getOption('P',options);
  if (bagSize.length() != 0) {
    setBagSizePercent(Integer.parseInt(bagSize));
  }
 else {
    setBagSizePercent(100);
  }
  setCalcOutOfBag(Utils.getFlag('O',options));
  super.setOptions(options);
}

Fixed version (ground truth):
/** 
 * Parses a given list of options. <!-- options-start --> <p> Valid options are: </p> <pre> -P Size of each bag, as a percentage of the training set size. (default 100)</pre> <pre> -O Calculate the out of bag error.</pre> <pre> -S &lt;num&gt; Random number seed. (default 1)</pre> <pre> -I &lt;num&gt; Number of iterations. (default 10)</pre> <pre> -D If set, classifier is run in debug mode and may output additional info to the console</pre> <pre> -W Full name of base classifier. (default: fastRandomForest.classifiers.FastRandomTree)</pre> <!-- options-end --> <p> Options after -- are passed to the designated classifier. </p>
 * @param options the list of options as an array of strings
 * @throws Exception if an option is not supported
 */
@Override public void setOptions(String[] options) throws Exception {
  String bagSize=Utils.getOption('P',options);
  if (bagSize.length() != 0) {
    setBagSizePercent(Integer.parseInt(bagSize));
  }
 else {
    setBagSizePercent(100);
  }
  setCalcOutOfBag(Utils.getFlag('O',options));
  super.setOptions(options);
}
Program: 22694
Project: 22694
Buggy source:
/** 
 * Normalizes the doubles in the array using the given value. <p/> If supplied an array full of zeroes, does not modify the array.
 * @param doubles the array of double
 * @param sum     the value by which the doubles are to be normalized
 * @throws IllegalArgumentException if sum is zero or NaN
 */
private static void normalize(double[] doubles,double sum){
  if (Double.isNaN(sum)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (sum == 0) {
    return;
  }
  for (int i=0; i < doubles.length; i++) {
    doubles[i]/=sum;
  }
}

Fixed version (ground truth):
/** 
 * Normalizes the doubles in the array using the given value. <p> If supplied an array full of zeroes, does not modify the array. </p>
 * @param doubles the array of double
 * @param sum     the value by which the doubles are to be normalized
 * @throws IllegalArgumentException if sum is zero or NaN
 */
private static void normalize(double[] doubles,double sum){
  if (Double.isNaN(sum)) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (sum == 0) {
    return;
  }
  for (int i=0; i < doubles.length; i++) {
    doubles[i]/=sum;
  }
}
Program: 22695
Project: 22695
Buggy source:
/** 
 * Produces a random permutation of the values of an attribute in a dataset using Knuth shuffle. <p/> Copies back the current values of the previously scrambled attribute and uses the given permutation to scramble the values of the new attribute all by copying from the original dataset.
 * @param src      the source dataset
 * @param dst      the scrambled dataset
 * @param attIndex the attribute index
 * @param perm     the random permutation
 * @return fluent
 */
public static Instances scramble(Instances src,Instances dst,final int attIndex,int[] perm){
  for (int i=0; i < src.numInstances(); i++) {
    Instance scrambled=dst.instance(i);
    if (attIndex > 0)     scrambled.setValue(attIndex - 1,src.instance(i).value(attIndex - 1));
    scrambled.setValue(attIndex,src.instance(perm[i]).value(attIndex));
  }
  return dst;
}

Fixed version (ground truth):
/** 
 * Produces a random permutation of the values of an attribute in a dataset using Knuth shuffle. <p> Copies back the current values of the previously scrambled attribute and uses the given permutation to scramble the values of the new attribute all by copying from the original dataset. </p>
 * @param src      the source dataset
 * @param dst      the scrambled dataset
 * @param attIndex the attribute index
 * @param perm     the random permutation
 * @return fluent
 */
public static Instances scramble(Instances src,Instances dst,final int attIndex,int[] perm){
  for (int i=0; i < src.numInstances(); i++) {
    Instance scrambled=dst.instance(i);
    if (attIndex > 0)     scrambled.setValue(attIndex - 1,src.instance(i).value(attIndex - 1));
    scrambled.setValue(attIndex,src.instance(perm[i]).value(attIndex));
  }
  return dst;
}
Program: 22696
Project: 22696
Buggy source:
/** 
 * Get a specific label of the reference stack
 * @param index slice index (>=1)
 * @return label name
 */
public String getLabel(int index){
  if (referenceStackIndex == -1)   return null;
  return featureStackArray[referenceStackIndex].getSliceLabel(index);
}

Fixed version (ground truth):
/** 
 * Get a specific label of the reference stack
 * @param index slice index (&gt;=1)
 * @return label name
 */
public String getLabel(int index){
  if (referenceStackIndex == -1)   return null;
  return featureStackArray[referenceStackIndex].getSliceLabel(index);
}
Program: 22697
Project: 22697
Buggy source:
/** 
 * Get n-th stack in the array (remember n>=0)
 * @param n position of the stack to get
 * @return feature stack of the corresponding slice
 */
public FeatureStack get(int n){
  return featureStackArray[n];
}

Fixed version (ground truth):
/** 
 * Get n-th stack in the array (remember n&gt;=0)
 * @param n position of the stack to get
 * @return feature stack of the corresponding slice
 */
public FeatureStack get(int n){
  return featureStackArray[n];
}
Program: 22698
Project: 22698
Buggy source:
/** 
 * Set the current number of classes. Should not be used to create new classes. Use <link>addClass<\link> instead.
 * @param numOfClasses the new number of classes
 */
public void setNumOfClasses(int numOfClasses){
  this.numOfClasses=numOfClasses;
}

Fixed version (ground truth):
/** 
 * Set the current number of classes. Should not be used to create new classes. Use   {@link #addClass} instead.
 * @param numOfClasses the new number of classes
 */
public void setNumOfClasses(int numOfClasses){
  this.numOfClasses=numOfClasses;
}
Program: 22699
Project: 22699
Buggy source:
/** 
 * Get current feature stack
 * @param i number of feature stack slice (>=1)
 * @return feature stack of the corresponding slice
 */
public FeatureStack getFeatureStack(int i){
  return this.featureStackArray.get(i - 1);
}

Fixed version (ground truth):
/** 
 * Get current feature stack
 * @param i number of feature stack slice (&gt;=1)
 * @return feature stack of the corresponding slice
 */
public FeatureStack getFeatureStack(int i){
  return this.featureStackArray.get(i - 1);
}
Program: 22701
Project: 22701
Buggy source:
/** 
 * Extract pixel values from input image such that they have value h, hMin <= h <= hMax.
 * @param inputImage input image
 * @param hMin minimum grayscale height value
 * @param hMax maximum grayscale height value
 * @return list of input pixel values
 */
public ArrayList<PixelRecord> extractPixelValues(final ImageProcessor inputImage,final double hMin,final double hMax){
  final int size1=inputImage.getWidth();
  final int size2=inputImage.getHeight();
  final ArrayList<PixelRecord> list=new ArrayList<PixelRecord>();
  for (int x=0; x < size1; ++x)   for (int y=0; y < size2; ++y) {
    final double h=inputImage.getf(x,y);
    if (h >= hMin && h <= hMax)     list.add(new PixelRecord(x,y,h));
  }
  return list;
}

Fixed version (ground truth):
/** 
 * Extract pixel values from input image such that they have value h, hMin &lt;= h &lt;= hMax.
 * @param inputImage input image
 * @param hMin minimum grayscale height value
 * @param hMax maximum grayscale height value
 * @return list of input pixel values
 */
public ArrayList<PixelRecord> extractPixelValues(final ImageProcessor inputImage,final double hMin,final double hMax){
  final int size1=inputImage.getWidth();
  final int size2=inputImage.getHeight();
  final ArrayList<PixelRecord> list=new ArrayList<PixelRecord>();
  for (int x=0; x < size1; ++x)   for (int y=0; y < size2; ++y) {
    final double h=inputImage.getf(x,y);
    if (h >= hMin && h <= hMax)     list.add(new PixelRecord(x,y,h));
  }
  return list;
}
Program: 22703
Project: 22703
Buggy source:
/** 
 * Add training samples from a ShapeRoi
 * @param trainingData set of instances to add to
 * @param classIndex class index value
 * @param sliceNum number of 2d slice being processed
 * @param r shape roi
 * @return number of instances added
 */
private int addShapeRoiInstances(final Instances trainingData,int classIndex,int sliceNum,Roi r){
  int numInstances=0;
  final ShapeRoi shapeRoi=new ShapeRoi(r);
  final Rectangle rect=shapeRoi.getBounds();
  final int lastX=rect.x + rect.width;
  final int lastY=rect.y + rect.height;
  final FeatureStack fs=featureStackArray.get(sliceNum - 1);
  for (int x=rect.x; x < lastX; x++)   for (int y=rect.y; y < lastY; y++)   if (shapeRoi.contains(x,y)) {
    trainingData.add(fs.createInstance(x,y,classIndex));
    numInstances++;
  }
  return numInstances;
}

Fixed version (ground truth):
/** 
 * Add training samples from a ShapeRoi
 * @param trainingData set of instances to add to
 * @param classIndex class index value
 * @param sliceNum number of 2d slice being processed
 * @param r shape roi
 * @return number of instances added
 */
private int addShapeRoiInstances(final Instances trainingData,int classIndex,int sliceNum,Roi r){
  int numInstances=0;
  final ShapeRoi shapeRoi=new ShapeRoi(r);
  final Rectangle rect=shapeRoi.getBounds();
  int lastX=rect.x + rect.width;
  if (lastX >= trainingImage.getWidth())   lastX=trainingImage.getWidth() - 1;
  int lastY=rect.y + rect.height;
  if (lastY >= trainingImage.getHeight())   lastY=trainingImage.getHeight() - 1;
  int firstX=Math.max(rect.x,0);
  int firstY=Math.max(rect.y,0);
  final FeatureStack fs=featureStackArray.get(sliceNum - 1);
  for (int x=firstX; x < lastX; x++)   for (int y=firstY; y < lastY; y++)   if (shapeRoi.contains(x,y)) {
    trainingData.add(fs.createInstance(x,y,classIndex));
    numInstances++;
  }
  return numInstances;
}
Program: 22708
Project: 22708
Buggy source:
/** 
 * Get the minimum foreground-restricted metric value over a set of thresholds 
 * @param minThreshold minimum threshold value to binarize the input images
 * @param maxThreshold maximum threshold value to binarize the input images
 * @param stepThreshold threshold step value to use during binarization
 * @return minimum foreground-restricted value of the metric
 */
public double getMinimumForegroundRestrictedMetricValue(double minThreshold,double maxThreshold,double stepThreshold){
  double min=1.0;
  double bestTh=minThreshold;
  for (double th=minThreshold; th <= maxThreshold; th+=stepThreshold) {
    if (verbose)     IJ.log("String_Node_Str" + String.format("String_Node_Str",th) + "String_Node_Str");
    double error=getForegroundRestrictedMetricValue(th);
    if (min > error) {
      min=error;
      ;
      bestTh=th;
    }
    if (verbose)     IJ.log("String_Node_Str" + error);
  }
  if (verbose)   IJ.log("String_Node_Str" + min + "String_Node_Str"+ bestTh+ "String_Node_Str");
  return min;
}

Fixed version (ground truth):
/** 
 * Get the minimum foreground-restricted metric value over a set of thresholds 
 * @param minThreshold minimum threshold value to binarize the input images
 * @param maxThreshold maximum threshold value to binarize the input images
 * @param stepThreshold threshold step value to use during binarization
 * @return minimum foreground-restricted value of the metric
 */
public double getMinimumForegroundRestrictedMetricValue(double minThreshold,double maxThreshold,double stepThreshold){
  double min=Double.MAX_VALUE;
  double bestTh=minThreshold;
  for (double th=minThreshold; th <= maxThreshold; th+=stepThreshold) {
    if (verbose)     IJ.log("String_Node_Str" + String.format("String_Node_Str",th) + "String_Node_Str");
    double error=getForegroundRestrictedMetricValue(th);
    if (min > error) {
      min=error;
      ;
      bestTh=th;
    }
    if (verbose)     IJ.log("String_Node_Str" + error);
  }
  if (verbose)   IJ.log("String_Node_Str" + min + "String_Node_Str"+ bestTh+ "String_Node_Str");
  return min;
}
Program: 22712
Project: 22712
Buggy source:
/** 
 * No-image constructor. If you use this constructor, the image has to be set using setTrainingImage().
 */
public WekaSegmentation(){
  for (int i=0; i < MAX_NUM_CLASSES; i++)   this.classLabels[i]=new String("String_Node_Str" + i);
  rf=new FastRandomForest();
  rf.setNumTrees(numOfTrees);
  rf.setNumFeatures(randomFeatures);
  rf.setSeed((new Random()).nextInt());
  rf.setNumThreads(Prefs.getThreads());
  classifier=rf;
  addClass();
  addClass();
}

Fixed version (ground truth):
/** 
 * No-image constructor. If you use this constructor, the image has to be set using setTrainingImage().
 */
public WekaSegmentation(){
  for (int i=0; i < MAX_NUM_CLASSES; i++)   this.classLabels[i]=new String("String_Node_Str" + (i + 1));
  rf=new FastRandomForest();
  rf.setNumTrees(numOfTrees);
  rf.setNumFeatures(randomFeatures);
  rf.setSeed((new Random()).nextInt());
  rf.setNumThreads(Prefs.getThreads());
  classifier=rf;
  addClass();
  addClass();
}
Program: 22724
Project: 22724
Buggy source:
/** 
 * Calculate the pixel error and derived statistics between some 2D original labels  and the corresponding proposed labels. Both image are binarized.	 
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param mask 2D image representing the binary mask
 * @param binaryThreshold threshold value to binarize the input images
 * @return classification statistics
 */
public ClassificationStatistics precisionRecallStats(ImageProcessor label,ImageProcessor proposal,ImageProcessor mask,double binaryThreshold){
  float[] labelPix=(float[])label.getPixels();
  float[] proposalPix=(float[])proposal.getPixels();
  float[] maskPixels=(float[])mask.getPixels();
  double truePositives=0;
  double trueNegatives=0;
  double falsePositives=0;
  double falseNegatives=0;
  double pixelError=0;
  double n=0;
  for (int i=0; i < labelPix.length; i++) {
    int pix1=(labelPix[i] > binaryThreshold) ? 1 : 0;
    int pix2=(proposalPix[i] > binaryThreshold) ? 1 : 0;
    int pixMask=maskPixels[i] > 0 ? 1 : 0;
    if (pixMask == 0)     continue;
    if (pix1 == 1) {
      if (pix2 == 1)       truePositives++;
 else       falsePositives++;
    }
 else {
      if (pix2 == 1)       falseNegatives++;
 else       trueNegatives++;
    }
    pixelError+=(pix1 - pix2) * (pix1 - pix2);
    n++;
  }
  if (n > 0)   pixelError/=n;
  return new ClassificationStatistics(truePositives,trueNegatives,falsePositives,falseNegatives,pixelError);
}

Fixed version (ground truth):
/** 
 * Calculate the pixel error and derived statistics between some 2D original labels  and the corresponding proposed labels. Both image are binarized.	 
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param mask 2D image representing the binary mask
 * @param binaryThreshold threshold value to binarize the input images
 * @return classification statistics
 */
public ClassificationStatistics precisionRecallStats(ImageProcessor label,ImageProcessor proposal,ImageProcessor mask,double binaryThreshold){
  float[] labelPix=(float[])label.getPixels();
  float[] proposalPix=(float[])proposal.getPixels();
  float[] maskPixels=(float[])mask.getPixels();
  double truePositives=0;
  double trueNegatives=0;
  double falsePositives=0;
  double falseNegatives=0;
  double pixelError=0;
  double n=0;
  for (int i=0; i < labelPix.length; i++) {
    int pix1=(labelPix[i] > 0) ? 1 : 0;
    int pix2=(proposalPix[i] > binaryThreshold) ? 1 : 0;
    int pixMask=maskPixels[i] > 0 ? 1 : 0;
    if (pixMask == 0)     continue;
    if (pix1 == 1) {
      if (pix2 == 1)       truePositives++;
 else       falsePositives++;
    }
 else {
      if (pix2 == 1)       falseNegatives++;
 else       trueNegatives++;
    }
    pixelError+=(pix1 - pix2) * (pix1 - pix2);
    n++;
  }
  if (n > 0)   pixelError/=n;
  return new ClassificationStatistics(truePositives,trueNegatives,falsePositives,falseNegatives,pixelError);
}
Program: 22725
Project: 22725
Buggy source:
/** 
 * Calculate the pixel error and derived statistics between some 2D original labels  and the corresponding proposed labels. Both image are binarized.	 
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param mask 2D image representing the binary mask
 * @param binaryThreshold threshold value to binarize the input images
 * @return classification statistics
 */
public ClassificationStatistics precisionRecallStats(ImageProcessor label,ImageProcessor proposal,ImageProcessor mask,double binaryThreshold){
  float[] labelPix=(float[])label.getPixels();
  float[] proposalPix=(float[])proposal.getPixels();
  float[] maskPixels=(float[])mask.getPixels();
  double truePositives=0;
  double trueNegatives=0;
  double falsePositives=0;
  double falseNegatives=0;
  double pixelError=0;
  double n=0;
  for (int i=0; i < labelPix.length; i++) {
    int pix1=(labelPix[i] > 0) ? 1 : 0;
    int pix2=(proposalPix[i] > binaryThreshold) ? 1 : 0;
    int pixMask=maskPixels[i] > 0 ? 1 : 0;
    if (pixMask == 0)     continue;
    if (pix1 == 1) {
      if (pix2 == 1)       truePositives++;
 else       falsePositives++;
    }
 else {
      if (pix2 == 1)       falseNegatives++;
 else       trueNegatives++;
    }
    pixelError+=(pix1 - pix2) * (pix1 - pix2);
    n++;
  }
  if (n > 0)   pixelError/=n;
  return new ClassificationStatistics(truePositives,trueNegatives,falsePositives,falseNegatives,pixelError);
}

Fixed version (ground truth):
/** 
 * Calculate the pixel error and derived statistics between some 2D original labels  and the corresponding proposed labels. Both image are binarized.	 
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param mask 2D image representing the binary mask
 * @param binaryThreshold threshold value to binarize the input images
 * @return classification statistics
 */
public ClassificationStatistics precisionRecallStats(ImageProcessor label,ImageProcessor proposal,ImageProcessor mask,double binaryThreshold){
  float[] labelPix=(float[])label.getPixels();
  float[] proposalPix=(float[])proposal.getPixels();
  float[] maskPixels=(float[])mask.getPixels();
  double truePositives=0;
  double trueNegatives=0;
  double falsePositives=0;
  double falseNegatives=0;
  double pixelError=0;
  double n=0;
  for (int i=0; i < labelPix.length; i++) {
    int pix1=(labelPix[i] > 0) ? 1 : 0;
    int pix2=(proposalPix[i] > binaryThreshold) ? 1 : 0;
    int pixMask=maskPixels[i] > 0 ? 1 : 0;
    if (pixMask == 0)     continue;
    if (pix2 == 1) {
      if (pix1 == 1)       truePositives++;
 else       falsePositives++;
    }
 else {
      if (pix1 == 1)       falseNegatives++;
 else       trueNegatives++;
    }
    pixelError+=(pix1 - pix2) * (pix1 - pix2);
    n++;
  }
  if (n > 0)   pixelError/=n;
  return new ClassificationStatistics(truePositives,trueNegatives,falsePositives,falseNegatives,pixelError);
}
Program: 22729
Project: 22729
Buggy source:
/** 
 * Add Sobel filter version of the original image
 * @param sigma radius of the Gaussian blue applied previous to the Sobel filtering
 */
public void addGradient(float sigma){
  ImagePlus[] channels=extractChannels(originalImage);
  ImagePlus[] results=new ImagePlus[channels.length];
  for (int ch=0; ch < channels.length; ch++) {
    GaussianBlur gs=new GaussianBlur();
    ImageProcessor ip_x=channels[ch].getProcessor().convertToFloat();
    gs.blurGaussian(ip_x,0.4 * sigma,0.4 * sigma,0.0002);
    Convolver c=new Convolver();
    float[] sobelFilter_x={1f,2f,1f,0f,0f,0f,-1f,-2f,-1f};
    c.convolveFloat(ip_x,sobelFilter_x,3,3);
    ImageProcessor ip_y=channels[ch].getProcessor().convertToFloat();
    gs.blurGaussian(ip_y,0.4 * sigma,0.4 * sigma,0.0002);
    c=new Convolver();
    float[] sobelFilter_y={1f,0f,-1f,2f,0f,-2f,1f,0f,-1f};
    c.convolveFloat(ip_y,sobelFilter_y,3,3);
    ImageProcessor ip=new FloatProcessor(width,height);
    for (int x=0; x < width; x++) {
      for (int y=0; y < height; y++) {
        float s_x=ip_x.getf(x,y);
        float s_y=ip_y.getf(x,y);
        ip.setf(x,y,(float)Math.sqrt(s_x * s_x + s_y * s_y));
      }
    }
    results[ch]=new ImagePlus(availableFeatures[SOBEL] + "String_Node_Str" + sigma,ip);
  }
  ImagePlus merged=mergeResultChannels(results);
  wholeStack.addSlice(merged.getTitle(),merged.getImageStack().getProcessor(1));
}

Fixed version (ground truth):
/** 
 * Add Sobel filter version of the original image
 * @param sigma radius of the Gaussian blue applied previous to the Sobel filtering
 */
public void addGradient(float sigma){
  ImagePlus[] channels=extractChannels(originalImage);
  ImagePlus[] results=new ImagePlus[channels.length];
  for (int ch=0; ch < channels.length; ch++) {
    GaussianBlur gs=new GaussianBlur();
    ImageProcessor ip_x=channels[ch].getProcessor().duplicate().convertToFloat();
    gs.blurGaussian(ip_x,0.4 * sigma,0.4 * sigma,0.0002);
    Convolver c=new Convolver();
    float[] sobelFilter_x={1f,2f,1f,0f,0f,0f,-1f,-2f,-1f};
    c.convolveFloat(ip_x,sobelFilter_x,3,3);
    ImageProcessor ip_y=channels[ch].getProcessor().duplicate().convertToFloat();
    gs.blurGaussian(ip_y,0.4 * sigma,0.4 * sigma,0.0002);
    c=new Convolver();
    float[] sobelFilter_y={1f,0f,-1f,2f,0f,-2f,1f,0f,-1f};
    c.convolveFloat(ip_y,sobelFilter_y,3,3);
    ImageProcessor ip=new FloatProcessor(width,height);
    for (int x=0; x < width; x++) {
      for (int y=0; y < height; y++) {
        float s_x=ip_x.getf(x,y);
        float s_y=ip_y.getf(x,y);
        ip.setf(x,y,(float)Math.sqrt(s_x * s_x + s_y * s_y));
      }
    }
    results[ch]=new ImagePlus(availableFeatures[SOBEL] + "String_Node_Str" + sigma,ip);
  }
  ImagePlus merged=mergeResultChannels(results);
  wholeStack.addSlice(merged.getTitle(),merged.getImageStack().getProcessor(1));
}
Program: 22733
Project: 22733
Buggy source:
/** 
 * Calculate the pixel error and derived statistics between some 2D original labels  and the corresponding proposed labels. Both image are binarized.	 
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param mask 2D image representing the binary mask
 * @param binaryThreshold threshold value to binarize the input images
 * @return classification statistics
 */
public ClassificationStatistics precisionRecallStats(ImageProcessor label,ImageProcessor proposal,ImageProcessor mask,double binaryThreshold){
  float[] labelPix=(float[])label.getPixels();
  float[] proposalPix=(float[])proposal.getPixels();
  float[] maskPixels=(float[])mask.getPixels();
  double truePositives=0;
  double trueNegatives=0;
  double falsePositives=0;
  double falseNegatives=0;
  double pixelError=0;
  double n=0;
  for (int i=0; i < labelPix.length; i++) {
    int pix1=(labelPix[i] > 0) ? 1 : 0;
    int pix2=(proposalPix[i] > binaryThreshold) ? 1 : 0;
    if (maskPixels[i] > 0)     continue;
    if (pix2 == 1) {
      if (pix1 == 1)       truePositives++;
 else       falsePositives++;
    }
 else {
      if (pix1 == 1)       falseNegatives++;
 else       trueNegatives++;
    }
    pixelError+=(pix1 - pix2) * (pix1 - pix2);
    n++;
  }
  if (n > 0)   pixelError/=n;
  return new ClassificationStatistics(truePositives,trueNegatives,falsePositives,falseNegatives,pixelError);
}

Fixed version (ground truth):
/** 
 * Calculate the pixel error and derived statistics between some 2D original labels  and the corresponding proposed labels. Both image are binarized.	 
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param mask 2D image representing the binary mask
 * @param binaryThreshold threshold value to binarize the input images
 * @return classification statistics
 */
public ClassificationStatistics precisionRecallStats(ImageProcessor label,ImageProcessor proposal,ImageProcessor mask,double binaryThreshold){
  float[] labelPix=(float[])label.getPixels();
  float[] proposalPix=(float[])proposal.getPixels();
  float[] maskPixels=(float[])mask.getPixels();
  double truePositives=0;
  double trueNegatives=0;
  double falsePositives=0;
  double falseNegatives=0;
  double pixelError=0;
  double n=0;
  for (int i=0; i < labelPix.length; i++) {
    int pix1=(labelPix[i] > 0) ? 1 : 0;
    int pix2=(proposalPix[i] > binaryThreshold) ? 1 : 0;
    if (maskPixels[i] > 0) {
      if (pix2 == 1) {
        if (pix1 == 1)         truePositives++;
 else         falsePositives++;
      }
 else {
        if (pix1 == 1)         falseNegatives++;
 else         trueNegatives++;
      }
      pixelError+=(pix1 - pix2) * (pix1 - pix2);
      n++;
    }
  }
  if (n > 0)   pixelError/=n;
  return new ClassificationStatistics(truePositives,trueNegatives,falsePositives,falseNegatives,pixelError);
}
Program: 22734
Project: 22734
Buggy source:
/** 
 * Filter small objects and holes at a specific threshold value
 * @param probabilityMap probability image
 * @param thresholdValue threshold to use
 * @param minSize minimum size of the objects (in pixels)
 */
public static void filterSmallObjectsAndHoles(FloatProcessor probabilityMap,double thresholdValue,int minSize){
  ByteProcessor thresholded=threshold(probabilityMap,thresholdValue);
  Results res=connectedComponents(new ImagePlus("String_Node_Str",thresholded),4,minSize);
  ByteProcessor th=threshold(res.allRegions.getProcessor(),0.5);
  ByteProcessor th2=(ByteProcessor)th.duplicate();
  th2.copyBits(thresholded,0,0,Blitter.DIFFERENCE);
  for (int x=0; x < th2.getWidth(); x++)   for (int y=0; y < th2.getHeight(); y++) {
    if (th2.getPixelValue(x,y) > 0)     probabilityMap.putPixelValue(x,y,0);
  }
  fill(th,255,0);
  th2=(ByteProcessor)th.duplicate();
  th2.copyBits(thresholded,0,0,Blitter.DIFFERENCE);
  for (int x=0; x < th2.getWidth(); x++)   for (int y=0; y < th2.getHeight(); y++) {
    if (th2.getPixelValue(x,y) > 0)     probabilityMap.putPixelValue(x,y,1);
  }
}

Fixed version (ground truth):
/** 
 * Filter small objects and holes at a specific threshold value
 * @param probabilityMap probability image
 * @param thresholdValue threshold to use
 * @param minSize minimum size of the objects (in pixels)
 */
public static void filterSmallObjectsAndHoles(FloatProcessor probabilityMap,double thresholdValue,int minSize){
  ByteProcessor thresholded=threshold(probabilityMap,thresholdValue);
  Results res=connectedComponents(new ImagePlus("String_Node_Str",thresholded),4,minSize);
  ByteProcessor th=threshold(res.allRegions.getProcessor(),0.5);
  ByteProcessor th2=(ByteProcessor)th.duplicate();
  th2.copyBits(thresholded,0,0,Blitter.DIFFERENCE);
  byte[] th2pixels=(byte[])th2.getPixels();
  final float[] probPixels=(float[])probabilityMap.getPixels();
  for (int i=0; i < th2pixels.length; i++) {
    if (th2pixels[i] != 0)     probPixels[i]=0;
  }
  th2=(ByteProcessor)th.duplicate();
  fill(th2,255,0);
  th2.copyBits(th,0,0,Blitter.DIFFERENCE);
  th2pixels=(byte[])th2.getPixels();
  for (int i=0; i < th2pixels.length; i++) {
    if (th2pixels[i] != 0)     probPixels[i]=1;
  }
}
Program: 22735
Project: 22735
Buggy source:
/** 
 * Get the binary class coordinates from a label image (2D image or stack)
 * @param labelImage labels (they can be in any format, black = 0)
 * @param mask binary mask to select the pixels to be extracted
 * @return array with the two lists (black and white) of sample coordinates
 */
public static ArrayList<Point3f>[] getClassCoordinates(ImagePlus labelImage,ImagePlus mask){
  final ArrayList<Point3f>[] classPoints=new ArrayList[2];
  classPoints[0]=new ArrayList<Point3f>();
  classPoints[1]=new ArrayList<Point3f>();
  final int width=labelImage.getWidth();
  final int height=labelImage.getHeight();
  final int size=labelImage.getImageStackSize();
  final boolean useMask=null != mask;
  for (int slice=1; slice <= size; slice++) {
    final float[] labelsPix=(float[])labelImage.getImageStack().getProcessor(slice).convertToFloat().getPixels();
    final float[] maskPix=useMask ? (float[])mask.getImageStack().getProcessor(slice).convertToFloat().getPixels() : null;
    for (int x=0; x < width; x++)     for (int y=0; y < height; y++)     if (useMask && maskPix[x + y * width] > 0) {
      if (labelsPix[x + y * width] != 0)       classPoints[1].add(new Point3f(new float[]{x,y,slice - 1}));
 else       classPoints[0].add(new Point3f(new float[]{x,y,slice - 1}));
    }
  }
  return classPoints;
}

Fixed version (ground truth):
/** 
 * Get the binary class coordinates from a label image (2D image or stack)
 * @param labelImage labels (they can be in any format, black = 0)
 * @param mask binary mask to select the pixels to be extracted
 * @return array with the two lists (black and white) of sample coordinates
 */
public static ArrayList<Point3f>[] getClassCoordinates(ImagePlus labelImage,ImagePlus mask){
  final ArrayList<Point3f>[] classPoints=new ArrayList[2];
  classPoints[0]=new ArrayList<Point3f>();
  classPoints[1]=new ArrayList<Point3f>();
  final int width=labelImage.getWidth();
  final int height=labelImage.getHeight();
  final int size=labelImage.getImageStackSize();
  if (null != mask) {
    for (int slice=1; slice <= size; slice++) {
      final float[] labelsPix=(float[])labelImage.getImageStack().getProcessor(slice).convertToFloat().getPixels();
      final float[] maskPix=(float[])mask.getImageStack().getProcessor(slice).convertToFloat().getPixels();
      for (int x=0; x < width; x++)       for (int y=0; y < height; y++)       if (maskPix[x + y * width] > 0) {
        if (labelsPix[x + y * width] != 0)         classPoints[1].add(new Point3f(new float[]{x,y,slice - 1}));
 else         classPoints[0].add(new Point3f(new float[]{x,y,slice - 1}));
      }
    }
  }
 else {
    for (int slice=1; slice <= size; slice++) {
      final float[] labelsPix=(float[])labelImage.getImageStack().getProcessor(slice).convertToFloat().getPixels();
      for (int x=0; x < width; x++)       for (int y=0; y < height; y++)       if (labelsPix[x + y * width] != 0)       classPoints[1].add(new Point3f(new float[]{x,y,slice - 1}));
 else       classPoints[0].add(new Point3f(new float[]{x,y,slice - 1}));
    }
  }
  return classPoints;
}
Program: 22737
Project: 22737
Buggy source:
/** 
 * Get the binary class coordinates from a label image (2D image or stack)
 * @param labelImage labels (they can be in any format, black = 0)
 * @param mask binary mask to select the pixels to be extracted
 * @return array with the two lists (black and white) of sample coordinates
 */
public static ArrayList<Point3f>[] getClassCoordinates(ImagePlus labelImage,ImagePlus mask){
  final ArrayList<Point3f>[] classPoints=new ArrayList[2];
  classPoints[0]=new ArrayList<Point3f>();
  classPoints[1]=new ArrayList<Point3f>();
  final int width=labelImage.getWidth();
  final int height=labelImage.getHeight();
  final int size=labelImage.getImageStackSize();
  final boolean useMask=null != mask;
  for (int slice=1; slice <= size; slice++) {
    final float[] labelsPix=(float[])labelImage.getImageStack().getProcessor(slice).convertToFloat().getPixels();
    final float[] maskPix=useMask ? (float[])labelImage.getImageStack().getProcessor(slice).convertToFloat().getPixels() : null;
    for (int x=0; x < width; x++)     for (int y=0; y < height; y++)     if (useMask && maskPix[x + y * width] > 0) {
      if (labelsPix[x + y * width] > 0)       classPoints[1].add(new Point3f(new float[]{x,y,slice - 1}));
 else       classPoints[0].add(new Point3f(new float[]{x,y,slice - 1}));
    }
  }
  return classPoints;
}

Fixed version (ground truth):
/** 
 * Get the binary class coordinates from a label image (2D image or stack)
 * @param labelImage labels (they can be in any format, black = 0)
 * @param mask binary mask to select the pixels to be extracted
 * @return array with the two lists (black and white) of sample coordinates
 */
public static ArrayList<Point3f>[] getClassCoordinates(ImagePlus labelImage,ImagePlus mask){
  final ArrayList<Point3f>[] classPoints=new ArrayList[2];
  classPoints[0]=new ArrayList<Point3f>();
  classPoints[1]=new ArrayList<Point3f>();
  final int width=labelImage.getWidth();
  final int height=labelImage.getHeight();
  final int size=labelImage.getImageStackSize();
  final boolean useMask=null != mask;
  for (int slice=1; slice <= size; slice++) {
    final float[] labelsPix=(float[])labelImage.getImageStack().getProcessor(slice).convertToFloat().getPixels();
    final float[] maskPix=useMask ? (float[])mask.getImageStack().getProcessor(slice).convertToFloat().getPixels() : null;
    for (int x=0; x < width; x++)     for (int y=0; y < height; y++)     if (useMask && maskPix[x + y * width] > 0) {
      if (labelsPix[x + y * width] != 0)       classPoints[1].add(new Point3f(new float[]{x,y,slice - 1}));
 else       classPoints[0].add(new Point3f(new float[]{x,y,slice - 1}));
    }
  }
  return classPoints;
}
Program: 22741
Project: 22741
Buggy source:
/** 
 * Get the image with the classified mismatches
 * @param wr warping results
 * @param radius radius in pixels to use while classifying pixels
 * @return image with classified mismatches
 */
public ImagePlus getMismatchImage(WarpingResults wr,int radius){
  int[] mismatchesLabels=classifyMismatches2d(wr.warpedSource,wr.mismatches,radius);
  ByteProcessor bp=new ByteProcessor(wr.warpedSource.getWidth(),wr.warpedSource.getHeight());
  for (int i=0; i < wr.mismatches.size(); i++) {
    Point3f p=wr.mismatches.get(i);
    bp.set((int)p.x,(int)p.y,mismatchesLabels[i]);
  }
  return new ImagePlus("String_Node_Str",bp);
}

Fixed version (ground truth):
/** 
 * Get the image with the classified mismatches
 * @param wr warping results
 * @param mismatchesLabels labels of the warping mismatches
 * @return image with classified mismatches
 */
public ImagePlus getMismatchImage(WarpingResults wr,int[] mismatchesLabels,int flags){
  ByteProcessor bp=new ByteProcessor(wr.warpedSource.getWidth(),wr.warpedSource.getHeight());
  for (int i=0; i < wr.mismatches.size(); i++) {
    Point3f p=wr.mismatches.get(i);
    bp.set((int)p.x,(int)p.y,mismatchesLabels[i] & flags);
  }
  return new ImagePlus("String_Node_Str",bp);
}