Program: 175188
Project: 175188
Buggy source:
/** 
 * aggregate using the neighbours within tilesize
 * @param neighboursdistance
 * @param tilesize
 * @param removelandconnectedpixels
 * @param bands
 * @param mask
 * @param kdist
 * @throws IOException
 */
private void aggregate(DetectedPixels detPixels,int neighboursdistance,int tilesize,boolean removelandconnectedpixels,int[] bands,IMask mask,KDistributionEstimation kdist) throws IOException {
  int id=0;
  Pixel pixels[]=detPixels.getAllDetectedPixelsValues().toArray(new Pixel[0]);
  int count=0;
  for (  Pixel detectedPix : pixels) {
    count++;
    int xx=detectedPix.x;
    int yy=detectedPix.y;
    if ((count % 100) == 0)     logger.info(new StringBuilder().append("String_Node_Str").append(count).append("String_Node_Str").append(xx).append("String_Node_Str").append(yy).toString());
    boolean checked=false;
    for (    BoatConnectedPixelMap boatpixel : detPixels.listboatneighbours) {
      if (boatpixel.containsPixel(xx,yy)) {
        checked=true;
        break;
      }
    }
    if (checked) {
      continue;
    }
    int cornerx=Math.min(Math.max(0,xx - tilesize / 2),gir.getWidth() - tilesize);
    int cornery=Math.min(Math.max(0,yy - tilesize / 2),gir.getHeight() - tilesize);
    int boatx=xx - cornerx;
    int boaty=yy - cornery;
    int numberbands=bands.length;
    int[][] data=new int[numberbands][];
    try {
      for (int bandcounter=0; bandcounter < numberbands; bandcounter++) {
        data[bandcounter]=gir.read(cornerx,cornery,tilesize,tilesize,bands[bandcounter]);
      }
    }
 catch (    IOException e) {
      logger.error(e.getMessage());
      throw e;
    }
    double[][] statistics=AnalysisUtil.calculateImagemapStatistics(cornerx,cornery,tilesize,tilesize,bands,data,kdist);
    double[][] thresholdvalues=new double[numberbands][2];
    int[] maxValue=new int[numberbands];
    boolean pixelabove=false;
    for (int bandcounter=0; bandcounter < numberbands; bandcounter++) {
      double mean=(statistics[bandcounter][1] + statistics[bandcounter][2] + statistics[bandcounter][3]+ statistics[bandcounter][4]) / 4;
      thresholdvalues[bandcounter][0]=mean + 3 * mean * statistics[bandcounter][0];
      thresholdvalues[bandcounter][1]=mean + 5 * mean * statistics[bandcounter][0];
      int value=data[bandcounter][boatx + boaty * tilesize];
      if (value > thresholdvalues[bandcounter][1]) {
        pixelabove=true;
      }
      if (value > maxValue[bandcounter]) {
        maxValue[bandcounter]=data[bandcounter][boatx + boaty * tilesize];
      }
    }
    if (pixelabove) {
      Raster rastermask=null;
      if (mask != null) {
        if (mask.intersects(cornerx,cornery,tilesize,tilesize)) {
          rastermask=(mask.rasterize(cornerx,cornery,tilesize,tilesize,-cornerx,-cornery,1.0)).getData();
        }
      }
      BoatConnectedPixelMap boatpixel=new BoatConnectedPixelMap(cornerx,cornery,xx,yy,id++,data[0][boatx + boaty * tilesize]);
      for (int iBand=0; iBand < numberbands; iBand++) {
        String bb=((SarImageReader)gir).getBands()[iBand];
        float thresholdBand=this.thresholdsBandParams.get(bb);
        int row=(cornery + 1) / this.verTiles;
        int col=(cornerx + 1) / this.horTiles;
        kdist.setImageData(cornerx,cornery,tilesize,tilesize,row,col,iBand);
        int[] newdata=gir.readTile(cornerx,cornery,tilesize,tilesize,iBand);
        kdist.estimate(rastermask,newdata);
        double[] treshTile=kdist.getDetectThresh();
        double threshTotal=treshTile[0] + treshTile[1] + treshTile[2]+ treshTile[3];
        double threshWindowsVals[]=AnalysisUtil.calcThreshWindowVals(thresholdBand,treshTile);
        double tileAvg=threshTotal / treshTile[5];
        double tileStdDev=treshTile[0] * threshTotal / treshTile[5];
        int idxBand=idxOn4Band(bb);
        boatpixel.putMeanValue(idxBand,(statistics[iBand][1] + statistics[iBand][2] + statistics[iBand][3]+ statistics[iBand][4]) / 4);
        boatpixel.putThresholdValue(idxBand,(threshWindowsVals[0] + threshWindowsVals[1] + threshWindowsVals[2]+ threshWindowsVals[3]) / 4);
        boatpixel.putMaxValue(idxBand,maxValue[iBand]);
        boatpixel.putStDevValue(idxBand,tileStdDev);
        double significance=(maxValue[iBand] - tileAvg) / tileStdDev;
        boatpixel.putSignificanceValue(idxBand,significance);
        boatpixel.putAvgValue(idxBand,tileAvg);
      }
      detPixels.listboatneighbours.add(boatpixel);
      List<int[]> boataggregatedpixels=new ArrayList<int[]>();
      int[] imagemap=new int[tilesize * tilesize];
      for (int i=0; i < tilesize * tilesize; i++) {
        imagemap[i]=0;
      }
      boolean result=detPixels.checkNeighbours(boataggregatedpixels,imagemap,data,thresholdvalues,new int[]{boatx,boaty},neighboursdistance,tilesize,rastermask);
      boatpixel.setTouchesLandMask(result);
      for (      int[] pixel : boataggregatedpixels) {
        boatpixel.addConnectedPixel(pixel[0] + cornerx,pixel[1] + cornery,pixel[2],pixel[3] == 1 ? true : false);
      }
    }
  }
  if (removelandconnectedpixels) {
    List<BoatConnectedPixelMap> toRemove=new ArrayList<BoatConnectedPixelMap>();
    for (int i=0; i < detPixels.listboatneighbours.size(); i++) {
      BoatConnectedPixelMap boat=detPixels.listboatneighbours.get(i);
      if (boat.touchesLand()) {
        toRemove.add(boat);
      }
    }
    detPixels.listboatneighbours.removeAll(toRemove);
  }
  detPixels.computeBoatsAttributesAndStatistics(detPixels.listboatneighbours);
}

