Program: 175044
Project: 175044
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,MaskGeometries mask,KDistributionEstimation kdist) throws IOException {
  int id=0;
  DetectedPixels.BoatPixel pixels[]=detPixels.getAllDetectedPixelsValues().toArray(new DetectedPixels.BoatPixel[0]);
  int count=0;
  for (  DetectedPixels.BoatPixel detectedPix : pixels) {
    count++;
    int xx=detectedPix.x;
    int yy=detectedPix.y;
    if ((count % 100) == 0) {
      if (logger.isInfoEnabled())       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][];
    for (int bandcounter=0; bandcounter < numberbands; bandcounter++) {
      data[bandcounter]=gir.read(cornerx,cornery,tilesize,tilesize,bands[bandcounter]);
    }
    int row=(cornery + 1) / this.verTilesImage;
    int col=(cornerx + 1) / this.horTilesImage;
    TileAnalysis ta=null;
    if (this.blackBorderAnalysis != null)     ta=this.blackBorderAnalysis.getAnalysisTile(row,col);
    double[][] statistics=AnalysisUtil.calculateImagemapStatistics(cornerx,cornery,tilesize,tilesize,row,col,bands,data,kdist,ta);
    double[][] thresholdvalues=new double[numberbands][2];
    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 (pixelabove) {
      int[] dataMask=createDataMask(cornerx,cornery,tilesize,tilesize,0,0);
      BoatConnectedPixelMap boatpixel=null;
      try {
        boatpixel=new BoatConnectedPixelMap(cornerx,cornery,xx,yy,id++,data[0][boatx + boaty * tilesize]);
      }
 catch (      Exception e) {
        boatpixel=new BoatConnectedPixelMap(cornerx,cornery,xx,yy,id++,data[0][(boatx + boaty * tilesize) - 1]);
      }
      for (int iBand=0; iBand < numberbands; iBand++) {
        String bb=gir.getBandName(bands[iBand]);
        float thresholdBand=this.thresholdsBandParams.get(bb);
        TileAnalysis bbAnalysis=null;
        if (blackBorderAnalysis != null)         bbAnalysis=blackBorderAnalysis.getAnalysisTile(row,col);
        kdist.setImageData(cornerx,cornery,tilesize,tilesize,iBand,bbAnalysis);
        int[] newdata=gir.read(cornerx,cornery,tilesize,tilesize,bands[iBand]);
        kdist.estimate(newdata,newdata);
        double[] treshTile=kdist.getDetectThresh();
        double threshTotal=treshTile[0] + treshTile[1] + treshTile[2]+ treshTile[3];
        double threshWindowsVals[]=AnalysisUtil.calcThreshWindowVals(thresholdBand,treshTile);
        double tileAvg=0;
        int i=0;
        int y=-1;
        for (; i < data[iBand].length; i++) {
          int x=i % 200;
          if (x == 0)           y++;
          try {
            if (dataMask == null || dataMask[x + (y * tilesize)] == 0) {
              tileAvg=tileAvg + data[iBand][i];
            }
          }
 catch (          Exception e) {
            logger.warn(new StringBuilder(e.getMessage()).append("String_Node_Str").append(x).append("String_Node_Str").append(y).append("String_Node_Str").toString());
          }
        }
        tileAvg=tileAvg / i;
        double tileStdDev=treshTile[0] * threshTotal / treshTile[5];
        boatpixel.getStatMap().setTreshold(Precision.round((threshWindowsVals[0] + threshWindowsVals[1] + threshWindowsVals[2]+ threshWindowsVals[3]) / 4,3),bb);
        boatpixel.getStatMap().setTileStd(Precision.round(tileStdDev,3),bb);
        boatpixel.getStatMap().setTileAvg(Precision.round(tileAvg,3),bb);
      }
      detPixels.listboatneighbours.add(boatpixel);
      List<int[]> boataggregatedpixels=new ArrayList<int[]>();
      boolean result=detPixels.checkNeighbours(boataggregatedpixels,data,thresholdvalues,new int[]{boatx,boaty},neighboursdistance,tilesize,dataMask);
      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);
  }
}

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,MaskGeometries mask,KDistributionEstimation kdist) throws IOException {
  int id=0;
  DetectedPixels.BoatPixel pixels[]=detPixels.getAllDetectedPixelsValues().toArray(new DetectedPixels.BoatPixel[0]);
  int count=0;
  for (  DetectedPixels.BoatPixel detectedPix : pixels) {
    count++;
    int xx=detectedPix.x;
    int yy=detectedPix.y;
    if ((count % 100) == 0) {
      if (logger.isInfoEnabled())       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][];
    for (int bandcounter=0; bandcounter < numberbands; bandcounter++) {
      data[bandcounter]=gir.read(cornerx,cornery,tilesize,tilesize,bands[bandcounter]);
    }
    int row=(cornery + 1) / this.verTilesImage;
    int col=(cornerx + 1) / this.horTilesImage;
    TileAnalysis ta=null;
    if (this.blackBorderAnalysis != null)     ta=this.blackBorderAnalysis.getAnalysisTile(row,col);
    double[][] statistics=AnalysisUtil.calculateImagemapStatistics(cornerx,cornery,tilesize,tilesize,row,col,bands,data,kdist,ta);
    double[][] thresholdvalues=new double[numberbands][2];
    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;
      }
 else {
      }
    }
    if (pixelabove) {
      int[] dataMask=createDataMask(cornerx,cornery,tilesize,tilesize,0,0);
      BoatConnectedPixelMap boatpixel=null;
      try {
        boatpixel=new BoatConnectedPixelMap(cornerx,cornery,xx,yy,id++,data[0][boatx + boaty * tilesize]);
      }
 catch (      Exception e) {
        boatpixel=new BoatConnectedPixelMap(cornerx,cornery,xx,yy,id++,data[0][(boatx + boaty * tilesize) - 1]);
      }
      for (int iBand=0; iBand < numberbands; iBand++) {
        String bb=gir.getBandName(bands[iBand]);
        float thresholdBand=this.thresholdsBandParams.get(bb);
        TileAnalysis bbAnalysis=null;
        if (blackBorderAnalysis != null)         bbAnalysis=blackBorderAnalysis.getAnalysisTile(row,col);
        kdist.setImageData(cornerx,cornery,tilesize,tilesize,iBand,bbAnalysis);
        int[] newdata=gir.read(cornerx,cornery,tilesize,tilesize,bands[iBand]);
        kdist.estimate(newdata,newdata);
        double[] treshTile=kdist.getDetectThresh();
        double threshTotal=treshTile[0] + treshTile[1] + treshTile[2]+ treshTile[3];
        double threshWindowsVals[]=AnalysisUtil.calcThreshWindowVals(thresholdBand,treshTile);
        double tileAvg=0;
        int i=0;
        int y=-1;
        for (; i < data[iBand].length; i++) {
          int x=i % tilesize;
          if (x == 0)           y++;
          try {
            if (dataMask == null || dataMask[x + (y * tilesize)] == 0) {
              tileAvg=tileAvg + data[iBand][i];
            }
          }
 catch (          Exception e) {
            logger.warn(new StringBuilder(e.getMessage()).append("String_Node_Str").append(x).append("String_Node_Str").append(y).append("String_Node_Str").toString());
          }
        }
        tileAvg=tileAvg / i;
        double tileStdDev=treshTile[0] * threshTotal / treshTile[5];
        boatpixel.getStatMap().setTreshold(Precision.round((threshWindowsVals[0] + threshWindowsVals[1] + threshWindowsVals[2]+ threshWindowsVals[3]) / 4,3),bb);
        boatpixel.getStatMap().setTileStd(Precision.round(tileStdDev,3),bb);
        boatpixel.getStatMap().setTileAvg(Precision.round(tileAvg,3),bb);
      }
      detPixels.listboatneighbours.add(boatpixel);
      List<int[]> boataggregatedpixels=new ArrayList<int[]>();
      boolean result=detPixels.checkNeighbours(boataggregatedpixels,data,thresholdvalues,new int[]{boatx,boaty},neighboursdistance,tilesize,dataMask);
      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);
  }
}