Esempio n. 1
0
 /**
  * Creates a new GenericDialog with the specified title. Uses the current image image window as
  * the parent frame or the ImageJ frame if no image windows are open. Dialog parameters are
  * recorded by ImageJ's command recorder but this requires that the first word of each label be
  * unique.
  */
 public GenericDialog(String title) {
   this(
       title,
       WindowManager.getCurrentImage() != null
           ? (Frame) WindowManager.getCurrentImage().getWindow()
           : IJ.getInstance() != null ? IJ.getInstance() : new Frame());
 }
Esempio n. 2
0
 private static Frame getParentFrame() {
   Frame parent =
       WindowManager.getCurrentImage() != null
           ? (Frame) WindowManager.getCurrentImage().getWindow()
           : IJ.getInstance() != null ? IJ.getInstance() : new Frame();
   if (IJ.isMacOSX() && IJ.isJava18()) {
     ImageJ ij = IJ.getInstance();
     if (ij != null && ij.isActive()) parent = ij;
     else parent = null;
   }
   return parent;
 }
Esempio n. 3
0
  public Channels() {
    super("Channels");
    if (instance != null) {
      instance.toFront();
      return;
    }
    WindowManager.addWindow(this);
    instance = this;
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    setLayout(gridbag);
    int y = 0;
    c.gridx = 0;
    c.gridy = y++;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    int margin = 32;
    if (IJ.isMacOSX()) margin = 20;
    c.insets = new Insets(10, margin, 10, margin);
    choice = new Choice();
    for (int i = 0; i < modes.length; i++) choice.addItem(modes[i]);
    choice.select(0);
    choice.addItemListener(this);
    add(choice, c);

    CompositeImage ci = getImage();
    int nCheckBoxes = ci != null ? ci.getNChannels() : 3;
    if (nCheckBoxes > CompositeImage.MAX_CHANNELS) nCheckBoxes = CompositeImage.MAX_CHANNELS;
    checkbox = new Checkbox[nCheckBoxes];
    for (int i = 0; i < nCheckBoxes; i++) {
      checkbox[i] = new Checkbox("Channel " + (i + 1), true);
      c.insets = new Insets(0, 25, i < nCheckBoxes - 1 ? 0 : 10, 5);
      c.gridy = y++;
      add(checkbox[i], c);
      checkbox[i].addItemListener(this);
    }

    c.insets = new Insets(0, 15, 10, 15);
    c.fill = GridBagConstraints.NONE;
    c.gridy = y++;
    moreButton = new Button(moreLabel);
    moreButton.addActionListener(this);
    add(moreButton, c);
    update();

    pm = new PopupMenu();
    for (int i = 0; i < menuItems.length; i++) addPopupItem(menuItems[i]);
    add(pm);

    addKeyListener(IJ.getInstance()); // ImageJ handles keyboard shortcuts
    setResizable(false);
    pack();
    if (location == null) {
      GUI.center(this);
      location = getLocation();
    } else setLocation(location);
    show();
  }
Esempio n. 4
0
 /**
  * Builds dialog to query users for projection parameters.
  *
  * @param start starting slice to display
  * @param stop last slice
  */
 protected GenericDialog buildControlDialog(int start, int stop) {
   GenericDialog gd = new GenericDialog("ZProjection", IJ.getInstance());
   gd.addNumericField("Start slice:", startSlice, 0 /*digits*/);
   gd.addNumericField("Stop slice:", stopSlice, 0 /*digits*/);
   gd.addChoice("Projection type", METHODS, METHODS[method]);
   if (isHyperstack && imp.getNFrames() > 1 && imp.getNSlices() > 1)
     gd.addCheckbox("All time frames", allTimeFrames);
   return gd;
 }
Esempio n. 5
0
 void addScrollbars(ImagePlus imp) {
   ImageStack s = imp.getStack();
   int stackSize = s.getSize();
   nSlices = stackSize;
   hyperStack = imp.getOpenAsHyperStack();
   // imp.setOpenAsHyperStack(false);
   int[] dim = imp.getDimensions();
   int nDimensions = 2 + (dim[2] > 1 ? 1 : 0) + (dim[3] > 1 ? 1 : 0) + (dim[4] > 1 ? 1 : 0);
   if (nDimensions <= 3 && dim[2] != nSlices) hyperStack = false;
   if (hyperStack) {
     nChannels = dim[2];
     nSlices = dim[3];
     nFrames = dim[4];
   }
   // IJ.log("StackWindow: "+hyperStack+" "+nChannels+" "+nSlices+" "+nFrames);
   if (nSlices == stackSize) hyperStack = false;
   if (nChannels * nSlices * nFrames != stackSize) hyperStack = false;
   if (cSelector != null || zSelector != null || tSelector != null) removeScrollbars();
   ImageJ ij = IJ.getInstance();
   if (nChannels > 1) {
     cSelector = new ScrollbarWithLabel(this, 1, 1, 1, nChannels + 1, 'c');
     add(cSelector);
     if (ij != null) cSelector.addKeyListener(ij);
     cSelector.addAdjustmentListener(this);
     cSelector.setFocusable(false); // prevents scroll bar from blinking on Windows
     cSelector.setUnitIncrement(1);
     cSelector.setBlockIncrement(1);
   }
   if (nSlices > 1) {
     char label = nChannels > 1 || nFrames > 1 ? 'z' : 't';
     if (stackSize == dim[2] && imp.isComposite()) label = 'c';
     zSelector = new ScrollbarWithLabel(this, 1, 1, 1, nSlices + 1, label);
     if (label == 't') animationSelector = zSelector;
     add(zSelector);
     if (ij != null) zSelector.addKeyListener(ij);
     zSelector.addAdjustmentListener(this);
     zSelector.setFocusable(false);
     int blockIncrement = nSlices / 10;
     if (blockIncrement < 1) blockIncrement = 1;
     zSelector.setUnitIncrement(1);
     zSelector.setBlockIncrement(blockIncrement);
     sliceSelector = zSelector.bar;
   }
   if (nFrames > 1) {
     animationSelector = tSelector = new ScrollbarWithLabel(this, 1, 1, 1, nFrames + 1, 't');
     add(tSelector);
     if (ij != null) tSelector.addKeyListener(ij);
     tSelector.addAdjustmentListener(this);
     tSelector.setFocusable(false);
     int blockIncrement = nFrames / 10;
     if (blockIncrement < 1) blockIncrement = 1;
     tSelector.setUnitIncrement(1);
     tSelector.setBlockIncrement(blockIncrement);
   }
 }
 public PlugInDialog(String title) {
   super(IJ.isMacOSX() ? IJ.getInstance() : IJ.isJava16() ? null : new Frame(), title);
   enableEvents(AWTEvent.WINDOW_EVENT_MASK);
   this.title = title;
   ImageJ ij = IJ.getInstance();
   if (IJ.isMacOSX() && ij != null) {
     ij.toFront(); // needed for keyboard shortcuts to work
     IJ.wait(250);
   }
   addWindowListener(this);
   addFocusListener(this);
   if (IJ.isLinux()) setBackground(ImageJ.backgroundColor);
   if (ij != null && !IJ.isMacOSX() && IJ.isJava16()) {
     Image img = ij.getIconImage();
     if (img != null)
       try {
         setIconImage(img);
       } catch (Exception e) {
       }
   }
 }
