Program: 22700
Project: 22700
Buggy source:
/** 
 * Computes topological numbers for the central point of an image patch. These numbers can be used as the basis of a topological classification. T_4 and T_8 are used when IM is a 2d image patch of size 3x3 defined on p. 172 of Bertrand & Malandain, Patt. Recog. Lett. 15, 169-75 (1994).
 * @param im input image
 * @param adjacency number of neighbors
 * @return number of components in the patch excluding the center pixel
 */
public int topo(final ImagePlus im,final int adjacency){
  ImageProcessor components=null;
  final ImagePlus im2=new ImagePlus("String_Node_Str",im.getProcessor().duplicate());
switch (adjacency) {
case 4:
    if (im.getStack().getSize() > 1) {
      IJ.error("String_Node_Str");
      return -1;
    }
  if (im.getProcessor().getWidth() > 3 || im.getProcessor().getHeight() > 3) {
    IJ.error("String_Node_Str");
    return -1;
  }
im2.getProcessor().set(1,1,0);
components=Utils.connectedComponents(im2,adjacency).allRegions.getProcessor();
components.set(0,0,0);
components.set(0,2,0);
components.set(1,1,0);
components.set(2,0,0);
components.set(2,2,0);
break;
case 8:
if (im.getStack().getSize() > 1) {
IJ.error("String_Node_Str");
return -1;
}
if (im.getProcessor().getWidth() > 3 || im.getProcessor().getHeight() > 3) {
IJ.error("String_Node_Str");
return -1;
}
im2.getProcessor().set(1,1,0);
components=Utils.connectedComponents(im2,adjacency).allRegions.getProcessor();
break;
default :
IJ.error("String_Node_Str");
return -1;
}
if (null == components) return -1;
int t=0;
ArrayList<Integer> uniqueId=new ArrayList<Integer>();
for (int i=0; i < 3; i++) for (int j=0; j < 3; j++) {
if ((t=components.get(i,j)) != 0 && !uniqueId.contains(t)) {
uniqueId.add(t);
}
}
return uniqueId.size();
}

Fixed version (ground truth):
/** 
 * Computes topological numbers for the central point of an image patch. These numbers can be used as the basis of a topological classification. T_4 and T_8 are used when IM is a 2d image patch of size 3x3 defined on p. 172 of Bertrand &amp; Malandain, Patt. Recog. Lett. 15, 169-75 (1994).
 * @param im input image
 * @param adjacency number of neighbors
 * @return number of components in the patch excluding the center pixel
 */
public int topo(final ImagePlus im,final int adjacency){
  ImageProcessor components=null;
  final ImagePlus im2=new ImagePlus("String_Node_Str",im.getProcessor().duplicate());
switch (adjacency) {
case 4:
    if (im.getStack().getSize() > 1) {
      IJ.error("String_Node_Str");
      return -1;
    }
  if (im.getProcessor().getWidth() > 3 || im.getProcessor().getHeight() > 3) {
    IJ.error("String_Node_Str");
    return -1;
  }
im2.getProcessor().set(1,1,0);
components=Utils.connectedComponents(im2,adjacency).allRegions.getProcessor();
components.set(0,0,0);
components.set(0,2,0);
components.set(1,1,0);
components.set(2,0,0);
components.set(2,2,0);
break;
case 8:
if (im.getStack().getSize() > 1) {
IJ.error("String_Node_Str");
return -1;
}
if (im.getProcessor().getWidth() > 3 || im.getProcessor().getHeight() > 3) {
IJ.error("String_Node_Str");
return -1;
}
im2.getProcessor().set(1,1,0);
components=Utils.connectedComponents(im2,adjacency).allRegions.getProcessor();
break;
default :
IJ.error("String_Node_Str");
return -1;
}
if (null == components) return -1;
int t=0;
ArrayList<Integer> uniqueId=new ArrayList<Integer>();
for (int i=0; i < 3; i++) for (int j=0; j < 3; j++) {
if ((t=components.get(i,j)) != 0 && !uniqueId.contains(t)) {
uniqueId.add(t);
}
}
return uniqueId.size();
}