Exemplo n.º 1
0
 void createNewStack(ImagePlus imp, ImageProcessor ip) {
   int nSlices = imp.getStackSize();
   int w = imp.getWidth(), h = imp.getHeight();
   ImagePlus imp2 = imp.createImagePlus();
   Rectangle r = ip.getRoi();
   boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight();
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(newWidth, newHeight);
   ImageProcessor ip1, ip2;
   int method = interpolationMethod;
   if (w == 1 || h == 1) method = ImageProcessor.NONE;
   for (int i = 1; i <= nSlices; i++) {
     IJ.showStatus("Scale: " + i + "/" + nSlices);
     ip1 = stack1.getProcessor(i);
     String label = stack1.getSliceLabel(i);
     if (crop) {
       ip1.setRoi(r);
       ip1 = ip1.crop();
     }
     ip1.setInterpolationMethod(method);
     ip2 = ip1.resize(newWidth, newHeight, averageWhenDownsizing);
     if (ip2 != null) stack2.addSlice(label, ip2);
     IJ.showProgress(i, nSlices);
   }
   imp2.setStack(title, stack2);
   Calibration cal = imp2.getCalibration();
   if (cal.scaled()) {
     cal.pixelWidth *= 1.0 / xscale;
     cal.pixelHeight *= 1.0 / yscale;
   }
   IJ.showProgress(1.0);
   int[] dim = imp.getDimensions();
   imp2.setDimensions(dim[2], dim[3], dim[4]);
   if (imp.isComposite()) {
     imp2 = new CompositeImage(imp2, ((CompositeImage) imp).getMode());
     ((CompositeImage) imp2).copyLuts(imp);
   }
   if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true);
   if (newDepth > 0 && newDepth != oldDepth)
     imp2 = (new Resizer()).zScale(imp2, newDepth, interpolationMethod);
   if (imp2 != null) {
     imp2.show();
     imp2.changes = true;
   }
 }
Exemplo n.º 2
0
 void createNewStack(ImagePlus imp, ImageProcessor ip) {
   Rectangle r = ip.getRoi();
   boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight();
   int nSlices = imp.getStackSize();
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(newWidth, newHeight);
   ImageProcessor ip1, ip2;
   boolean interp = interpolate;
   if (imp.getWidth() == 1 || imp.getHeight() == 1) interp = false;
   for (int i = 1; i <= nSlices; i++) {
     IJ.showStatus("Scale: " + i + "/" + nSlices);
     ip1 = stack1.getProcessor(i);
     String label = stack1.getSliceLabel(i);
     if (crop) {
       ip1.setRoi(r);
       ip1 = ip1.crop();
     }
     ip1.setInterpolate(interp);
     ip2 = ip1.resize(newWidth, newHeight);
     if (ip2 != null) stack2.addSlice(label, ip2);
     IJ.showProgress(i, nSlices);
   }
   ImagePlus imp2 = imp.createImagePlus();
   imp2.setStack(title, stack2);
   Calibration cal = imp2.getCalibration();
   if (cal.scaled()) {
     cal.pixelWidth *= 1.0 / xscale;
     cal.pixelHeight *= 1.0 / yscale;
   }
   int[] dim = imp.getDimensions();
   imp2.setDimensions(dim[2], dim[3], dim[4]);
   IJ.showProgress(1.0);
   if (imp.isComposite()) {
     imp2 = new CompositeImage(imp2, 0);
     ((CompositeImage) imp2).copyLuts(imp);
   }
   if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true);
   imp2.show();
   imp2.changes = true;
 }