Fixed version (ground truth):
/** 
 * aggregate using the neighbours within tilesize
 * @param neighboursdistance
 * @param tilesize
 * @param removelandconnectedpixels
 * @param bands
 * @param mask
 * @param kdist
 * @throws IOException
 */
private void aggregate(DetectedPixels detPixels,int neighboursdistance,int tilesize,boolean removelandconnectedpixels,int[] bands,IMask mask,KDistributionEstimation kdist) throws IOException {
  int id=0;
  Pixel pixels[]=detPixels.getAllDetectedPixelsValues().toArray(new Pixel[0]);
  int count=0;
  for (  Pixel detectedPix : pixels) {
    count++;
    int xx=detectedPix.x;
    int yy=detectedPix.y;
    if ((count % 100) == 0)     logger.info(new StringBuilder().append("String_Node_Str").append(count).append("String_Node_Str").append(xx).append("String_Node_Str").append(yy).toString());
    boolean checked=false;
    for (    BoatConnectedPixelMap boatpixel : detPixels.listboatneighbours) {
      if (boatpixel.containsPixel(xx,yy)) {
        checked=true;
        break;
      }
    }
    if (checked) {
      continue;
    }
    int cornerx=Math.min(Math.max(0,xx - tilesize / 2),gir.getWidth() - tilesize);
    int cornery=Math.min(Math.max(0,yy - tilesize / 2),gir.getHeight() - tilesize);
    int boatx=xx - cornerx;
    int boaty=yy - cornery;
    int numberbands=bands.length;
    int[][] data=new int[numberbands][];
    try {
      for (int bandcounter=0; bandcounter < numberbands; bandcounter++) {
        data[bandcounter]=gir.read(cornerx,cornery,tilesize,tilesize,bands[bandcounter]);
      }
    }
 catch (    IOException e) {
      logger.error(e.getMessage());
      throw e;
    }
    int row=(cornery + 1) / this.verTiles;
    int col=(cornerx + 1) / this.horTiles;
    double[][] statistics=AnalysisUtil.calculateImagemapStatistics(cornerx,cornery,tilesize,tilesize,row,col,bands,data,kdist);
    double[][] thresholdvalues=new double[numberbands][2];
    int[] maxValue=new int[numberbands];
    boolean pixelabove=false;
    for (int bandcounter=0; bandcounter < numberbands; bandcounter++) {
      double mean=(statistics[bandcounter][1] + statistics[bandcounter][2] + statistics[bandcounter][3]+ statistics[bandcounter][4]) / 4;
      thresholdvalues[bandcounter][0]=mean + 3 * mean * statistics[bandcounter][0];
      thresholdvalues[bandcounter][1]=mean + 5 * mean * statistics[bandcounter][0];
      int value=data[bandcounter][boatx + boaty * tilesize];
      if (value > thresholdvalues[bandcounter][1]) {
        pixelabove=true;
      }
      if (value > maxValue[bandcounter]) {
        maxValue[bandcounter]=data[bandcounter][boatx + boaty * tilesize];
      }
    }
    if (pixelabove) {
      Raster rastermask=null;
      if (mask != null) {
        if (mask.intersects(cornerx,cornery,tilesize,tilesize)) {
          rastermask=(mask.rasterize(cornerx,cornery,tilesize,tilesize,-cornerx,-cornery,1.0)).getData();
        }
      }
      BoatConnectedPixelMap boatpixel=new BoatConnectedPixelMap(cornerx,cornery,xx,yy,id++,data[0][boatx + boaty * tilesize]);
      for (int iBand=0; iBand < numberbands; iBand++) {
        String bb=((SarImageReader)gir).getBands()[iBand];
        float thresholdBand=this.thresholdsBandParams.get(bb);
        kdist.setImageData(cornerx,cornery,tilesize,tilesize,row,col,iBand);
        int[] newdata=gir.readTile(cornerx,cornery,tilesize,tilesize,iBand);
        kdist.estimate(rastermask,newdata);
        double[] treshTile=kdist.getDetectThresh();
        double threshTotal=treshTile[0] + treshTile[1] + treshTile[2]+ treshTile[3];
        double threshWindowsVals[]=AnalysisUtil.calcThreshWindowVals(thresholdBand,treshTile);
        double tileAvg=threshTotal / treshTile[5];
        double tileStdDev=treshTile[0] * threshTotal / treshTile[5];
        int idxBand=idxOn4Band(bb);
        boatpixel.putMeanValue(idxBand,(statistics[iBand][1] + statistics[iBand][2] + statistics[iBand][3]+ statistics[iBand][4]) / 4);
        boatpixel.putThresholdValue(idxBand,(threshWindowsVals[0] + threshWindowsVals[1] + threshWindowsVals[2]+ threshWindowsVals[3]) / 4);
        boatpixel.putMaxValue(idxBand,maxValue[iBand]);
        boatpixel.putStDevValue(idxBand,tileStdDev);
        double significance=(maxValue[iBand] - tileAvg) / tileStdDev;
        boatpixel.putSignificanceValue(idxBand,significance);
        boatpixel.putAvgValue(idxBand,tileAvg);
      }
      detPixels.listboatneighbours.add(boatpixel);
      List<int[]> boataggregatedpixels=new ArrayList<int[]>();
      int[] imagemap=new int[tilesize * tilesize];
      for (int i=0; i < tilesize * tilesize; i++) {
        imagemap[i]=0;
      }
      boolean result=detPixels.checkNeighbours(boataggregatedpixels,imagemap,data,thresholdvalues,new int[]{boatx,boaty},neighboursdistance,tilesize,rastermask);
      boatpixel.setTouchesLandMask(result);
      for (      int[] pixel : boataggregatedpixels) {
        boatpixel.addConnectedPixel(pixel[0] + cornerx,pixel[1] + cornery,pixel[2],pixel[3] == 1 ? true : false);
      }
    }
  }
  if (removelandconnectedpixels) {
    List<BoatConnectedPixelMap> toRemove=new ArrayList<BoatConnectedPixelMap>();
    for (int i=0; i < detPixels.listboatneighbours.size(); i++) {
      BoatConnectedPixelMap boat=detPixels.listboatneighbours.get(i);
      if (boat.touchesLand()) {
        toRemove.add(boat);
      }
    }
    detPixels.listboatneighbours.removeAll(toRemove);
  }
  detPixels.computeBoatsAttributesAndStatistics(detPixels.listboatneighbours);
}