Esempio n. 7
0
 public ImageCanvas(ImagePlus imp) {
   this.imp = imp;
   ij = IJ.getInstance();
   int width = imp.getWidth();
   int height = imp.getHeight();
   imageWidth = width;
   imageHeight = height;
   srcRect = new Rectangle(0, 0, imageWidth, imageHeight);
   setDrawingSize(imageWidth, (int) (imageHeight));
   magnification = 1.0;
   addMouseListener(this);
   addMouseMotionListener(this);
   addKeyListener(ij); // ImageJ handles keyboard shortcuts
   setFocusTraversalKeysEnabled(false);
 }
Esempio n. 8
0
  public void run(String arg) {
    GenericDialog gd = new GenericDialog("Options");
    double sfreq = 20000.0;
    gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null);
    String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"};
    gd.addChoice("PSF Type?", psfchoice, psfchoice[0]);
    String[] filetypechoice = {
      "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File"
    };
    gd.addChoice("File Type?", filetypechoice, filetypechoice[0]);
    boolean ch2green = true;
    gd.addCheckbox("Ch2 is green?", ch2green);
    gd.showDialog();
    if (gd.wasCanceled()) {
      return;
    }
    sfreq = gd.getNextNumber();
    int psfflag = gd.getNextChoiceIndex();
    int fileflag = gd.getNextChoiceIndex();
    ch2green = gd.getNextBoolean();
    int nfiles = 0;
    Object[] histograms = null;
    int xmax = 0;
    int ymax = 0;
    String[] names = null;
    if (fileflag < 2) {
      jdataio ioclass = new jdataio();
      File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance());
      if (filearray.length == 0) {
        return;
      }
      String dir = filearray[0].getAbsolutePath();
      int sepindex = dir.lastIndexOf(File.separator);
      String newdir = dir.substring(0, sepindex + 1);
      OpenDialog.setDefaultDirectory(newdir);
      nfiles = filearray.length / 2;
      if (nfiles > 25) {
        nfiles = 25;
      }
      histograms = new Object[nfiles];
      names = organize_c3_files(filearray);
      for (int i = 0; i < nfiles; i++) {
        try {
          int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0);
          int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0);
          int length3 = (int) (((double) filearray[2 * i].length()) / 2.0);
          int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0);
          InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i]));
          InputStream instream2 =
              new BufferedInputStream(new FileInputStream(filearray[2 * i + 1]));
          if (fileflag == 0) {
            int[] pmdata = new int[length1];
            int[] pmdata2 = new int[length2];
            if (!ioclass.skipstreambytes(instream, 128)) {
              showioerror();
              instream.close();
              return;
            }
            if (!ioclass.skipstreambytes(instream2, 128)) {
              showioerror();
              instream2.close();
              return;
            }
            if (!ioclass.readintelintfile(instream, length1, pmdata)) {
              showioerror();
              instream.close();
              return;
            }
            if (!ioclass.readintelintfile(instream2, length2, pmdata2)) {
              showioerror();
              instream2.close();
              return;
            }
            if (ch2green) {
              histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000);
            } else {
              histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000);
            }
          } else {
            float[] tmdata = new float[length3];
            float[] tmdata2 = new float[length4];
            if (!ioclass.readintelshortfile(instream, length3, tmdata)) {
              showioerror();
              instream.close();
              return;
            }
            if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) {
              showioerror();
              instream2.close();
              return;
            }
            if (ch2green) {
              histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata);
            } else {
              histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2);
            }
          }
          if (((float[][]) histograms[i]).length > xmax) {
            xmax = ((float[][]) histograms[i]).length;
          }
          if (((float[][]) histograms[i])[0].length > ymax) {
            ymax = ((float[][]) histograms[i])[0].length;
          }
          instream.close();
          instream2.close();
        } catch (IOException e) {
          showioerror();
          return;
        }
      }
    } else {
      if (fileflag == 2) {
        ImageWindow iw = WindowManager.getCurrentWindow();
        float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues");
        float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues");
        sfreq = 1.0 / ((double) tempxvals[0][1]);
        nfiles = trajectories.length / 2;
        if (nfiles > 25) {
          nfiles = 25;
        }
        names = new String[nfiles + 1];
        names[nfiles] = "avg";
        histograms = new Object[nfiles];
        for (int i = 0; i < nfiles; i++) {
          names[i] = "trajectory " + (i + 1);
          if (ch2green) {
            histograms[i] =
                (new pmodeconvert())
                    .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]);
          } else {
            histograms[i] =
                (new pmodeconvert())
                    .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]);
          }
          if (((float[][]) histograms[i]).length > xmax) {
            xmax = ((float[][]) histograms[i]).length;
          }
          if (((float[][]) histograms[i])[0].length > ymax) {
            ymax = ((float[][]) histograms[i])[0].length;
          }
        }
      } else {
        // here we read tab delimited lines from files
        jdataio ioclass = new jdataio();
        File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance());
        if (filearray.length == 0) {
          return;
        }
        String dir = filearray[0].getAbsolutePath();
        int sepindex = dir.lastIndexOf(File.separator);
        String newdir = dir.substring(0, sepindex + 1);
        OpenDialog.setDefaultDirectory(newdir);
        nfiles = filearray.length;
        if (nfiles > 25) {
          nfiles = 25;
        }
        histograms = new Object[nfiles];
        names = new String[nfiles + 1];
        names[nfiles] = "avg";
        for (int i = 0; i < nfiles; i++) {
          try {
            names[i] = filearray[i].getName();
            BufferedReader d = new BufferedReader(new FileReader(filearray[i]));
            String[] lines = new String[256];
            int counter = 0;
            do {
              lines[counter] = d.readLine();
              counter++;
            } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256);
            int numcolumns = 0;
            for (int j = 0; j < counter - 1; j++) {
              int temp = getncolumns(lines[j]);
              if (temp > numcolumns) {
                numcolumns = temp;
              }
            }
            float[][] temphist2 = null;
            if (ch2green) {
              temphist2 = new float[numcolumns][counter - 1];
            } else {
              temphist2 = new float[counter - 1][numcolumns];
            }
            for (int k = 0; k < counter - 1; k++) {
              float[] temp = tab_delim2float(lines[k]);
              for (int j = 0; j < numcolumns; j++) {
                if (ch2green) {
                  temphist2[j][k] = temp[j];
                } else {
                  temphist2[k][j] = temp[j];
                }
              }
            }
            histograms[i] = temphist2;
            d.close();
          } catch (IOException e) {
            showioerror();
            return;
          }
        }
        for (int i = 0; i < nfiles; i++) {
          if (((float[][]) histograms[i]).length > xmax) {
            xmax = ((float[][]) histograms[i]).length;
          }
          if (((float[][]) histograms[i])[0].length > ymax) {
            ymax = ((float[][]) histograms[i])[0].length;
          }
        }
      }
    }
    // note that here x is green and y is red
    float[][][] pch = new float[nfiles][xmax][ymax];
    for (int i = 0; i < nfiles; i++) {
      for (int j = 0; j < ((float[][]) histograms[i]).length; j++) {
        for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) {
          pch[i][j][k] = ((float[][]) histograms[i])[j][k];
        }
      }
    }

    final PCH2DFitWindow cw = new PCH2DFitWindow();
    cw.init(names, pch, psfflag);

    final Frame f = new Frame("PCH 2D Analysis");
    f.setLocation(10, 10);
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            f.dispose();
          }
        });

    f.add(cw);
    f.pack();
    f.setResizable(false);
    Insets ins = f.getInsets();
    cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65;
    cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right;
    f.setSize(cw.totalSize);
    f.setVisible(true);
    cw.requestFocus();
  }
