示例#1
0
  private void drawGraph(
      final double[] params, final double[] boxSizes, final double[] boxCountSums) {

    final int samples = 100;
    final float[] px = new float[samples];
    final float[] py = new float[samples];
    double[] a = Tools.getMinMax(boxSizes);
    final double xmin = a[0], xmax = a[1];

    a = Tools.getMinMax(boxCountSums);
    double ymin = a[0], ymax = a[1];
    final double inc = (xmax - xmin) / ((double) samples - 1);
    double tmp = xmin;

    for (int i = 0; i < samples; i++) {
      px[i] = (float) tmp;
      tmp += inc;
    }
    for (int i = 0; i < samples; i++) {
      py[i] = (float) CurveFitter.f(CurveFitter.STRAIGHT_LINE, params, px[i]);
    }
    a = Tools.getMinMax(py);
    ymin = Math.min(ymin, a[0]);
    ymax = Math.max(ymax, a[1]);
    final Plot plot = new Plot("Plot", "-log(box size)", "log(box count)", px, py);
    plot.setLimits(xmin, xmax * 0.9, ymin, ymax * 1.1);
    plot.draw();
    plot.addPoints(boxSizes, boxCountSums, Plot.CIRCLE);
    plot.addPoints(px, py, Plot.LINE);
    final CurveFitter cf = new CurveFitter(boxSizes, boxCountSums);
    cf.doFit(CurveFitter.STRAIGHT_LINE);
    plot.addLabel(
        0.1, 0.1, "Slope: " + IJ.d2s(params[1], 4) + "\n" + "R²: " + IJ.d2s(cf.getRSquared(), 4));
    final ImagePlus plotImage = new ImagePlus("Plot", plot.getProcessor());
    plotImage.show();
    return;
  }
示例#2
0
  public int setup(String arg, ImagePlus imp) {
    // IJ.register(Average_Oversampled.class);

    if (IJ.versionLessThan("1.32c")) return DONE;

    if (this.pre) { // before finding means

      imp.unlock();
      this.imp = imp;
      this.nslices = imp.getNSlices();
      this.width = imp.getWidth();
      this.height = imp.getHeight();
      this.slicecols = new float[nslices][width];
      this.pre = false;
      return (DOES_ALL + DOES_STACKS + FINAL_PROCESSING);

    } else { // find SD after finding means of columns
      float sum; // sum of pixel values column
      float avg; // average pixel value of a column
      double devsum; // sum of deviations
      double devavg; // standard deviation
      double[] columns = new double[width]; // x-axis of plot
      double[] sdevs = new double[width]; // y-axis of plot

      for (int i = 0; i < width; i += 1) {
        sum = 0; // reset with each column
        avg = 0; // reset with each column
        devsum = 0; // reset with each column
        devavg = 0; // reset with each column
        columns[i] = i; // building x-axis

        for (int s = 0; s < nslices; s += 1) { // sum of column means
          sum = sum + slicecols[s][i];
        }
        avg = sum / nslices; // mean of one column across all slices

        for (int s = 0; s < nslices; s += 1) { // standard deviation
          devsum = devsum + Math.pow((slicecols[s][i] - avg), 2); // square diff
        }
        devavg = Math.sqrt(devsum / nslices);

        sdevs[i] = devavg; // building y-axis
      }

      Plot plot = new Plot("Average SD by Column", "Columns", "Standard Deviation", columns, sdevs);
      plot.show();

      // calculate CTN
      double ctn;
      double sdevssum = 0;
      for (double sd : sdevs) {
        sdevssum = sdevssum + sd;
      }
      ctn = sdevssum / width;

      // display CTN on results table
      ResultsTable rt = ResultsTable.getResultsTable();
      // rt.incrementCounter();
      rt.addValue("Column Temporal Noise", ctn);
      rt.show("Results");

      this.pre = false;

      return DONE;
    }
  }