Program: 22772
Project: 22772
Buggy source:
/** 
 * Train a classifier using BLOTC (static method)
 * @param image input image
 * @param labels binary labels
 * @param classifier Weka classifier
 * @param resample flag to resample input data (to homogenize classes distribution)
 * @param selectAttributes flag to select best attributes and filter the data
 * @return warped labels from applying BLOTC 
 */
public static ImagePlus trainBLOTC(final ImagePlus image,final ImagePlus labels,final AbstractClassifier classifier,final boolean resample,final boolean selectAttributes){
  final ImageStack warpedLabelStack=new ImageStack(image.getWidth(),image.getHeight());
  for (int i=1; i <= labels.getStackSize(); i++)   warpedLabelStack.addSlice("String_Node_Str" + i,labels.getStack().getProcessor(i).duplicate().convertToFloat());
  ImagePlus warpedLabels=new ImagePlus("String_Node_Str",warpedLabelStack);
  final Weka_Segmentation seg=new Weka_Segmentation(image);
  if (null != classifier)   seg.setClassifier(classifier);
  seg.useAllFeatures();
  String firstClass=seg.classLabels[0];
  String secondClass=seg.classLabels[1];
  double error=Double.MAX_VALUE;
  final int numOfPixelsPerImage=image.getWidth() * image.getHeight();
  IJ.log("String_Node_Str");
  seg.addBinaryData(image,labels,secondClass,firstClass);
  Instances originalData=seg.getTrainingInstances();
  if (selectAttributes) {
    IJ.log("String_Node_Str");
    final long start=System.currentTimeMillis();
    originalData=selectAttributes(originalData);
    final long end=System.currentTimeMillis();
    seg.setLoadedTrainingData(originalData);
    IJ.log("String_Node_Str" + originalData.numInstances() + "String_Node_Str"+ originalData.numAttributes()+ "String_Node_Str"+ originalData.numClasses()+ "String_Node_Str");
    IJ.log("String_Node_Str" + (end - start) + "String_Node_Str");
  }
  Instances trainingData=originalData;
  if (resample) {
    IJ.log("String_Node_Str");
    trainingData=homogenizeTrainingData(trainingData);
    seg.setLoadedTrainingData(trainingData);
  }
  int iter=1;
  while (true) {
    IJ.log("String_Node_Str");
    seg.trainClassifier();
    double newError=seg.getTrainingError();
    IJ.log("String_Node_Str" + iter + "String_Node_Str"+ newError);
    if (newError >= error)     break;
    error=newError;
    final ImageStack proposalStack=new ImageStack(image.getWidth(),image.getHeight());
    for (int i=1; i <= image.getStackSize(); i++) {
      final Instances subDataSet=new Instances(originalData,(i - 1) * numOfPixelsPerImage,numOfPixelsPerImage);
      IJ.log("String_Node_Str" + i + "String_Node_Str");
      ImagePlus result=seg.getProbabilityMapsMT(subDataSet,image.getWidth(),image.getHeight());
      proposalStack.addSlice("String_Node_Str" + i,result.getImageStack().getProcessor(2));
    }
    final ImagePlus proposal=new ImagePlus("String_Node_Str",proposalStack);
    IJ.log("String_Node_Str");
    warpedLabels=seg.simplePointWarp2d(warpedLabels,proposal,null,0.5);
    if (!resample)     seg.udpateDataClassification(warpedLabels,secondClass,firstClass);
 else {
      IJ.log("String_Node_Str");
      updateDataClassification(originalData,warpedLabels,1,0);
      trainingData=homogenizeTrainingData(originalData);
      seg.setLoadedTrainingData(trainingData);
    }
    iter++;
  }
  return warpedLabels;
}

Fixed version (ground truth):
/** 
 * Train a classifier using BLOTC (static method)
 * @param image input image
 * @param labels binary labels
 * @param classifier Weka classifier
 * @param resample flag to resample input data (to homogenize classes distribution)
 * @param selectAttributes flag to select best attributes and filter the data
 * @return warped labels from applying BLOTC 
 */
public static ImagePlus trainBLOTC(final ImagePlus image,final ImagePlus labels,final AbstractClassifier classifier,final boolean resample,final boolean selectAttributes){
  final ImageStack warpedLabelStack=new ImageStack(image.getWidth(),image.getHeight());
  for (int i=1; i <= labels.getStackSize(); i++)   warpedLabelStack.addSlice("String_Node_Str" + i,labels.getStack().getProcessor(i).duplicate().convertToFloat());
  ImagePlus warpedLabels=new ImagePlus("String_Node_Str",warpedLabelStack);
  final Weka_Segmentation seg=new Weka_Segmentation(image);
  if (null != classifier)   seg.setClassifier(classifier);
  seg.useAllFeatures();
  String firstClass=seg.classLabels[0];
  String secondClass=seg.classLabels[1];
  double error=Double.MAX_VALUE;
  final int numOfPixelsPerImage=image.getWidth() * image.getHeight();
  IJ.log("String_Node_Str");
  seg.addBinaryData(image,labels,secondClass,firstClass);
  Instances originalData=seg.getTrainingInstances();
  if (selectAttributes) {
    IJ.log("String_Node_Str");
    final long start=System.currentTimeMillis();
    originalData=selectAttributes(originalData);
    final long end=System.currentTimeMillis();
    seg.setLoadedTrainingData(originalData);
    IJ.log("String_Node_Str" + originalData.numInstances() + "String_Node_Str"+ originalData.numAttributes()+ "String_Node_Str"+ originalData.numClasses()+ "String_Node_Str");
    IJ.log("String_Node_Str" + (end - start) + "String_Node_Str");
  }
  Instances trainingData=originalData;
  if (resample) {
    IJ.log("String_Node_Str");
    trainingData=homogenizeTrainingData(trainingData);
    seg.setLoadedTrainingData(trainingData);
  }
  int iter=1;
  while (true) {
    IJ.log("String_Node_Str");
    seg.trainClassifier();
    double newError=seg.getTrainingError();
    IJ.log("String_Node_Str" + iter + "String_Node_Str"+ newError);
    if (newError >= error)     break;
    error=newError;
    final ImageStack proposalStack=new ImageStack(image.getWidth(),image.getHeight());
    for (int i=1; i <= image.getStackSize(); i++) {
      final Instances subDataSet=new Instances(originalData,(i - 1) * numOfPixelsPerImage,numOfPixelsPerImage);
      IJ.log("String_Node_Str" + i + "String_Node_Str");
      ImagePlus result=seg.getProbabilityMapsMT(subDataSet,image.getWidth(),image.getHeight());
      proposalStack.addSlice("String_Node_Str" + i,result.getImageStack().getProcessor(2));
    }
    final ImagePlus proposal=new ImagePlus("String_Node_Str",proposalStack);
    IJ.log("String_Node_Str");
    warpedLabels=seg.simplePointWarp2dMT(warpedLabels,proposal,null,0.5);
    if (!resample)     seg.udpateDataClassification(warpedLabels,secondClass,firstClass);
 else {
      IJ.log("String_Node_Str");
      updateDataClassification(originalData,warpedLabels,1,0);
      trainingData=homogenizeTrainingData(originalData);
      seg.setLoadedTrainingData(trainingData);
    }
    iter++;
  }
  return warpedLabels;
}