Esempio n. 1
0
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    if (imp == null) {
      IJ.noImage();
      return;
    }

    ImageStack stack1 = imp.getStack();
    String fileName = imp.getTitle();
    int endslice = stack1.getSize();

    ImagePlus imp2 = duplicateStack(imp);
    imp2.show();
    String duplicateName = imp2.getTitle();
    // IJ.showMessage("Box",fileName);
    ImageStack stack2 = imp2.getStack();
    stack1.deleteSlice(1);
    stack2.deleteSlice(endslice);

    String calculatorstring =
        ("image1='"
            + fileName
            + "' operation=Subtract image2="
            + imp2.getTitle()
            + " create stack");

    IJ.run("Image Calculator...", calculatorstring);
    ImagePlus imp3 = WindowManager.getCurrentImage();
    imp3.setTitle(fileName + " DeltaF up");
    imp2.getWindow().close();
    imp.getWindow().close();
  }
 /**
  * Splits the specified RGB stack into three 8-bit grayscale stacks. Deletes the source stack if
  * keepSource is false.
  */
 public static ImageStack[] splitRGB(ImageStack rgb, boolean keepSource) {
   int w = rgb.getWidth();
   int h = rgb.getHeight();
   ImageStack[] channels = new ImageStack[3];
   for (int i = 0; i < 3; i++) channels[i] = new ImageStack(w, h);
   byte[] r, g, b;
   ColorProcessor cp;
   int slice = 1;
   int inc = keepSource ? 1 : 0;
   int n = rgb.getSize();
   for (int i = 1; i <= n; i++) {
     IJ.showStatus(i + "/" + n);
     r = new byte[w * h];
     g = new byte[w * h];
     b = new byte[w * h];
     cp = (ColorProcessor) rgb.getProcessor(slice);
     slice += inc;
     cp.getRGB(r, g, b);
     if (!keepSource) rgb.deleteSlice(1);
     channels[0].addSlice(null, r);
     channels[1].addSlice(null, g);
     channels[2].addSlice(null, b);
     IJ.showProgress((double) i / n);
   }
   return channels;
 }
Esempio n. 3
0
  /* Replaces all sample index in imp with neighbor sample*/
  public static ImagePlus ReplaceSlices(ImagePlus imp, ArrayList<Integer> samples) {
    ImageStack ims = imp.getStack();
    Iterator itr = samples.iterator();
    while (itr.hasNext()) {
      Integer k = (Integer) itr.next();
      if (k == 0) {
        continue;
      }
      ImageProcessor ip_slice = ims.getProcessor(k);
      //            double value_1 = getMeanOfSlice(ims.getProcessor(k-1));
      //            double value_2 = getMeanOfSlice(ims.getProcessor(k));
      //            double value_3 = getMeanOfSlice(ims.getProcessor(k+1));
      //            double value_4 = getMeanOfSlice(ims.getProcessor(k+2));

      // System.out.print("Replacing "+ value_ori+"with " +value_re );
      ims.addSlice("", ip_slice, k);
      ims.deleteSlice(k + 2);
    }
    imp.setStack(ims);
    return imp;
  }
 /** Deletes the last slice in the stack. */
 public void deleteLastSlice() {
   if (nSlices > 0) deleteSlice(nSlices);
 }
Esempio n. 5
0
  /* Methods */
  public void run(String argv) {
    if (this.setup()) { // validates conditions
      IJ.showStatus(" Dark noise removal...");
      imp_r = DarkNoiseRemoval(imp_r, NOISE_ROI);
      if (removeFirst) {
        ImageStack t_stack = imp_r.getStack(); // deletes first slice
        t_stack.deleteSlice(1);
        imp_r.setStack(t_stack);
      } else {
        // if first slice wasn't removed we must move the first index of the stim in binSize
        this.imp_s_index[0] -= Math.round((float) (this.dt_r / this.DT_S));
      }
      // imp_r.show();

      // get Cells by segmentation;
      IJ.showStatus(" Cell Segmentation...");
      ImagePlus avr_imp = AApSegmetator.getAverageIm(imp_r);
      AApSegmetator segmentator = new AApSegmetator(avr_imp);
      this.cells_roi = segmentator.SegmentCellsCWT();
      // this.cells_roi = segmentator.SegmentCellsML();

      // Resample stimulus
      ArrayList<Double> stim_vector = new ArrayList<>();
      if (!this.useArtifact) {
        IJ.showStatus(" Stimulus srtifact removal....");
        Stimulus_API sapi = new Stimulus_API();
        sapi.setup("", this.imp_s, this.cells_roi, 0);
        stim_vector =
            sapi.ResampleStimulus(
                this.dt_r, imp_r.getStackSize(), this.imp_s_index[0], this.imp_s_index[1]);
      } else {
        double[] var1 = Activity_Analysis.getAverageSignal(imp_r);
        Object[] var2 = Extract_Stimulus.getPeaks(var1, 1);
        TimeSeries var3 = Extract_Stimulus.getStimulusArray(var2, imp_r.getStackSize());
        for (int i = 0; i < var3.Signal.length; i++) {
          stim_vector.add(var3.Signal[i]);
        }
      }

      // Remove stimulus slices
      ArrayList<Integer> stim_sampels = new ArrayList<>();
      for (int i = 0; i < stim_vector.size(); i++) {
        if (stim_vector.get(i) > 0) stim_sampels.add(i);
      }
      this.imp_r = ReplaceSlices(this.imp_r, stim_sampels);
      //            this.imp_r.show();
      //            IJ.run("In [+]", "");
      //            IJ.run("In [+]", "");

      // Kalman filter
      ImageStack ims = imp_r.getStack();
      Kalman_Stack_Filter kl = new Kalman_Stack_Filter();
      kl.filter(ims, this.KL_PRECVAR, this.KM_GAIN);
      imp_r.setStack(ims);

      // wrap everything with the Cell manager
      this.cm = toCellManager(this.imp_r, this.cells_roi, avr_imp);

      System.out.print("Success!!");
    }

    // run local method

  }