void createSelectionFromMask(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); if (ip.getMinThreshold() != ImageProcessor.NO_THRESHOLD) { IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", ""); return; } if (!ip.isBinary()) { IJ.error( "Create Selection", "This command creates a composite selection from\n" + "a mask (8-bit binary image with white background)\n" + "or from an image that has been thresholded using\n" + "the Image>Adjust>Threshold tool. The current\n" + "image is not a mask and has not been thresholded."); return; } int threshold = ip.isInvertedLut() ? 255 : 0; ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", ""); }
/** Restores original disk or network version of image. */ public void revertToSaved(ImagePlus imp) { Image img; ProgressBar pb = IJ.getInstance().getProgressBar(); ImageProcessor ip; String path = fi.directory + fi.fileName; if (fi.fileFormat == fi.GIF_OR_JPG) { // restore gif or jpg img = Toolkit.getDefaultToolkit().createImage(path); imp.setImage(img); if (imp.getType() == ImagePlus.COLOR_RGB) Opener.convertGrayJpegTo8Bits(imp); return; } if (fi.fileFormat == fi.DICOM) { // restore DICOM ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.DICOM", path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.fileFormat == fi.BMP) { // restore BMP ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.BMP_Reader", path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.fileFormat == fi.PGM) { // restore PGM ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.PGM_Reader", path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.fileFormat == fi.ZIP_ARCHIVE) { // restore ".zip" file ImagePlus imp2 = (new Opener()).openZip(path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } // restore PNG or another image opened using ImageIO if (fi.fileFormat == fi.IMAGEIO) { ImagePlus imp2 = (new Opener()).openUsingImageIO(path); if (imp2 != null) imp.setProcessor(null, imp2.getProcessor()); return; } if (fi.nImages > 1) return; ColorModel cm; if (fi.url == null || fi.url.equals("")) IJ.showStatus("Loading: " + path); else IJ.showStatus("Loading: " + fi.url + fi.fileName); Object pixels = readPixels(fi); if (pixels == null) return; cm = createColorModel(fi); switch (fi.fileType) { case FileInfo.GRAY8: case FileInfo.COLOR8: case FileInfo.BITMAP: ip = new ByteProcessor(width, height, (byte[]) pixels, cm); imp.setProcessor(null, ip); break; case FileInfo.GRAY16_SIGNED: case FileInfo.GRAY16_UNSIGNED: case FileInfo.GRAY12_UNSIGNED: ip = new ShortProcessor(width, height, (short[]) pixels, cm); imp.setProcessor(null, ip); break; case FileInfo.GRAY32_INT: case FileInfo.GRAY32_FLOAT: ip = new FloatProcessor(width, height, (float[]) pixels, cm); imp.setProcessor(null, ip); break; case FileInfo.RGB: case FileInfo.BGR: case FileInfo.ARGB: case FileInfo.ABGR: case FileInfo.RGB_PLANAR: img = Toolkit.getDefaultToolkit() .createImage(new MemoryImageSource(width, height, (int[]) pixels, 0, width)); imp.setImage(img); break; } }
/** * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ. */ public ImageJ(java.applet.Applet applet, int mode) { super("ImageJ"); if ((mode & DEBUG) != 0) IJ.setDebugMode(true); mode = mode & 255; if (IJ.debugMode) IJ.log("ImageJ starting in debug mode: " + mode); embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW); this.applet = applet; String err1 = Prefs.load(this, applet); setBackground(backgroundColor); Menus m = new Menus(this, applet); String err2 = m.addMenuBar(); m.installPopupMenu(this); setLayout(new BorderLayout()); // Tool bar toolbar = new Toolbar(); toolbar.addKeyListener(this); add("Center", toolbar); // Status bar statusBar = new Panel(); statusBar.setLayout(new BorderLayout()); statusBar.setForeground(Color.black); statusBar.setBackground(backgroundColor); statusLine = new JLabel(); statusLine.setFont(new Font("SansSerif", Font.PLAIN, 13)); statusLine.addKeyListener(this); statusLine.addMouseListener(this); statusBar.add("Center", statusLine); progressBar = new ProgressBar(120, 20); progressBar.addKeyListener(this); progressBar.addMouseListener(this); statusBar.add("East", progressBar); add("South", statusBar); IJ.init(this, applet); addKeyListener(this); addWindowListener(this); setFocusTraversalKeysEnabled(false); m.installStartupMacroSet(); // add custom tools runStartupMacro(); Point loc = getPreferredLocation(); Dimension tbSize = toolbar.getPreferredSize(); setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug if (mode != NO_SHOW) { if (IJ.isWindows()) try { setIcon(); } catch (Exception e) { } setLocation(loc.x, loc.y); setResizable(!IJ.isMacOSX()); pack(); setVisible(true); } if (err1 != null) IJ.error(err1); if (err2 != null) { IJ.error(err2); IJ.runPlugIn("ij.plugin.ClassChecker", ""); } if (IJ.isMacintosh() && applet == null) { Object qh = null; qh = IJ.runPlugIn("MacAdapter", ""); if (qh == null) IJ.runPlugIn("QuitHandler", ""); } if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", ""); String str = m.getMacroCount() == 1 ? " macro" : " macros"; IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str); configureProxy(); if (applet == null) loadCursors(); }
/** * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ. */ public ImageJ(java.applet.Applet applet, int mode) { super("ImageJ"); embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW); this.applet = applet; String err1 = Prefs.load(this, applet); if (IJ.isLinux()) { backgroundColor = new Color(240, 240, 240); setBackground(backgroundColor); } Menus m = new Menus(this, applet); String err2 = m.addMenuBar(); m.installPopupMenu(this); setLayout(new GridLayout(2, 1)); // Tool bar toolbar = new Toolbar(); toolbar.addKeyListener(this); add(toolbar); // Status bar statusBar = new Panel(); statusBar.setLayout(new BorderLayout()); statusBar.setForeground(Color.black); statusBar.setBackground(backgroundColor); statusLine = new Label(); statusLine.setFont(SansSerif12); statusLine.addKeyListener(this); statusLine.addMouseListener(this); statusBar.add("Center", statusLine); progressBar = new ProgressBar(120, 20); progressBar.addKeyListener(this); progressBar.addMouseListener(this); statusBar.add("East", progressBar); statusBar.setSize(toolbar.getPreferredSize()); add(statusBar); IJ.init(this, applet); addKeyListener(this); addWindowListener(this); setFocusTraversalKeysEnabled(false); Point loc = getPreferredLocation(); Dimension tbSize = toolbar.getPreferredSize(); int ijWidth = tbSize.width + 10; int ijHeight = 100; setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug if (mode != NO_SHOW) { if (IJ.isWindows()) try { setIcon(); } catch (Exception e) { } setBounds(loc.x, loc.y, ijWidth, ijHeight); // needed for pack to work setLocation(loc.x, loc.y); pack(); setResizable(!(IJ.isMacintosh() || IJ.isWindows())); // make resizable on Linux show(); } if (err1 != null) IJ.error(err1); if (err2 != null) { IJ.error(err2); IJ.runPlugIn("ij.plugin.ClassChecker", ""); } m.installStartupMacroSet(); if (IJ.isMacintosh() && applet == null) { Object qh = null; qh = IJ.runPlugIn("MacAdapter", ""); if (qh == null) IJ.runPlugIn("QuitHandler", ""); } if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", ""); String str = m.getMacroCount() == 1 ? " macro" : " macros"; IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str); // if (applet==null && !embedded && Prefs.runSocketListener) // new SocketListener(); configureProxy(); if (applet == null) loadCursors(); }