Esempio n. 9
0
 public static void main(String args[]) {
   if (System.getProperty("java.version").substring(0, 3).compareTo("1.5") < 0) {
     javax.swing.JOptionPane.showMessageDialog(
         null, "ImageJ " + VERSION + " requires Java 1.5 or later.");
     System.exit(0);
   }
   boolean noGUI = false;
   int mode = STANDALONE;
   arguments = args;
   // System.setProperty("file.encoding", "UTF-8");
   int nArgs = args != null ? args.length : 0;
   boolean commandLine = false;
   for (int i = 0; i < nArgs; i++) {
     String arg = args[i];
     if (arg == null) continue;
     if (args[i].startsWith("-")) {
       if (args[i].startsWith("-batch")) noGUI = true;
       else if (args[i].startsWith("-debug")) IJ.setDebugMode(true);
       else if (args[i].startsWith("-ijpath") && i + 1 < nArgs) {
         if (IJ.debugMode) IJ.log("-ijpath: " + args[i + 1]);
         Prefs.setHomeDir(args[i + 1]);
         commandLine = true;
         args[i + 1] = null;
       } else if (args[i].startsWith("-port")) {
         int delta = (int) Tools.parseDouble(args[i].substring(5, args[i].length()), 0.0);
         commandLine = true;
         if (delta == 0) mode = EMBEDDED;
         else if (delta > 0 && DEFAULT_PORT + delta < 65536) port = DEFAULT_PORT + delta;
       }
     }
   }
   // If existing ImageJ instance, pass arguments to it and quit.
   boolean passArgs = mode == STANDALONE && !noGUI;
   if (IJ.isMacOSX() && !commandLine) passArgs = false;
   if (passArgs && isRunning(args)) return;
   ImageJ ij = IJ.getInstance();
   if (!noGUI && (ij == null || (ij != null && !ij.isShowing()))) {
     ij = new ImageJ(null, mode);
     ij.exitWhenQuitting = true;
   }
   int macros = 0;
   for (int i = 0; i < nArgs; i++) {
     String arg = args[i];
     if (arg == null) continue;
     if (arg.startsWith("-")) {
       if ((arg.startsWith("-macro") || arg.startsWith("-batch")) && i + 1 < nArgs) {
         String arg2 = i + 2 < nArgs ? args[i + 2] : null;
         Prefs.commandLineMacro = true;
         if (noGUI && args[i + 1].endsWith(".js")) Interpreter.batchMode = true;
         IJ.runMacroFile(args[i + 1], arg2);
         break;
       } else if (arg.startsWith("-eval") && i + 1 < nArgs) {
         String rtn = IJ.runMacro(args[i + 1]);
         if (rtn != null) System.out.print(rtn);
         args[i + 1] = null;
       } else if (arg.startsWith("-run") && i + 1 < nArgs) {
         IJ.run(args[i + 1]);
         args[i + 1] = null;
       }
     } else if (macros == 0 && (arg.endsWith(".ijm") || arg.endsWith(".txt"))) {
       IJ.runMacroFile(arg);
       macros++;
     } else if (arg.length() > 0 && arg.indexOf("ij.ImageJ") == -1) {
       File file = new File(arg);
       IJ.open(file.getAbsolutePath());
     }
   }
   if (IJ.debugMode && IJ.getInstance() == null) new JavaProperties().run("");
   if (noGUI) System.exit(0);
 }
