Program: 22752
Project: 22752
Buggy source:
/** 
 * Calculate the Rand error between some 2D original labels  and the corresponding proposed labels. Both image are binarized. The Rand error is defined as the 1 - Rand index, as described by William M. Rand \cite{Rand71}. BibTeX: <pre> &#64;article{Rand71, author    = {William M. Rand}, title     = {Objective criteria for the evaluation of clustering methods}, journal   = {Journal of the American Statistical Association}, year      = {1971}, volume    = {66}, number    = {336}, pages     = {846–850}, doi       = {10.2307/2284239) } </pre>
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param binaryThreshold threshold value to binarize the input images
 * @return Rand error
 */
public static double randError(ImageProcessor label,ImageProcessor proposal,double binaryThreshold){
  ByteProcessor binaryLabel=new ByteProcessor(label.getWidth(),label.getHeight());
  ByteProcessor binaryProposal=new ByteProcessor(label.getWidth(),label.getHeight());
  for (int x=0; x < label.getWidth(); x++)   for (int y=0; y < label.getHeight(); y++) {
    binaryLabel.set(x,y,label.get(x,y) > 0 ? 255 : 0);
    binaryProposal.set(x,y,proposal.get(x,y) > 0 ? 255 : 0);
  }
  ShortProcessor components1=(ShortProcessor)connectedComponents(new ImagePlus("String_Node_Str",binaryLabel),4).allRegions.getProcessor();
  ShortProcessor components2=(ShortProcessor)connectedComponents(new ImagePlus("String_Node_Str",binaryProposal),4).allRegions.getProcessor();
  return 1 - randIndex(components1,components2);
}

Fixed version (ground truth):
/** 
 * Calculate the Rand error between some 2D original labels  and the corresponding proposed labels. Both image are binarized. The Rand error is defined as the 1 - Rand index, as described by William M. Rand \cite{Rand71}. BibTeX: <pre> &#64;article{Rand71, author    = {William M. Rand}, title     = {Objective criteria for the evaluation of clustering methods}, journal   = {Journal of the American Statistical Association}, year      = {1971}, volume    = {66}, number    = {336}, pages     = {846–850}, doi       = {10.2307/2284239) } </pre>
 * @param label 2D image with the original labels
 * @param proposal 2D image with the proposed labels
 * @param binaryThreshold threshold value to binarize the input images
 * @return Rand error
 */
public static double randError(ImageProcessor label,ImageProcessor proposal,double binaryThreshold){
  ByteProcessor binaryLabel=new ByteProcessor(label.getWidth(),label.getHeight());
  ByteProcessor binaryProposal=new ByteProcessor(label.getWidth(),label.getHeight());
  for (int x=0; x < label.getWidth(); x++)   for (int y=0; y < label.getHeight(); y++) {
    binaryLabel.set(x,y,label.getPixelValue(x,y) > binaryThreshold ? 255 : 0);
    binaryProposal.set(x,y,proposal.getPixelValue(x,y) > binaryThreshold ? 255 : 0);
  }
  ShortProcessor components1=(ShortProcessor)connectedComponents(new ImagePlus("String_Node_Str",binaryLabel),4).allRegions.getProcessor();
  ShortProcessor components2=(ShortProcessor)connectedComponents(new ImagePlus("String_Node_Str",binaryProposal),4).allRegions.getProcessor();
  return 1 - randIndex(components1,components2);
}