Program: 175091
Project: 175091
Buggy source:
/** 
 * @param kdist
 * @param thresholdBandParams
 * @return
 * @throws IOException
 */
public DetectedPixels analyse(final KDistributionEstimation kdist,final int band) throws IOException {
  DetectedPixels dpixels=new DetectedPixels(gir.getRangeSpacing(),gir.getAzimuthSpacing());
  String bb=((SarImageReader)gir).getBands()[band];
  float thresholdBand=this.thresholdsBandParams.get(bb);
  int xLeftTile=0;
  int xRightTile=0;
  int yTopTile=0;
  int yBottomTile=0;
  double[][][] tileStat=new double[verTilesImage][horTilesImage][5];
  int dy=0;
  for (int rowIndex=0; rowIndex < verTilesImage; rowIndex++) {
    if (isAnalyseSingleTile()) {
      if (rowIndex != yTileToAnalyze)       continue;
    }
    notifyStartNextRowProcessing(rowIndex);
    if (rowIndex == verTilesImage - 1) {
      dy=gir.getHeight() - ((verTilesImage - 1) * realSizeY) - realSizeY;
    }
    xLeftTile=0;
    xRightTile=0;
    yTopTile=rowIndex * realSizeY;
    yBottomTile=yTopTile + realSizeY + dy;
    int dx=0;
    for (int colIndex=0; colIndex < horTilesImage; colIndex++) {
      if (isAnalyseSingleTile()) {
        if (colIndex != xTileToAnalyze)         continue;
      }
      if (colIndex == horTilesImage - 1) {
        dx=(gir.getWidth() - ((horTilesImage - 1) * realSizeX)) - realSizeX;
      }
      xLeftTile=colIndex * realSizeX;
      xRightTile=xLeftTile + realSizeX + dx;
      boolean containsMinPixelValid=false;
      int[] maskdata=null;
      if (coastMask == null || !intersects(xLeftTile,xRightTile,yTopTile,yBottomTile)) {
        maskdata=null;
      }
 else {
        if (includes(xLeftTile,xRightTile,yTopTile,yBottomTile))         continue;
        maskdata=createDataMask(xLeftTile,yTopTile,realSizeX,realSizeY,dx,dy);
        int inValidPixelCount=0;
        for (int count=0; count < maskdata.length; count++)         inValidPixelCount+=maskdata[count];
        containsMinPixelValid=((double)inValidPixelCount / maskdata.length) <= MIN_TRESH_FOR_ANALYSIS;
        if (!containsMinPixelValid) {
          maskdata=createDataMask(xLeftTile - 30,yTopTile - 30,realSizeX + 30,realSizeY + 30,dx,dy);
          inValidPixelCount=0;
          for (int count=0; count < maskdata.length; count++)           inValidPixelCount+=maskdata[count];
          containsMinPixelValid=((double)inValidPixelCount / maskdata.length) <= MIN_TRESH_FOR_ANALYSIS;
        }
      }
      if (containsMinPixelValid || maskdata == null) {
        TileAnalysis bbAnalysis=null;
        if (blackBorderAnalysis != null)         bbAnalysis=blackBorderAnalysis.getAnalysisTile(rowIndex,colIndex);
        int[] data=gir.readTile(xLeftTile,yTopTile,realSizeX + dx,realSizeY + dy,band);
        kdist.setImageData(xLeftTile,yTopTile,realSizeX + dx,realSizeY + dy,band,bbAnalysis);
        kdist.estimate(maskdata,data);
        double[] thresh=kdist.getDetectThresh();
        tileStat[rowIndex][0]=kdist.getTileStat();
        double threshWindowsVals[]=AnalysisUtil.calcThreshWindowVals(thresholdBand,thresh);
        for (int k=0; k < (realSizeY + dy); k++) {
          for (int h=0; h < (realSizeX + dx); h++) {
            if (maskdata == null || (maskdata[h + ((realSizeX + dx) * k)] == 0)) {
              int subwindow=1;
              if (h < (realSizeX + dx) / 2) {
                if (k < (realSizeY + dy) / 2) {
                  subwindow=1;
                }
 else {
                  subwindow=3;
                }
              }
 else {
                if (k < (realSizeY + dy) / 2) {
                  subwindow=2;
                }
 else {
                  subwindow=4;
                }
              }
              int pix=data[k * (realSizeX + dx) + h];
              if (pix > threshWindowsVals[subwindow - 1]) {
                double tileAvg=thresh[subwindow] / thresh[5];
                double tileStdDev=thresh[0] * thresh[subwindow] / thresh[5];
                dpixels.add(h + xLeftTile,k + yTopTile,pix,tileAvg,tileStdDev,thresh[5],band);
              }
            }
          }
        }
      }
    }
    System.out.println(rowIndex + "String_Node_Str" + verTilesImage);
  }
  System.out.println("String_Node_Str" + dpixels.getAllDetectedPixels().size());
  return dpixels;
}

Fixed version (ground truth):
/** 
 * @param kdist
 * @param thresholdBandParams
 * @return
 * @throws IOException
 */