Esempio n. 10
0
 public void windowActivated(WindowEvent e) {
   ImageJ ij = IJ.getInstance();
   if (IJ.isMacOSX() && ij != null && !ij.isActive() && !(this instanceof ThresholdAdjuster))
     ij.toFront();
   WindowManager.setWindow(this);
 }
Esempio n. 11
0
    public BandAdjuster() {

      super("Threshold Colour");
      if (instance != null) {
        instance.toFront();
        return;
      }
      imp = WindowManager.getCurrentImage();
      if (imp == null) {
        IJ.beep();
        IJ.showStatus("No image");
        return;
      }
      IJ.run("Select None");
      thread = new Thread(this, "BandAdjuster");
      WindowManager.addWindow(this);
      instance = this;
      IJ.register(PasteController.class);

      ij = IJ.getInstance();
      Font font = new Font("SansSerif", Font.PLAIN, 10);
      GridBagLayout gridbag = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      setLayout(gridbag);

      int y = 0;
      c.gridx = 0;
      c.gridy = y;
      c.gridwidth = 1;
      c.weightx = 0;
      c.insets = new Insets(5, 0, 0, 0);
      labelh = new Label("Hue", Label.CENTER);
      add(labelh, c);

      c.gridx = 1;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = 0;
      c.insets = new Insets(7, 0, 0, 0);
      labelf = new Label("Filter type", Label.RIGHT);
      add(labelf, c);

      // plot
      c.gridx = 0;
      c.gridy = y;
      c.gridwidth = 1;
      c.fill = c.BOTH;
      c.anchor = c.CENTER;
      c.insets = new Insets(0, 5, 0, 0);
      add(plot, c);

      // checkboxes
      panelh = new Panel();
      filterTypeH = new CheckboxGroup();
      bandPassH = new Checkbox("Pass");
      bandPassH.setCheckboxGroup(filterTypeH);
      bandPassH.addItemListener(this);
      panelh.add(bandPassH);
      bandStopH = new Checkbox("Stop");
      bandStopH.setCheckboxGroup(filterTypeH);
      bandStopH.addItemListener(this);
      panelh.add(bandStopH);
      bandPassH.setState(true);
      c.gridx = 1;
      c.gridy = y++;
      c.gridwidth = 2;
      c.insets = new Insets(5, 0, 0, 0);
      add(panelh, c);

      // minHue slider
      minSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange);
      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = IJ.isMacintosh() ? 90 : 100;
      c.fill = c.HORIZONTAL;
      c.insets = new Insets(5, 5, 0, 0);

      add(minSlider, c);
      minSlider.addAdjustmentListener(this);
      minSlider.setUnitIncrement(1);

      // minHue slider label
      c.gridx = 1;
      c.gridwidth = 1;
      c.weightx = IJ.isMacintosh() ? 10 : 0;
      c.insets = new Insets(5, 0, 0, 0);
      label1 = new Label("       ", Label.LEFT);
      label1.setFont(font);
      add(label1, c);

      // maxHue sliderHue
      maxSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange);
      c.gridx = 0;
      c.gridy = y;
      c.gridwidth = 1;
      c.weightx = 100;
      c.insets = new Insets(5, 5, 0, 0);
      add(maxSlider, c);
      maxSlider.addAdjustmentListener(this);
      maxSlider.setUnitIncrement(1);

      // maxHue slider label
      c.gridx = 1;
      c.gridwidth = 1;
      c.gridy = y++;
      c.weightx = 0;
      c.insets = new Insets(5, 0, 0, 0);
      label2 = new Label("       ", Label.LEFT);
      label2.setFont(font);
      add(label2, c);

      // =====
      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = 0;
      c.insets = new Insets(10, 0, 0, 0);
      labels = new Label("Saturation", Label.CENTER);
      add(labels, c);

      // plot
      c.gridx = 0;
      c.gridy = y;
      c.gridwidth = 1;
      c.fill = c.BOTH;
      c.anchor = c.CENTER;
      c.insets = new Insets(0, 5, 0, 0);
      add(splot, c);

      // checkboxes
      panels = new Panel();
      filterTypeS = new CheckboxGroup();
      bandPassS = new Checkbox("Pass");
      bandPassS.setCheckboxGroup(filterTypeS);
      bandPassS.addItemListener(this);
      panels.add(bandPassS);
      bandStopS = new Checkbox("Stop");
      bandStopS.setCheckboxGroup(filterTypeS);
      bandStopS.addItemListener(this);
      panels.add(bandStopS);
      bandPassS.setState(true);
      c.gridx = 1;
      c.gridy = y++;
      c.gridwidth = 2;
      c.insets = new Insets(5, 0, 0, 0);
      add(panels, c);

      // minSat slider
      minSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange);
      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = IJ.isMacintosh() ? 90 : 100;
      c.fill = c.HORIZONTAL;
      c.insets = new Insets(5, 5, 0, 0);
      add(minSlider2, c);
      minSlider2.addAdjustmentListener(this);
      minSlider2.setUnitIncrement(1);

      // minSat slider label
      c.gridx = 1;
      c.gridwidth = 1;
      c.weightx = IJ.isMacintosh() ? 10 : 0;
      c.insets = new Insets(5, 0, 0, 0);
      label3 = new Label("       ", Label.LEFT);
      label3.setFont(font);
      add(label3, c);

      // maxSat slider
      maxSlider2 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange);
      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = 100;
      c.insets = new Insets(5, 5, 0, 0);
      add(maxSlider2, c);
      maxSlider2.addAdjustmentListener(this);
      maxSlider2.setUnitIncrement(1);

      // maxSat slider label
      c.gridx = 1;
      c.gridwidth = 1;
      c.weightx = 0;
      c.insets = new Insets(5, 0, 0, 0);
      label4 = new Label("       ", Label.LEFT);
      label4.setFont(font);
      add(label4, c);

      // =====
      c.gridx = 0;
      c.gridwidth = 1;
      c.gridy = y++;
      c.weightx = 0;
      c.insets = new Insets(10, 0, 0, 0);
      labelb = new Label("Brightness", Label.CENTER);
      add(labelb, c);

      c.gridx = 0;
      c.gridwidth = 1;
      c.gridy = y;
      c.fill = c.BOTH;
      c.anchor = c.CENTER;
      c.insets = new Insets(0, 5, 0, 0);
      add(bplot, c);

      // checkboxes
      panelb = new Panel();
      filterTypeB = new CheckboxGroup();
      bandPassB = new Checkbox("Pass");
      bandPassB.setCheckboxGroup(filterTypeB);
      bandPassB.addItemListener(this);
      panelb.add(bandPassB);
      bandStopB = new Checkbox("Stop");
      bandStopB.setCheckboxGroup(filterTypeB);
      bandStopB.addItemListener(this);
      panelb.add(bandStopB);
      bandPassB.setState(true);
      c.gridx = 1;
      c.gridy = y++;
      c.gridwidth = 2;
      c.insets = new Insets(5, 0, 0, 0);
      add(panelb, c);

      // minBri slider
      minSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange);
      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = IJ.isMacintosh() ? 90 : 100;
      c.fill = c.HORIZONTAL;
      c.insets = new Insets(5, 5, 0, 0);
      add(minSlider3, c);
      minSlider3.addAdjustmentListener(this);
      minSlider3.setUnitIncrement(1);

      // minBri slider label
      c.gridx = 1;
      c.gridwidth = 1;
      c.weightx = IJ.isMacintosh() ? 10 : 0;
      c.insets = new Insets(5, 0, 0, 0);
      label5 = new Label("       ", Label.LEFT);
      label5.setFont(font);
      add(label5, c);

      // maxBri slider
      maxSlider3 = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, sliderRange);
      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 1;
      c.weightx = 100;
      c.insets = new Insets(5, 5, 0, 0);
      add(maxSlider3, c);
      maxSlider3.addAdjustmentListener(this);
      maxSlider3.setUnitIncrement(1);

      // maxBri slider label
      c.gridx = 1;
      c.gridwidth = 1;
      c.weightx = 0;
      c.insets = new Insets(5, 0, 0, 0);
      label6 = new Label("       ", Label.LEFT);
      label6.setFont(font);
      add(label6, c);

      // =====
      panelt = new Panel();
      threshold = new Checkbox("Threshold");
      threshold.addItemListener(this);
      panelt.add(threshold);

      invert = new Checkbox("Invert");
      invert.addItemListener(this);
      panelt.add(invert);

      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 2;
      c.insets = new Insets(0, 0, 0, 0);
      add(panelt, c);

      // buttons
      panel = new Panel();
      // panel.setLayout(new GridLayout(2, 2, 0, 0));
      originalB = new Button("Original");
      originalB.setEnabled(false);
      originalB.addActionListener(this);
      originalB.addKeyListener(ij);
      panel.add(originalB);

      filteredB = new Button("Filtered");
      filteredB.setEnabled(false);
      filteredB.addActionListener(this);
      filteredB.addKeyListener(ij);
      panel.add(filteredB);

      stackB = new Button("Stack");
      stackB.addActionListener(this);
      stackB.addKeyListener(ij);
      panel.add(stackB);

      helpB = new Button("Help");
      helpB.addActionListener(this);
      helpB.addKeyListener(ij);
      panel.add(helpB);

      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 2;
      c.insets = new Insets(0, 0, 0, 0);
      add(panel, c);

      panelMode = new Panel();

      sampleB = new Button("Sample");
      sampleB.addActionListener(this);
      sampleB.addKeyListener(ij);
      panelMode.add(sampleB);

      colourMode = new CheckboxGroup();
      hsb = new Checkbox("HSB");
      hsb.setCheckboxGroup(colourMode);
      hsb.addItemListener(this);
      panelMode.add(hsb);
      hsb.setState(true);
      rgb = new Checkbox("RGB");
      rgb.setCheckboxGroup(colourMode);
      rgb.addItemListener(this);
      panelMode.add(rgb);

      c.gridx = 0;
      c.gridy = y++;
      c.gridwidth = 2;
      c.insets = new Insets(0, 0, 0, 0);
      add(panelMode, c);

      addKeyListener(ij); // ImageJ handles keyboard shortcuts
      pack();
      GUI.center(this);
      setVisible(true);

      ip = setup(imp);
      if (ip == null) {
        imp.unlock();
        IJ.beep();
        IJ.showStatus("RGB image cannot be thresholded");
        return;
      }
      thread.start();
    }
