/**
  * Creates a new FloatProcessor using the specified FloatProcessor. Set 'cm' to null to use the
  * default grayscale LUT.
  */
 public SerializableFloatProcessor(FloatProcessor floatProcessor) {
   floatProcessor = (FloatProcessor) floatProcessor.duplicate();
   this.width = floatProcessor.getWidth();
   this.height = floatProcessor.getHeight();
   this.pixels = (float[]) floatProcessor.getPixels();
   this.cm = floatProcessor.getColorModel();
   resetRoi();
   if (pixels != null) findMinAndMax();
 }
Esempio n. 2
0
  void SMLblur1Direction(
      final FloatProcessor ippp,
      final double sigma,
      final double accuracy,
      final boolean xDirection,
      final int extraLines) {

    final float[] pixels = (float[]) ippp.getPixels();
    final int width = ippp.getWidth();
    final int height = ippp.getHeight();
    final int length =
        xDirection ? width : height; // number of points per line (line can be a row or column)
    final int pointInc =
        xDirection ? 1 : width; // increment of the pixels array index to the next poin a line
    final int lineInc =
        xDirection ? width : 1; // increment of the pixels array index to the next line
    final int lineFromA = 0 - extraLines; // the first line to process
    final int lineFrom;
    if (lineFromA < 0) lineFrom = 0;
    else lineFrom = lineFromA;
    final int lineToA = (xDirection ? height : width) + extraLines; // the last line+1 to process
    final int lineTo;
    if (lineToA > (xDirection ? height : width)) lineTo = (xDirection ? height : width);
    else lineTo = lineToA;
    final int writeFrom = 0; // first point of a line that needs to be written
    final int writeTo = xDirection ? width : height;

    final float[][] gaussKernel = lowpassGauss.makeGaussianKernel(sigma, accuracy, length);
    final int kRadius = gaussKernel[0].length; // Gaussian kernel radius after upscaling
    final int readFrom =
        (writeFrom - kRadius < 0)
            ? 0
            : writeFrom - kRadius; // not including broadening by downscale&upscale
    final int readTo = (writeTo + kRadius > length) ? length : writeTo + kRadius;
    final int newLength = length;

    final float[] cache1 =
        new float[newLength]; // holds data before convolution (after downscaling, if any)

    int pixel0 = 0;
    for (int line = lineFrom; line < lineTo; line++, pixel0 += lineInc) {
      int p = pixel0 + readFrom * pointInc;
      for (int i = readFrom; i < readTo; i++, p += pointInc) cache1[i] = pixels[p];
      SMLconvolveLine(
          cache1, pixels, gaussKernel, readFrom, readTo, writeFrom, writeTo, pixel0, pointInc);
    }

    return;
  }
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    Calibration cal = imp.getCalibration();
    GenericDialog gd = new GenericDialog("Options");
    int subsize = 32;
    gd.addNumericField("Subregion Size (pixels)?", subsize, 0);
    int stepsize = 16;
    gd.addNumericField("Step Size?", stepsize, 0);
    int shift = 3;
    gd.addNumericField("STICS temporal Shift?", shift, 0);
    float xoffset = 0.0f;
    gd.addNumericField("X_Offset", xoffset, 5, 15, null);
    float yoffset = 0.0f;
    gd.addNumericField("Y_Offset", yoffset, 5, 15, null);
    float multiplier = 8.0f;
    gd.addNumericField("Velocity Multiplier", multiplier, 5, 15, null);
    float ftime = 1.0f;
    gd.addNumericField("Frame_Time(min)", ftime, 5, 15, null);
    float scaling = (float) cal.pixelWidth;
    gd.addNumericField("Pixel_Size(um)", scaling, 5, 15, null);
    boolean norm = true;
    gd.addCheckbox("Normalize_Vector_lengths?", norm);
    boolean centered = true;
    gd.addCheckbox("Center_Vectors?", centered);
    float magthresh = 0.0f;
    gd.addNumericField("Magnitude_Threshhold?", magthresh, 5, 15, null);
    int rlength = 10;
    gd.addNumericField("Running_avg_length", rlength, 0);
    int inc = 5;
    gd.addNumericField("Start_frame_increment", inc, 0);
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    subsize = (int) gd.getNextNumber();
    stepsize = (int) gd.getNextNumber();
    shift = (int) gd.getNextNumber();
    xoffset = (float) gd.getNextNumber();
    yoffset = (float) gd.getNextNumber();
    multiplier = (float) gd.getNextNumber();
    ftime = (float) gd.getNextNumber();
    scaling = (float) gd.getNextNumber();
    norm = gd.getNextBoolean();
    centered = gd.getNextBoolean();
    magthresh = (float) gd.getNextNumber();
    rlength = (int) gd.getNextNumber();
    inc = (int) gd.getNextNumber();

    int width = imp.getWidth();
    int xregions = 1 + (int) (((float) width - (float) subsize) / (float) stepsize);
    int newwidth = xregions * subsize;
    int height = imp.getHeight();
    int yregions = 1 + (int) (((float) height - (float) subsize) / (float) stepsize);
    int newheight = yregions * subsize;
    ImageStack stack = imp.getStack();
    int slices = imp.getNSlices();
    int channels = imp.getNChannels();
    int frames = imp.getNFrames();
    if (frames == 1) {
      frames = slices;
      slices = 1;
    }

    Roi roi = imp.getRoi();
    if (roi == null) {
      roi = new Roi(0, 0, width, height);
    }

    STICS_map map = new STICS_map(subsize, stepsize);
    Object[] tseries = jutils.get3DTSeries(stack, 0, 0, frames, slices, channels);
    map.update_STICS_map(tseries, width, height, 0, rlength, roi.getPolygon(), shift);
    FloatProcessor fp =
        map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh);
    ImageStack vector_stack = new ImageStack(fp.getWidth(), fp.getHeight());
    vector_stack.addSlice("", fp);
    float[][] vel = map.get_scaled_velocities(scaling, ftime, stepsize);
    ImageStack velstack = new ImageStack(map.xregions, map.yregions);
    velstack.addSlice("", vel[0]);
    velstack.addSlice("", vel[1]);
    int velframes = 2;
    IJ.showStatus("frame " + 0 + " calculated");
    for (int i = inc; i < (frames - rlength); i += inc) {
      map.update_STICS_map(tseries, width, height, i, rlength, roi.getPolygon(), shift);
      FloatProcessor fp2 =
          map.get_map(scaling, ftime, stepsize, centered, norm, multiplier, stepsize, magthresh);
      vector_stack.addSlice("", fp2);
      vel = map.get_scaled_velocities(scaling, ftime, stepsize);
      velstack.addSlice("", vel[0]);
      velstack.addSlice("", vel[1]);
      velframes += 2;
      IJ.showStatus("frame " + i + " calculated");
    }
    (new ImagePlus("STICS Vectors", vector_stack)).show();
    ImagePlus imp3 = new ImagePlus("Velocities", velstack);
    imp3.setOpenAsHyperStack(true);
    imp3.setDimensions(2, 1, velframes / 2);
    new CompositeImage(imp3, CompositeImage.COLOR).show();
  }