Exemplo n.º 3
0
  /** Opens the image. Displays it if 'show' is true. Returns an ImagePlus object if successful. */
  public ImagePlus open(boolean show) {
    ImagePlus imp = null;
    Object pixels;
    ProgressBar pb = null;
    ImageProcessor ip;

    ColorModel cm = createColorModel(fi);
    if (fi.nImages > 1) {
      return openStack(cm, show);
    }
    switch (fi.fileType) {
      case FileInfo.GRAY8:
      case FileInfo.COLOR8:
      case FileInfo.BITMAP:
        pixels = readPixels(fi);
        if (pixels == null) return null;
        ip = new ByteProcessor(width, height, (byte[]) pixels, cm);
        imp = new ImagePlus(fi.fileName, ip);
        break;
      case FileInfo.GRAY16_SIGNED:
      case FileInfo.GRAY16_UNSIGNED:
      case FileInfo.GRAY12_UNSIGNED:
        pixels = readPixels(fi);
        if (pixels == null) return null;
        ip = new ShortProcessor(width, height, (short[]) pixels, cm);
        imp = new ImagePlus(fi.fileName, ip);
        break;
      case FileInfo.GRAY32_INT:
      case FileInfo.GRAY32_UNSIGNED:
      case FileInfo.GRAY32_FLOAT:
      case FileInfo.GRAY24_UNSIGNED:
      case FileInfo.GRAY64_FLOAT:
        pixels = readPixels(fi);
        if (pixels == null) return null;
        ip = new FloatProcessor(width, height, (float[]) pixels, cm);
        imp = new ImagePlus(fi.fileName, ip);
        break;
      case FileInfo.RGB:
      case FileInfo.BGR:
      case FileInfo.ARGB:
      case FileInfo.ABGR:
      case FileInfo.BARG:
      case FileInfo.RGB_PLANAR:
        pixels = readPixels(fi);
        if (pixels == null) return null;
        ip = new ColorProcessor(width, height, (int[]) pixels);
        imp = new ImagePlus(fi.fileName, ip);
        break;
      case FileInfo.RGB48:
      case FileInfo.RGB48_PLANAR:
        boolean planar = fi.fileType == FileInfo.RGB48_PLANAR;
        Object[] pixelArray = (Object[]) readPixels(fi);
        if (pixelArray == null) return null;
        ImageStack stack = new ImageStack(width, height);
        stack.addSlice("Red", pixelArray[0]);
        stack.addSlice("Green", pixelArray[1]);
        stack.addSlice("Blue", pixelArray[2]);
        imp = new ImagePlus(fi.fileName, stack);
        imp.setDimensions(3, 1, 1);
        if (planar) imp.getProcessor().resetMinAndMax();
        imp.setFileInfo(fi);
        int mode = CompositeImage.COMPOSITE;
        if (fi.description != null) {
          if (fi.description.indexOf("mode=color") != -1) mode = CompositeImage.COLOR;
          else if (fi.description.indexOf("mode=gray") != -1) mode = CompositeImage.GRAYSCALE;
        }
        imp = new CompositeImage(imp, mode);
        if (!planar && fi.displayRanges == null) {
          for (int c = 1; c <= 3; c++) {
            imp.setPosition(c, 1, 1);
            imp.setDisplayRange(minValue, maxValue);
          }
          imp.setPosition(1, 1, 1);
        }
        break;
    }
    imp.setFileInfo(fi);
    setCalibration(imp);
    if (fi.info != null) imp.setProperty("Info", fi.info);
    if (fi.sliceLabels != null && fi.sliceLabels.length == 1 && fi.sliceLabels[0] != null)
      imp.setProperty("Label", fi.sliceLabels[0]);
    if (show) imp.show();
    return imp;
  }
Exemplo n.º 4
0
  void setCalibration(ImagePlus imp) {
    if (fi.fileType == FileInfo.GRAY16_SIGNED) {
      if (IJ.debugMode) IJ.log("16-bit signed");
      double[] coeff = new double[2];
      coeff[0] = -32768.0;
      coeff[1] = 1.0;
      imp.getLocalCalibration().setFunction(Calibration.STRAIGHT_LINE, coeff, "gray value");
    }

    Properties props = decodeDescriptionString(fi);
    Calibration cal = imp.getCalibration();
    boolean calibrated = false;
    if (fi.pixelWidth > 0.0 && fi.unit != null) {
      cal.pixelWidth = fi.pixelWidth;
      cal.pixelHeight = fi.pixelHeight;
      cal.pixelDepth = fi.pixelDepth;
      cal.setUnit(fi.unit);
      calibrated = true;
    }

    if (fi.valueUnit != null) {
      int f = fi.calibrationFunction;
      if ((f >= Calibration.STRAIGHT_LINE && f <= Calibration.RODBARD2 && fi.coefficients != null)
          || f == Calibration.UNCALIBRATED_OD) {
        boolean zeroClip = props != null && props.getProperty("zeroclip", "false").equals("true");
        cal.setFunction(f, fi.coefficients, fi.valueUnit, zeroClip);
        calibrated = true;
      }
    }

    if (calibrated) checkForCalibrationConflict(imp, cal);

    if (fi.frameInterval != 0.0) cal.frameInterval = fi.frameInterval;

    if (props == null) return;

    cal.xOrigin = getDouble(props, "xorigin");
    cal.yOrigin = getDouble(props, "yorigin");
    cal.zOrigin = getDouble(props, "zorigin");
    cal.info = props.getProperty("info");

    cal.fps = getDouble(props, "fps");
    cal.loop = getBoolean(props, "loop");
    cal.frameInterval = getDouble(props, "finterval");
    cal.setTimeUnit(props.getProperty("tunit", "sec"));

    double displayMin = getDouble(props, "min");
    double displayMax = getDouble(props, "max");
    if (!(displayMin == 0.0 && displayMax == 0.0)) {
      int type = imp.getType();
      ImageProcessor ip = imp.getProcessor();
      if (type == ImagePlus.GRAY8 || type == ImagePlus.COLOR_256)
        ip.setMinAndMax(displayMin, displayMax);
      else if (type == ImagePlus.GRAY16 || type == ImagePlus.GRAY32) {
        if (ip.getMin() != displayMin || ip.getMax() != displayMax)
          ip.setMinAndMax(displayMin, displayMax);
      }
    }

    int stackSize = imp.getStackSize();
    if (stackSize > 1) {
      int channels = (int) getDouble(props, "channels");
      int slices = (int) getDouble(props, "slices");
      int frames = (int) getDouble(props, "frames");
      if (channels == 0) channels = 1;
      if (slices == 0) slices = 1;
      if (frames == 0) frames = 1;
      // IJ.log("setCalibration: "+channels+"  "+slices+"  "+frames);
      if (channels * slices * frames == stackSize) {
        imp.setDimensions(channels, slices, frames);
        if (getBoolean(props, "hyperstack")) imp.setOpenAsHyperStack(true);
      }
    }
  }
Exemplo n.º 5
0
  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();
  }