Esempio n. 12
0
/*------------------------------------------------------------------*/
public class Differentials_ implements PlugIn {

  /* begin class Differentials_ */

  /*..................................................................*/
  /* Global-scope variables											*/
  /*..................................................................*/
  static final int GRADIENT_MAGNITUDE = 1;
  static final int GRADIENT_DIRECTION = 2;
  static final int LAPLACIAN = 3;
  static final int LARGEST_HESSIAN = 4;
  static final int SMALLEST_HESSIAN = 5;
  static final int HESSIAN_ORIENTATION = 6;

  private final double FLT_EPSILON = (double) Float.intBitsToFloat((int) 0x33FFFFFF);
  private ImagePlus imp = null;
  private ProgressBar progressBar = IJ.getInstance().getProgressBar();
  private long lastTime = System.currentTimeMillis();
  private int completed = 1;
  private int processDuration = 1;
  private static int operation = LAPLACIAN;
  private int stackSize = 1;
  private boolean cancel = false;

  /*..................................................................*/
  /* Public methods													*/
  /*..................................................................*/
  /*------------------------------------------------------------------*/
  public void getCrossHessian(ImageProcessor ip, double tolerance) {
    getHorizontalGradient(ip, tolerance);
    getVerticalGradient(ip, tolerance);
  } /* end getCrossHessian */

  /*------------------------------------------------------------------*/
  public void getHorizontalGradient(ImageProcessor ip, double tolerance) {
    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }

    float[] floatPixels = (float[]) ip.getPixels();
    int width = ip.getWidth();
    int height = ip.getHeight();
    double line[] = new double[width];

