Program: 22751
Project: 22751
Buggy source:
/** 
 * Calculate the adjusted Rand error between some 2D original labels  and the corresponding proposed labels. Both image are binarized. The adjusted Rand error is defined as the 1 - adjusted 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 adjusted Rand error
 */
public static double adjustedRandError(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 - adjustedRandIndex(components1,components2);
}

Fixed version (ground truth):
/** 
 * Calculate the adjusted Rand error between some 2D original labels  and the corresponding proposed labels. Both image are binarized. The adjusted Rand error is defined as the 1 - adjusted 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 adjusted Rand error
 */
public static double adjustedRandError(ImageProcessor label,ImageProcessor proposal,double binaryThreshold){
  ByteProcessor binaryLabel=new ByteProcessor(label.getWidth(),label.getHeight());
  ByteProcessor binaryProposal=new ByteProcessor(proposal.getWidth(),proposal.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);
  }
  final ImagePlus im1=new ImagePlus("String_Node_Str",binaryLabel);
  ShortProcessor components1=(ShortProcessor)connectedComponents(im1,4).allRegions.getProcessor();
  final ImagePlus im2=new ImagePlus("String_Node_Str",binaryProposal);
  ShortProcessor components2=(ShortProcessor)connectedComponents(im2,4).allRegions.getProcessor();
  return 1 - adjustedRandIndex(components1,components2);
}