public DetectedPixels analyse(final KDistributionEstimation kdist,final int band) throws IOException {
  DetectedPixels dpixels=new DetectedPixels(gir.getRangeSpacing(),gir.getAzimuthSpacing());
  String bb=((SarImageReader)gir).getBands()[band];
  float thresholdBand=this.thresholdsBandParams.get(bb);
  int xLeftTile=0;
  int xRightTile=0;
  int yTopTile=0;
  int yBottomTile=0;
  double[][][] tileStat=new double[verTilesImage][horTilesImage][5];
  int dy=0;
  for (int rowIndex=0; rowIndex < verTilesImage; rowIndex++) {
    if (isAnalyseSingleTile()) {
      if (rowIndex != yTileToAnalyze)       continue;
    }
    notifyStartNextRowProcessing(rowIndex);
    if (rowIndex == verTilesImage - 1) {
      dy=gir.getHeight() - ((verTilesImage - 1) * realSizeY) - realSizeY;
    }
    xLeftTile=0;
    xRightTile=0;
    yTopTile=rowIndex * realSizeY;
    yBottomTile=yTopTile + realSizeY + dy;
    int dx=0;
    for (int colIndex=0; colIndex < horTilesImage; colIndex++) {
      if (isAnalyseSingleTile()) {
        if (colIndex != xTileToAnalyze)         continue;
      }
      if (colIndex == horTilesImage - 1) {
        dx=(gir.getWidth() - ((horTilesImage - 1) * realSizeX)) - realSizeX;
      }
      xLeftTile=colIndex * realSizeX;
      xRightTile=xLeftTile + realSizeX + dx;
      boolean containsMinPixelValid=false;
      int[] maskdata=null;
      int[] enlargedMaskData=null;
      int offsetEnlarge=30;
      if (coastMask == null || !intersects(xLeftTile,xRightTile,yTopTile,yBottomTile)) {
        maskdata=null;
      }
 else {
        if (includes(xLeftTile,xRightTile,yTopTile,yBottomTile))         continue;
        maskdata=createDataMask(xLeftTile,yTopTile,realSizeX,realSizeY,dx,dy);
        int inValidPixelCount=0;
        for (int count=0; count < maskdata.length; count++)         inValidPixelCount+=maskdata[count];
        containsMinPixelValid=((double)inValidPixelCount / maskdata.length) <= MIN_TRESH_FOR_ANALYSIS;
        if (!containsMinPixelValid) {
          enlargedMaskData=createDataMask(xLeftTile - offsetEnlarge,yTopTile - offsetEnlarge,realSizeX + offsetEnlarge,realSizeY + offsetEnlarge,dx,dy);
          inValidPixelCount=0;
          for (int count=0; count < enlargedMaskData.length; count++)           inValidPixelCount+=enlargedMaskData[count];
          containsMinPixelValid=((double)inValidPixelCount / enlargedMaskData.length) <= MIN_TRESH_FOR_ANALYSIS;
        }
      }
      if (containsMinPixelValid || maskdata == null) {
        TileAnalysis bbAnalysis=null;
        if (blackBorderAnalysis != null)         bbAnalysis=blackBorderAnalysis.getAnalysisTile(rowIndex,colIndex);
        int[] data=gir.readTile(xLeftTile,yTopTile,realSizeX + dx,realSizeY + dy,band);
        if (enlargedMaskData == null) {
          kdist.setImageData(xLeftTile,yTopTile,realSizeX + dx,realSizeY + dy,band,bbAnalysis);
          kdist.estimate(maskdata,data);
        }
 else {
          int[] dataEn=gir.readTile(xLeftTile - offsetEnlarge,yTopTile - offsetEnlarge,realSizeX + dx + offsetEnlarge,realSizeY + dy + offsetEnlarge,band);
          kdist.setImageData(xLeftTile - offsetEnlarge,yTopTile - offsetEnlarge,realSizeX + offsetEnlarge + dx,realSizeY + offsetEnlarge + dy,band,bbAnalysis);
          kdist.estimate(enlargedMaskData,dataEn);
        }
        double[] thresh=kdist.getDetectThresh();
        tileStat[rowIndex][0]=kdist.getTileStat();
        double threshWindowsVals[]=AnalysisUtil.calcThreshWindowVals(thresholdBand,thresh);
        for (int k=0; k < (realSizeY + dy); k++) {
          for (int h=0; h < (realSizeX + dx); h++) {
            if (maskdata == null || (maskdata[h + ((realSizeX + dx) * k)] == 0)) {
              int subwindow=1;
              if (h < (realSizeX + dx) / 2) {
                if (k < (realSizeY + dy) / 2) {
                  subwindow=1;
                }
 else {
                  subwindow=3;
                }
              }
 else {
                if (k < (realSizeY + dy) / 2) {
                  subwindow=2;
                }
 else {
                  subwindow=4;
                }
              }
              int pix=data[k * (realSizeX + dx) + h];
              if (pix > threshWindowsVals[subwindow - 1]) {
                double tileAvg=thresh[subwindow] / thresh[5];
                double tileStdDev=thresh[0] * thresh[subwindow] / thresh[5];
                dpixels.add(h + xLeftTile,k + yTopTile,pix,tileAvg,tileStdDev,thresh[5],band);
              }
            }
          }
        }
      }
    }
    System.out.println(rowIndex + "String_Node_Str" + verTilesImage);
  }
  System.out.println("String_Node_Str" + dpixels.getAllDetectedPixels().size());
  return dpixels;
}