    for (int y = 0; (y < height); y++) {
      getRow(ip, y, line);
      getSplineInterpolationCoefficients(line, tolerance);
      getGradient(line);
      putRow(ip, y, line);
      stepProgressBar();
    }
  } /* end getHorizontalGradient */

  /*------------------------------------------------------------------*/
  public void getHorizontalHessian(ImageProcessor ip, double tolerance) {
    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }

    float[] floatPixels = (float[]) ip.getPixels();
    int width = ip.getWidth();
    int height = ip.getHeight();
    double line[] = new double[width];

    for (int y = 0; (y < height); y++) {
      getRow(ip, y, line);
      getSplineInterpolationCoefficients(line, tolerance);
      getHessian(line);
      putRow(ip, y, line);
      stepProgressBar();
    }
  } /* end getHorizontalHessian */

  /*------------------------------------------------------------------*/
  public void getVerticalGradient(ImageProcessor ip, double tolerance) {
    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }

    float[] floatPixels = (float[]) ip.getPixels();
    int width = ip.getWidth();
    int height = ip.getHeight();
    double line[] = new double[height];

    for (int x = 0; (x < width); x++) {
      getColumn(ip, x, line);
      getSplineInterpolationCoefficients(line, tolerance);
      getGradient(line);
      putColumn(ip, x, line);
      stepProgressBar();
    }
  } /* end getVerticalGradient */

  /*------------------------------------------------------------------*/
  public void getVerticalHessian(ImageProcessor ip, double tolerance) {
    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }

    float[] floatPixels = (float[]) ip.getPixels();
    int width = ip.getWidth();
    int height = ip.getHeight();
    double line[] = new double[height];

    for (int x = 0; (x < width); x++) {
      getColumn(ip, x, line);
      getSplineInterpolationCoefficients(line, tolerance);
      getHessian(line);
      putColumn(ip, x, line);
      stepProgressBar();
    }
  } /* end getVerticalHessian */

  /*------------------------------------------------------------------*/
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    this.imp = imp;
    if (imp == null) {
      IJ.noImage();
      return;
    }
    if ((1 < imp.getStackSize()) && (imp.getType() == imp.COLOR_256)) {
      IJ.error("Stack of color images not supported (use grayscale)");
      return;
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isRGB()) {
        IJ.error("RGB color images not supported (use grayscale)");
        return;
      }
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isHSB()) {
        IJ.error("HSB color images not supported (use grayscale)");
        return;
      }
    }
    if (imp.getType() == imp.COLOR_256) {
      IJ.error("Indexed color images not supported (use grayscale)");
      return;
    }
    if (imp.getType() == imp.COLOR_RGB) {
      IJ.error("Color images not supported (use grayscale)");
      return;
    }

    differentialsDialog dialog =
        new differentialsDialog(IJ.getInstance(), "Differentials", true, operation);
    GUI.center(dialog);
    dialog.setVisible(true);
    cancel = dialog.getCancel();
    operation = dialog.getOperation();
    dialog.dispose();
    if (cancel) {
      return;
    }

    imp.startTiming();
    if (1 < imp.getStackSize()) {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new StackConverter(imp).convertToGray32();
      }
    } else {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new ImageConverter(imp).convertToGray32();
      }
    }
    ImageStack stack = imp.getStack();
    stackSize = stack.getSize();
    Undo.reset();

    setupProgressBar();
    resetProgressBar();

    for (int i = 1; (i <= stackSize); i++) {
      ImageProcessor ip = stack.getProcessor(i);
      doIt(ip);
      imp.getProcessor().resetMinAndMax();
      imp.setSlice(i);
      imp.updateAndRepaintWindow();
    }
    imp.getProcessor().resetMinAndMax();
    imp.setSlice(1);
    imp.updateAndRepaintWindow();
    cleanUpProgressBar();
    IJ.showTime(imp, imp.getStartTime(), "Differentials: ");
    ImageWindow win = imp.getWindow();
    if (win != null) {
      win.running = false;
    }
  } /* end run */

  /*..................................................................*/
  /* Private methods													*/
  /*..................................................................*/
  /*------------------------------------------------------------------*/
  void antiSymmetricFirMirrorOnBounds(double[] h, double[] c, double[] s) {
    if (h.length != 2) {
      throw new IndexOutOfBoundsException("The half-length filter size should be 2");
    }
    if (h[0] != 0.0) {
      throw new IllegalArgumentException("Antisymmetry violation (should have h[0]=0.0)");
    }
    if (c.length != s.length) {
      throw new IndexOutOfBoundsException("Incompatible size");
    }
    if (2 <= c.length) {
      s[0] = 0.0;
      for (int i = 1; (i < (s.length - 1)); i++) {
        s[i] = h[1] * (c[i + 1] - c[i - 1]);
      }
      s[s.length - 1] = 0.0;
    } else {
      if (c.length == 1) {
        s[0] = 0.0;
      } else {
        throw new NegativeArraySizeException("Invalid length of data");
      }
    }
  } /* end antiSymmetricFirMirrorOnBounds */

  /*------------------------------------------------------------------*/
  void cleanUpProgressBar() {
    completed = 0;
    progressBar.show(2.0);
  } /* end cleanUpProgressBar */

  /*------------------------------------------------------------------*/
  void doIt(ImageProcessor ip) {
    int width = ip.getWidth();
    int height = ip.getHeight();
    double hLine[] = new double[width];
    double vLine[] = new double[height];

    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }
    switch (operation) {
      case GRADIENT_MAGNITUDE:
        {
          ImageProcessor h = ip.duplicate();
          ImageProcessor v = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsH = (float[]) h.getPixels();
          float[] floatPixelsV = (float[]) v.getPixels();

          getHorizontalGradient(h, FLT_EPSILON);
          getVerticalGradient(v, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] =
                  (float)
                      Math.sqrt(
                          floatPixelsH[k] * floatPixelsH[k] + floatPixelsV[k] * floatPixelsV[k]);
            }
            stepProgressBar();
          }
        }
        break;
      case GRADIENT_DIRECTION:
        {
          ImageProcessor h = ip.duplicate();
          ImageProcessor v = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsH = (float[]) h.getPixels();
          float[] floatPixelsV = (float[]) v.getPixels();

          getHorizontalGradient(h, FLT_EPSILON);
          getVerticalGradient(v, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] = (float) Math.atan2(floatPixelsH[k], floatPixelsV[k]);
            }
            stepProgressBar();
          }
        }
        break;
      case LAPLACIAN:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] = (float) (floatPixelsHH[k] + floatPixelsVV[k]);
            }
            stepProgressBar();
          }
        }
        break;
      case LARGEST_HESSIAN:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          ImageProcessor hv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();
          float[] floatPixelsHV = (float[]) hv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          getCrossHessian(hv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] =
                  (float)
                      (0.5
                          * (floatPixelsHH[k]
                              + floatPixelsVV[k]
                              + Math.sqrt(
                                  4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                      + (floatPixelsHH[k] - floatPixelsVV[k])
                                          * (floatPixelsHH[k] - floatPixelsVV[k]))));
            }
            stepProgressBar();
          }
        }
        break;
      case SMALLEST_HESSIAN:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          ImageProcessor hv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();
          float[] floatPixelsHV = (float[]) hv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          getCrossHessian(hv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] =
                  (float)
                      (0.5
                          * (floatPixelsHH[k]
                              + floatPixelsVV[k]
                              - Math.sqrt(
                                  4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                      + (floatPixelsHH[k] - floatPixelsVV[k])
                                          * (floatPixelsHH[k] - floatPixelsVV[k]))));
            }
            stepProgressBar();
          }
        }
        break;
      case HESSIAN_ORIENTATION:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          ImageProcessor hv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();
          float[] floatPixelsHV = (float[]) hv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          getCrossHessian(hv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              if (floatPixelsHV[k] < 0.0) {
                floatPixels[k] =
                    (float)
                        (-0.5
                            * Math.acos(
                                (floatPixelsHH[k] - floatPixelsVV[k])
                                    / Math.sqrt(
                                        4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                            + (floatPixelsHH[k] - floatPixelsVV[k])
                                                * (floatPixelsHH[k] - floatPixelsVV[k]))));
              } else {
                floatPixels[k] =
                    (float)
                        (0.5
                            * Math.acos(
                                (floatPixelsHH[k] - floatPixelsVV[k])
                                    / Math.sqrt(
                                        4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                            + (floatPixelsHH[k] - floatPixelsVV[k])
                                                * (floatPixelsHH[k] - floatPixelsVV[k]))));
              }
            }
            stepProgressBar();
          }
        }
        break;
      default:
        throw new IllegalArgumentException("Invalid operation");
    }
    ip.resetMinAndMax();
    imp.updateAndDraw();
  } /* end doIt */

  /*------------------------------------------------------------------*/
  void getColumn(ImageProcessor ip, int x, double[] column) {
    int width = ip.getWidth();

    if (ip.getHeight() != column.length) {
      throw new IndexOutOfBoundsException("Incoherent array sizes");
    }
    if (ip.getPixels() instanceof float[]) {
      float[] floatPixels = (float[]) ip.getPixels();
      for (int i = 0; (i < column.length); i++) {
        column[i] = (double) floatPixels[x];
        x += width;
      }
    } else {
      throw new IllegalArgumentException("Float image required");
    }
  } /* end getColumn */

  /*------------------------------------------------------------------*/
  void getGradient(double[] c) {
    double h[] = {0.0, -1.0 / 2.0};
    double s[] = new double[c.length];

    antiSymmetricFirMirrorOnBounds(h, c, s);
    System.arraycopy(s, 0, c, 0, s.length);
  } /* end getGradient */

  /*------------------------------------------------------------------*/
  void getHessian(double[] c) {
    double h[] = {-2.0, 1.0};
    double s[] = new double[c.length];

    symmetricFirMirrorOnBounds(h, c, s);
    System.arraycopy(s, 0, c, 0, s.length);
  } /* end getHessian */

  /*------------------------------------------------------------------*/
  double getInitialAntiCausalCoefficientMirrorOnBounds(double[] c, double z, double tolerance) {
    return ((z * c[c.length - 2] + c[c.length - 1]) * z / (z * z - 1.0));
  } /* end getInitialAntiCausalCoefficientMirrorOnBounds */

  /*------------------------------------------------------------------*/
  double getInitialCausalCoefficientMirrorOnBounds(double[] c, double z, double tolerance) {
    double z1 = z, zn = Math.pow(z, c.length - 1);
    double sum = c[0] + zn * c[c.length - 1];
    int horizon = c.length;

    if (0.0 < tolerance) {
      horizon = 2 + (int) (Math.log(tolerance) / Math.log(Math.abs(z)));
      horizon = (horizon < c.length) ? (horizon) : (c.length);
    }
    zn = zn * zn;
    for (int n = 1; (n < (horizon - 1)); n++) {
      zn = zn / z;
      sum = sum + (z1 + zn) * c[n];
      z1 = z1 * z;
    }
    return (sum / (1.0 - Math.pow(z, 2 * c.length - 2)));
  } /* end getInitialCausalCoefficientMirrorOnBounds */

  /*------------------------------------------------------------------*/
  void getRow(ImageProcessor ip, int y, double[] row) {
    int rowLength = ip.getWidth();

    if (rowLength != row.length) {
      throw new IndexOutOfBoundsException("Incoherent array sizes");
    }
    y *= rowLength;
    if (ip.getPixels() instanceof float[]) {
      float[] floatPixels = (float[]) ip.getPixels();
      for (int i = 0; (i < rowLength); i++) {
        row[i] = (double) floatPixels[y++];
      }
    } else {
      throw new IllegalArgumentException("Float image required");
    }
  } /* end getRow */

  /*------------------------------------------------------------------*/
  void getSplineInterpolationCoefficients(double[] c, double tolerance) {
    double z[] = {Math.sqrt(3.0) - 2.0};
    double lambda = 1.0;

    if (c.length == 1) {
      return;
    }
    for (int k = 0; (k < z.length); k++) {
      lambda = lambda * (1.0 - z[k]) * (1.0 - 1.0 / z[k]);
    }
    for (int n = 0; (n < c.length); n++) {
      c[n] = c[n] * lambda;
    }
    for (int k = 0; (k < z.length); k++) {
      c[0] = getInitialCausalCoefficientMirrorOnBounds(c, z[k], tolerance);
      for (int n = 1; (n < c.length); n++) {
        c[n] = c[n] + z[k] * c[n - 1];
      }
      c[c.length - 1] = getInitialAntiCausalCoefficientMirrorOnBounds(c, z[k], tolerance);
      for (int n = c.length - 2; (0 <= n); n--) {
        c[n] = z[k] * (c[n + 1] - c[n]);
      }
    }
  } /* end getSplineInterpolationCoefficients */

  /*------------------------------------------------------------------*/
  void putColumn(ImageProcessor ip, int x, double[] column) {
    int width = ip.getWidth();

    if (ip.getHeight() != column.length) {
      throw new IndexOutOfBoundsException("Incoherent array sizes");
    }
    if (ip.getPixels() instanceof float[]) {
      float[] floatPixels = (float[]) ip.getPixels();
      for (int i = 0; (i < column.length); i++) {
        floatPixels[x] = (float) column[i];
        x += width;
      }
    } else {
      throw new IllegalArgumentException("Float image required");
    }
  } /* end putColumn */

  /*------------------------------------------------------------------*/
  void putRow(ImageProcessor ip, int y, double[] row) {
    int rowLength = ip.getWidth();

    if (rowLength != row.length) {
      throw new IndexOutOfBoundsException("Incoherent array sizes");
    }
    y *= rowLength;
    if (ip.getPixels() instanceof float[]) {
      float[] floatPixels = (float[]) ip.getPixels();
      for (int i = 0; (i < rowLength); i++) {
        floatPixels[y++] = (float) row[i];
      }
    } else {
      throw new IllegalArgumentException("Float image required");
    }
  } /* end putRow */

  /*------------------------------------------------------------------*/
  void resetProgressBar() {
    completed = 0;
    lastTime = System.currentTimeMillis();
    progressBar.show(2.0);
  } /* end resetProgressBar */

  /*------------------------------------------------------------------*/
  void setupProgressBar() {
    int height = imp.getHeight();
    int width = imp.getWidth();

    completed = 0;
    lastTime = System.currentTimeMillis();
    switch (operation) {
      case GRADIENT_MAGNITUDE:
        processDuration = stackSize * (width + 2 * height);
        break;
      case GRADIENT_DIRECTION:
        processDuration = stackSize * (width + 2 * height);
        break;
      case LAPLACIAN:
        processDuration = stackSize * (width + 2 * height);
        break;
      case LARGEST_HESSIAN:
        processDuration = stackSize * (2 * width + 3 * height);
        break;
      case SMALLEST_HESSIAN:
        processDuration = stackSize * (2 * width + 3 * height);
        break;
      case HESSIAN_ORIENTATION:
        processDuration = stackSize * (2 * width + 3 * height);
        break;
      default:
        throw new IllegalArgumentException("Invalid operation");
    }
  } /* end setupProgressBar */

  /*------------------------------------------------------------------*/
  void stepProgressBar() {
    long timeStamp = System.currentTimeMillis();

    completed = completed + 1;
    if (50L < (timeStamp - lastTime)) {
      lastTime = timeStamp;
      progressBar.show((double) completed / (double) processDuration);
    }
  } /* end stepProgressBar */

  /*------------------------------------------------------------------*/
  void symmetricFirMirrorOnBounds(double[] h, double[] c, double[] s) {
    if (h.length != 2) {
      throw new IndexOutOfBoundsException("The half-length filter size should be 2");
    }
    if (c.length != s.length) {
      throw new IndexOutOfBoundsException("Incompatible size");
    }
    if (2 <= c.length) {
      s[0] = h[0] * c[0] + 2.0 * h[1] * c[1];
      for (int i = 1; (i < (s.length - 1)); i++) {
        s[i] = h[0] * c[i] + h[1] * (c[i - 1] + c[i + 1]);
      }
      s[s.length - 1] = h[0] * c[c.length - 1] + 2.0 * h[1] * c[c.length - 2];
    } else {
      switch (c.length) {
        case 1:
          s[0] = (h[0] + 2.0 * h[1]) * c[0];
          break;
        default:
          throw new NegativeArraySizeException("Invalid length of data");
      }
    }
  } /* end symmetricFirMirrorOnBounds */
} /* end class Differentials_ */
Esempio n. 13
0
  /*------------------------------------------------------------------*/
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    this.imp = imp;
    if (imp == null) {
      IJ.noImage();
      return;
    }
    if ((1 < imp.getStackSize()) && (imp.getType() == imp.COLOR_256)) {
      IJ.error("Stack of color images not supported (use grayscale)");
      return;
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isRGB()) {
        IJ.error("RGB color images not supported (use grayscale)");
        return;
      }
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isHSB()) {
        IJ.error("HSB color images not supported (use grayscale)");
        return;
      }
    }
    if (imp.getType() == imp.COLOR_256) {
      IJ.error("Indexed color images not supported (use grayscale)");
      return;
    }
    if (imp.getType() == imp.COLOR_RGB) {
      IJ.error("Color images not supported (use grayscale)");
      return;
    }

    differentialsDialog dialog =
        new differentialsDialog(IJ.getInstance(), "Differentials", true, operation);
    GUI.center(dialog);
    dialog.setVisible(true);
    cancel = dialog.getCancel();
    operation = dialog.getOperation();
    dialog.dispose();
    if (cancel) {
      return;
    }

    imp.startTiming();
    if (1 < imp.getStackSize()) {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new StackConverter(imp).convertToGray32();
      }
    } else {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new ImageConverter(imp).convertToGray32();
      }
    }
    ImageStack stack = imp.getStack();
    stackSize = stack.getSize();
    Undo.reset();

    setupProgressBar();
    resetProgressBar();

    for (int i = 1; (i <= stackSize); i++) {
      ImageProcessor ip = stack.getProcessor(i);
      doIt(ip);
      imp.getProcessor().resetMinAndMax();
      imp.setSlice(i);
      imp.updateAndRepaintWindow();
    }
    imp.getProcessor().resetMinAndMax();
    imp.setSlice(1);
    imp.updateAndRepaintWindow();
    cleanUpProgressBar();
    IJ.showTime(imp, imp.getStartTime(), "Differentials: ");
    ImageWindow win = imp.getWindow();
    if (win != null) {
      win.running = false;
    }
  } /* end run */