コード例 #1
0
ファイル: Rotator.java プロジェクト: AlexJoz/docuensj
 public void run(ImageProcessor ip) {
   if (enlarge && gd.wasOKed())
     synchronized (this) {
       if (!isEnlarged) {
         enlargeCanvas();
         isEnlarged = true;
       }
     }
   if (isEnlarged) { // enlarging may have made the ImageProcessor invalid, also for the parallel
                     // threads
     int slice = pfr.getSliceNumber();
     if (imp.getStackSize() == 1) ip = imp.getProcessor();
     else ip = imp.getStack().getProcessor(slice);
   }
   ip.setInterpolationMethod(interpolationMethod);
   if (fillWithBackground) {
     Color bgc = Toolbar.getBackgroundColor();
     if (bitDepth == 8) ip.setBackgroundValue(ip.getBestIndex(bgc));
     else if (bitDepth == 24) ip.setBackgroundValue(bgc.getRGB());
   } else ip.setBackgroundValue(0);
   ip.rotate(angle);
   if (!gd.wasOKed()) drawGridLines(gridLines);
   if (isEnlarged && imp.getStackSize() == 1) {
     imp.changes = true;
     imp.updateAndDraw();
     Undo.setup(Undo.COMPOUND_FILTER_DONE, imp);
   }
 }
コード例 #2
0
 void showResults() {
   int count = rt.getCounter();
   // if (count==0) return;
   boolean lastSlice = !processStack || slice == imp.getStackSize();
   if ((showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS) && slice == 1 && count > 0)
     imp.setOverlay(overlay);
   else if (outlines != null && lastSlice) {
     String title = imp != null ? imp.getTitle() : "Outlines";
     String prefix;
     if (showChoice == MASKS) prefix = "Mask of ";
     else if (showChoice == ROI_MASKS) prefix = "Count Masks of ";
     else prefix = "Drawing of ";
     outlines.update(drawIP);
     outputImage = new ImagePlus(prefix + title, outlines);
     if (inSituShow) {
       if (imp.getStackSize() == 1) Undo.setup(Undo.TRANSFORM, imp);
       imp.setStack(null, outputImage.getStack());
     } else if (!hideOutputImage) outputImage.show();
   }
   if (showResults && !processStack) {
     TextPanel tp = IJ.getTextPanel();
     if (beginningCount > 0 && tp != null && tp.getLineCount() != count) rt.show("Results");
     Analyzer.firstParticle = beginningCount;
     Analyzer.lastParticle = Analyzer.getCounter() - 1;
   } else Analyzer.firstParticle = Analyzer.lastParticle = 0;
 }
コード例 #3
0
ファイル: MyDialogs.java プロジェクト: baowuji/quickpalm
  public boolean beadCalibration3d() {
    imp = IJ.getImage();
    if (imp == null) {
      IJ.noImage();
      return false;
    } else if (imp.getStackSize() == 1) {
      IJ.error("Stack required");
      return false;
    } else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16) {
      // In order to support 32bit images, pict[] must be changed to float[], and  getPixel(x, y);
      // requires a Float.intBitsToFloat() conversion
      IJ.error("8 or 16 bit greyscale image required");
      return false;
    }
    width = imp.getWidth();
    height = imp.getHeight();
    nslices = imp.getStackSize();
    imtitle = imp.getTitle();

    models[0] = "*None*";
    models[1] = "line";
    models[2] = "2nd degree polynomial";
    models[3] = "3rd degree polynomial";
    models[4] = "4th degree polynomial";

    GenericDialog gd = new GenericDialog("3D PALM calibration");
    gd.addNumericField("Maximum FWHM (in px)", prefs.get("QuickPALM.3Dcal_fwhm", 20), 0);
    gd.addNumericField(
        "Particle local threshold (% maximum intensity)", prefs.get("QuickPALM.pthrsh", 20), 0);
    gd.addNumericField("Z-spacing (nm)", prefs.get("QuickPALM.z-step", 10), 2);
    gd.addNumericField("Calibration Z-smoothing (radius)", prefs.get("QuickPALM.window", 1), 0);
    gd.addChoice("Model", models, prefs.get("QuickPALM.model", models[3]));
    gd.addCheckbox(
        "Show divergence of bead positions against model",
        prefs.get("QuickPALM.3Dcal_showDivergence", false));
    gd.addCheckbox("Show extra particle info", prefs.get("QuickPALM.3Dcal_showExtraInfo", false));
    gd.addMessage("\n\nDon't forget to save the table in the end...");
    gd.showDialog();
    if (gd.wasCanceled()) return false;
    fwhm = gd.getNextNumber();
    prefs.set("QuickPALM.QuickPALM.3Dcal_fwhm", fwhm);
    pthrsh = gd.getNextNumber() / 100;
    prefs.set("QuickPALM.pthrsh", pthrsh * 100);
    cal_z = gd.getNextNumber();
    prefs.set("QuickPALM.z-step", cal_z);
    window = (int) gd.getNextNumber();
    prefs.set("QuickPALM.window", window);
    model = gd.getNextChoice();
    prefs.set("QuickPALM.model", model);
    part_divergence = gd.getNextBoolean();
    prefs.set("QuickPALM.3Dcal_showDivergence", part_divergence);
    part_extrainfo = gd.getNextBoolean();
    prefs.set("QuickPALM.3Dcal_showExtraInfo", part_extrainfo);
    return true;
  }
コード例 #4
0
ファイル: Bleach_.java プロジェクト: HelioScan/HelioScan
  public void run(String arg) {
    int[] wList = WindowManager.getIDList();
    if (wList == null) {
      IJ.error("No images are open.");
      return;
    }

    double thalf = 0.5;
    boolean keep;

    GenericDialog gd = new GenericDialog("Bleach correction");

    gd.addNumericField("t½:", thalf, 1);
    gd.addCheckbox("Keep source stack:", true);
    gd.showDialog();
    if (gd.wasCanceled()) return;

    long start = System.currentTimeMillis();
    thalf = gd.getNextNumber();
    keep = gd.getNextBoolean();
    if (keep) IJ.run("Duplicate...", "title='Bleach corrected' duplicate");
    ImagePlus imp1 = WindowManager.getCurrentImage();
    int d1 = imp1.getStackSize();
    double v1, v2;
    int width = imp1.getWidth();
    int height = imp1.getHeight();
    ImageProcessor ip1, ip2, ip3;

    int slices = imp1.getStackSize();
    ImageStack stack1 = imp1.getStack();
    ImageStack stack2 = imp1.getStack();
    int currentSlice = imp1.getCurrentSlice();

    for (int n = 1; n <= slices; n++) {
      ip1 = stack1.getProcessor(n);
      ip3 = stack1.getProcessor(1);
      ip2 = stack2.getProcessor(n);
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          v1 = ip1.getPixelValue(x, y);
          v2 = ip3.getPixelValue(x, y);

          // =B8/(EXP(-C$7*A8))
          v1 = (v1 / Math.exp(-n * thalf));
          ip2.putPixelValue(x, y, v1);
        }
      }
      IJ.showProgress((double) n / slices);
      IJ.showStatus(n + "/" + slices);
    }

    // stack2.show();
    imp1.updateAndDraw();
  }
コード例 #5
0
ファイル: EDM.java プロジェクト: sina-masoud-ansari/ImageJ
 /**
  * Called by the PlugInFilterRunner after setup. Asks the user in case of a stack and prepares a
  * separate ouptut stack if required
  */
 public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
   this.pfr = pfr;
   int width = imp.getWidth();
   int height = imp.getHeight();
   // ask whether to process all slices of stack & prepare stack
   // (if required) for writing into it in parallel threads
   flags = IJ.setupDialog(imp, flags);
   if ((flags & DOES_STACKS) != 0 && outImageType != BYTE_OVERWRITE) {
     outStack = new ImageStack(width, height, imp.getStackSize());
     maxFinder.setNPasses(imp.getStackSize());
   }
   return flags;
 } // public int showDialog
コード例 #6
0
 public void run(ImageProcessor ip) {
   if (canceled) return;
   slice++;
   if (imp.getStackSize() > 1 && processStack) imp.setSlice(slice);
   if (imp.getType() == ImagePlus.COLOR_RGB) {
     ip = (ImageProcessor) imp.getProperty("Mask");
     ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   }
   if (!analyze(imp, ip)) canceled = true;
   if (slice == imp.getStackSize()) {
     imp.updateAndDraw();
     if (saveRoi != null) imp.setRoi(saveRoi);
   }
 }
コード例 #7
0
 void updateSliceSummary() {
   int slices = imp.getStackSize();
   float[] areas = rt.getColumn(ResultsTable.AREA);
   if (areas == null) areas = new float[0];
   String label = imp.getTitle();
   if (slices > 1) {
     label = imp.getStack().getShortSliceLabel(slice);
     label = label != null && !label.equals("") ? label : "" + slice;
   }
   String aLine = null;
   double sum = 0.0;
   int start = areas.length - particleCount;
   if (start < 0) return;
   for (int i = start; i < areas.length; i++) sum += areas[i];
   int places = Analyzer.getPrecision();
   Calibration cal = imp.getCalibration();
   String total = "\t" + ResultsTable.d2s(sum, places);
   String average = "\t" + ResultsTable.d2s(sum / particleCount, places);
   String fraction = "\t" + ResultsTable.d2s(sum * 100.0 / totalArea, 1);
   aLine = label + "\t" + particleCount + total + average + fraction;
   aLine = addMeans(aLine, areas.length > 0 ? start : -1);
   if (slices == 1) {
     Frame frame = WindowManager.getFrame("Summary");
     if (frame != null && (frame instanceof TextWindow) && summaryHdr.equals(prevHdr))
       tw = (TextWindow) frame;
   }
   if (tw == null) {
     String title = slices == 1 ? "Summary" : "Summary of " + imp.getTitle();
     tw = new TextWindow(title, summaryHdr, aLine, 450, 300);
     prevHdr = summaryHdr;
   } else tw.append(aLine);
 }
コード例 #8
0
 /**
  * Saves statistics for one particle in a results table. This is a method subclasses may want to
  * override.
  */
 protected void saveResults(ImageStatistics stats, Roi roi) {
   analyzer.saveResults(stats, roi);
   if (recordStarts) {
     rt.addValue("XStart", stats.xstart);
     rt.addValue("YStart", stats.ystart);
   }
   if (addToManager) {
     if (roiManager == null) {
       if (Macro.getOptions() != null && Interpreter.isBatchMode())
         roiManager = Interpreter.getBatchModeRoiManager();
       if (roiManager == null) {
         Frame frame = WindowManager.getFrame("ROI Manager");
         if (frame == null) IJ.run("ROI Manager...");
         frame = WindowManager.getFrame("ROI Manager");
         if (frame == null || !(frame instanceof RoiManager)) {
           addToManager = false;
           return;
         }
         roiManager = (RoiManager) frame;
       }
       if (resetCounter) roiManager.runCommand("reset");
     }
     if (imp.getStackSize() > 1) roi.setPosition(imp.getCurrentSlice());
     if (lineWidth != 1) roi.setStrokeWidth(lineWidth);
     roiManager.add(imp, roi, rt.getCounter());
   }
   if (showResults) rt.addResults();
 }
コード例 #9
0
ファイル: Rotator.java プロジェクト: AlexJoz/docuensj
 public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
   this.pfr = pfr;
   String macroOptions = Macro.getOptions();
   if (macroOptions != null) {
     if (macroOptions.indexOf(" interpolate") != -1)
       macroOptions.replaceAll(" interpolate", " interpolation=Bilinear");
     else if (macroOptions.indexOf(" interpolation=") == -1)
       macroOptions = macroOptions + " interpolation=None";
     Macro.setOptions(macroOptions);
   }
   gd = new GenericDialog("Rotate", IJ.getInstance());
   gd.addNumericField("Angle (degrees):", angle, (int) angle == angle ? 1 : 2);
   gd.addNumericField("Grid Lines:", gridLines, 0);
   gd.addChoice("Interpolation:", methods, methods[interpolationMethod]);
   if (bitDepth == 8 || bitDepth == 24)
     gd.addCheckbox("Fill with Background Color", fillWithBackground);
   if (canEnlarge) gd.addCheckbox("Enlarge Image to Fit Result", enlarge);
   else enlarge = false;
   gd.addPreviewCheckbox(pfr);
   gd.addDialogListener(this);
   gd.showDialog();
   drawGridLines(0);
   if (gd.wasCanceled()) {
     return DONE;
   }
   if (!enlarge) flags |= KEEP_PREVIEW; // standard filter without enlarge
   else if (imp.getStackSize() == 1) flags |= NO_CHANGES; // undoable as a "compound filter"
   return IJ.setupDialog(imp, flags);
 }
コード例 #10
0
ファイル: Scaler.java プロジェクト: TaihaoJin/ImgSigJ
 void scale(ImageProcessor ip) {
   if (newWindow) {
     Rectangle r = ip.getRoi();
     ImagePlus imp2 = imp.createImagePlus();
     imp2.setProcessor(title, ip.resize(newWidth, newHeight));
     Calibration cal = imp2.getCalibration();
     if (cal.scaled()) {
       cal.pixelWidth *= 1.0 / xscale;
       cal.pixelHeight *= 1.0 / yscale;
     }
     imp2.show();
     imp.trimProcessor();
     imp2.trimProcessor();
     imp2.changes = true;
   } else {
     if (processStack && imp.getStackSize() > 1) {
       Undo.reset();
       StackProcessor sp = new StackProcessor(imp.getStack(), ip);
       sp.scale(xscale, yscale, bgValue);
     } else {
       ip.snapshot();
       Undo.setup(Undo.FILTER, imp);
       ip.setSnapshotCopyMode(true);
       ip.scale(xscale, yscale);
       ip.setSnapshotCopyMode(false);
     }
     imp.killRoi();
     imp.updateAndDraw();
     imp.changes = true;
   }
 }
コード例 #11
0
ファイル: ImageJ.java プロジェクト: chrisp87/ImageJA
 private boolean ignoreArrowKeys(ImagePlus imp) {
   Frame frame = WindowManager.getFrontWindow();
   String title = frame.getTitle();
   if (title != null && title.equals("ROI Manager")) return true;
   // Control Panel?
   if (frame != null && frame instanceof javax.swing.JFrame) return true;
   ImageWindow win = imp.getWindow();
   // LOCI Data Browser window?
   if (imp.getStackSize() > 1 && win != null && win.getClass().getName().startsWith("loci"))
     return true;
   return false;
 }
コード例 #12
0
ファイル: Info.java プロジェクト: boron1111/ij
 public String getImageInfo(ImagePlus imp, ImageProcessor ip) {
   String infoProperty = null;
   if (imp.getStackSize() > 1) {
     ImageStack stack = imp.getStack();
     String label = stack.getSliceLabel(imp.getCurrentSlice());
     if (label != null && label.indexOf('\n') > 0) infoProperty = label;
   }
   if (infoProperty == null) {
     infoProperty = (String) imp.getProperty("Info");
     if (infoProperty == null) infoProperty = getExifData(imp);
   }
   String info = getInfo(imp, ip);
   if (infoProperty != null) return infoProperty + "\n------------------------\n" + info;
   else return info;
 }
コード例 #13
0
ファイル: EDM.java プロジェクト: sina-masoud-ansari/ImageJ
 // at the very end - show output image (if the is a separate one)
 private void showOutput() {
   if (interrupted) return;
   if (outStack != null) {
     outImp = new ImagePlus(TITLE_PREFIX[processType] + imp.getShortTitle(), outStack);
     int[] d = imp.getDimensions();
     outImp.setDimensions(d[2], d[3], d[4]);
     for (int i = 1; i <= imp.getStackSize(); i++)
       outStack.setSliceLabel(imp.getStack().getSliceLabel(i), i);
   }
   if (outImageType != BYTE_OVERWRITE) {
     ImageProcessor ip = outImp.getProcessor();
     if (!Prefs.blackBackground) ip.invertLut();
     ip.resetMinAndMax();
     outImp.show();
   }
 }
コード例 #14
0
ファイル: Scaler.java プロジェクト: BinRoot/Photometer
 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;
   }
 }
コード例 #15
0
  /**
   * Execute the plugin functionality: duplicate and scale the given image.
   *
   * @return an Object[] array with the name and the scaled ImagePlus. Does NOT show the new, image;
   *     just returns it.
   */
  public Object[] exec(
      ImagePlus imp, String myMethod, int radius, double par1, double par2, boolean doIwhite) {

    // 0 - Check validity of parameters
    if (null == imp) return null;
    ImageProcessor ip = imp.getProcessor();
    int xe = ip.getWidth();
    int ye = ip.getHeight();

    // int [] data = (ip.getHistogram());

    IJ.showStatus("Thresholding...");
    long startTime = System.currentTimeMillis();
    // 1 Do it
    if (imp.getStackSize() == 1) {
      ip.snapshot();
      Undo.setup(Undo.FILTER, imp);
    }
    // Apply the selected algorithm
    if (myMethod.equals("Bernsen")) {
      Bernsen(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Contrast")) {
      Contrast(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Mean")) {
      Mean(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Median")) {
      Median(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("MidGrey")) {
      MidGrey(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Niblack")) {
      Niblack(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Otsu")) {
      Otsu(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Phansalkar")) {
      Phansalkar(imp, radius, par1, par2, doIwhite);
    } else if (myMethod.equals("Sauvola")) {
      Sauvola(imp, radius, par1, par2, doIwhite);
    }
    // IJ.showProgress((double)(255-i)/255);
    imp.updateAndDraw();
    imp.getProcessor().setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
    // 2 - Return the threshold and the image
    IJ.showStatus("\nDone " + (System.currentTimeMillis() - startTime) / 1000.0);
    return new Object[] {imp};
  }
コード例 #16
0
ファイル: ZProjector.java プロジェクト: halirutan/imagej1
 private void doRGBProjection(ImageStack stack) {
   ImageStack[] channels = ChannelSplitter.splitRGB(stack, true);
   ImagePlus red = new ImagePlus("Red", channels[0]);
   ImagePlus green = new ImagePlus("Green", channels[1]);
   ImagePlus blue = new ImagePlus("Blue", channels[2]);
   imp.unlock();
   ImagePlus saveImp = imp;
   imp = red;
   color = "(red)";
   doProjection();
   ImagePlus red2 = projImage;
   imp = green;
   color = "(green)";
   doProjection();
   ImagePlus green2 = projImage;
   imp = blue;
   color = "(blue)";
   doProjection();
   ImagePlus blue2 = projImage;
   int w = red2.getWidth(), h = red2.getHeight(), d = red2.getStackSize();
   if (method == SD_METHOD) {
     ImageProcessor r = red2.getProcessor();
     ImageProcessor g = green2.getProcessor();
     ImageProcessor b = blue2.getProcessor();
     double max = 0;
     double rmax = r.getStatistics().max;
     if (rmax > max) max = rmax;
     double gmax = g.getStatistics().max;
     if (gmax > max) max = gmax;
     double bmax = b.getStatistics().max;
     if (bmax > max) max = bmax;
     double scale = 255 / max;
     r.multiply(scale);
     g.multiply(scale);
     b.multiply(scale);
     red2.setProcessor(r.convertToByte(false));
     green2.setProcessor(g.convertToByte(false));
     blue2.setProcessor(b.convertToByte(false));
   }
   RGBStackMerge merge = new RGBStackMerge();
   ImageStack stack2 =
       merge.mergeStacks(w, h, d, red2.getStack(), green2.getStack(), blue2.getStack(), true);
   imp = saveImp;
   projImage = new ImagePlus(makeTitle(), stack2);
 }
コード例 #17
0
ファイル: Scaler.java プロジェクト: TaihaoJin/ImgSigJ
 public void run(String arg) {
   imp = IJ.getImage();
   Roi roi = imp.getRoi();
   if (roi != null && !roi.isArea()) imp.killRoi(); // ignore any line selection
   ImageProcessor ip = imp.getProcessor();
   if (!showDialog(ip)) return;
   if (ip.getWidth() > 1 && ip.getHeight() > 1) ip.setInterpolate(interpolate);
   else ip.setInterpolate(false);
   ip.setBackgroundValue(bgValue);
   imp.startTiming();
   try {
     if (newWindow && imp.getStackSize() > 1 && processStack) createNewStack(imp, ip);
     else scale(ip);
   } catch (OutOfMemoryError o) {
     IJ.outOfMemory("Scale");
   }
   IJ.showProgress(1.0);
 }
コード例 #18
0
ファイル: Rotator.java プロジェクト: AlexJoz/docuensj
 void enlargeCanvas() {
   imp.unlock();
   if (imp.getStackSize() == 1) Undo.setup(Undo.COMPOUND_FILTER, imp);
   IJ.run("Select All");
   IJ.run("Rotate...", "angle=" + angle);
   Roi roi = imp.getRoi();
   Rectangle r = roi.getBounds();
   if (r.width < imp.getWidth()) r.width = imp.getWidth();
   if (r.height < imp.getHeight()) r.height = imp.getHeight();
   IJ.showStatus("Rotate: Enlarging...");
   IJ.run(
       "Canvas Size...",
       "width="
           + r.width
           + " height="
           + r.height
           + " position=Center "
           + (fillWithBackground ? "" : "zero"));
   IJ.showStatus("Rotating...");
 }
コード例 #19
0
ファイル: Scaler.java プロジェクト: TaihaoJin/ImgSigJ
 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;
 }
コード例 #20
0
 public void run(String arg) {
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp == null) {
     IJ.noImage();
     return;
   }
   if (imp.getStackSize() > 1) {
     IJ.error("This command requires a montage");
     return;
   }
   GenericDialog gd = new GenericDialog("Stack Maker");
   gd.addNumericField("Images_per_row: ", w, 0);
   gd.addNumericField("Images_per_column: ", h, 0);
   gd.addNumericField("Border width: ", b, 0);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   w = (int) gd.getNextNumber();
   h = (int) gd.getNextNumber();
   b = (int) gd.getNextNumber();
   ImageStack stack = makeStack(imp.getProcessor(), w, h, b);
   new ImagePlus("Stack", stack).show();
 }
コード例 #21
0
ファイル: SpecifyROI.java プロジェクト: dannyZhou/imagej
 public void run(String arg) {
   imp = IJ.getImage();
   if (imp == null) return;
   stackSize = imp.getStackSize();
   Roi roi = imp.getRoi();
   Calibration cal = imp.getCalibration();
   if (roi != null && roi.getBounds().equals(prevRoi) && cal.pixelWidth == prevPixelWidth)
     roi = null;
   if (roi != null) {
     boolean rectOrOval =
         roi != null && (roi.getType() == Roi.RECTANGLE || roi.getType() == Roi.OVAL);
     oval = rectOrOval && (roi.getType() == Roi.OVAL); // Handle existing oval ROI
     Rectangle r = roi.getBounds();
     width = r.width;
     height = r.height;
     xRoi = r.x;
     yRoi = r.y;
     if (scaledUnits && cal.scaled()) {
       xRoi = xRoi * cal.pixelWidth;
       yRoi = yRoi * cal.pixelHeight;
       width = width * cal.pixelWidth;
       height = height * cal.pixelHeight;
     }
     if (centered) { // Make xRoi and yRoi consistent when centered mode is active
       xRoi += width / 2.0;
       yRoi += height / 2.0;
     }
   } else if (!validDialogValues()) {
     width = imp.getWidth() / 2;
     height = imp.getHeight() / 2;
     xRoi = width / 2;
     yRoi = height / 2;
   }
   iSlice = imp.getCurrentSlice();
   showDialog();
 }
コード例 #22
0
ファイル: FileOpener.java プロジェクト: earrouvi/PAPPL
  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);
      }
    }
  }
コード例 #23
0
ファイル: Info.java プロジェクト: boron1111/ij
  String getInfo(ImagePlus imp, ImageProcessor ip) {
    String s = new String("\n");
    s += "Title: " + imp.getTitle() + "\n";
    Calibration cal = imp.getCalibration();
    int stackSize = imp.getStackSize();
    int channels = imp.getNChannels();
    int slices = imp.getNSlices();
    int frames = imp.getNFrames();
    int digits = imp.getBitDepth() == 32 ? 4 : 0;
    if (cal.scaled()) {
      String unit = cal.getUnit();
      String units = cal.getUnits();
      s +=
          "Width:  "
              + IJ.d2s(imp.getWidth() * cal.pixelWidth, 2)
              + " "
              + units
              + " ("
              + imp.getWidth()
              + ")\n";
      s +=
          "Height:  "
              + IJ.d2s(imp.getHeight() * cal.pixelHeight, 2)
              + " "
              + units
              + " ("
              + imp.getHeight()
              + ")\n";
      if (slices > 1)
        s += "Depth:  " + IJ.d2s(slices * cal.pixelDepth, 2) + " " + units + " (" + slices + ")\n";
      double xResolution = 1.0 / cal.pixelWidth;
      double yResolution = 1.0 / cal.pixelHeight;
      int places = Tools.getDecimalPlaces(xResolution, yResolution);
      if (xResolution == yResolution)
        s += "Resolution:  " + IJ.d2s(xResolution, places) + " pixels per " + unit + "\n";
      else {
        s += "X Resolution:  " + IJ.d2s(xResolution, places) + " pixels per " + unit + "\n";
        s += "Y Resolution:  " + IJ.d2s(yResolution, places) + " pixels per " + unit + "\n";
      }
    } else {
      s += "Width:  " + imp.getWidth() + " pixels\n";
      s += "Height:  " + imp.getHeight() + " pixels\n";
      if (stackSize > 1) s += "Depth:  " + slices + " pixels\n";
    }
    if (stackSize > 1)
      s +=
          "Voxel size: "
              + d2s(cal.pixelWidth)
              + "x"
              + d2s(cal.pixelHeight)
              + "x"
              + d2s(cal.pixelDepth)
              + " "
              + cal.getUnit()
              + "\n";
    else
      s +=
          "Pixel size: "
              + d2s(cal.pixelWidth)
              + "x"
              + d2s(cal.pixelHeight)
              + " "
              + cal.getUnit()
              + "\n";

    s += "ID: " + imp.getID() + "\n";
    String zOrigin = stackSize > 1 || cal.zOrigin != 0.0 ? "," + d2s(cal.zOrigin) : "";
    s += "Coordinate origin:  " + d2s(cal.xOrigin) + "," + d2s(cal.yOrigin) + zOrigin + "\n";
    int type = imp.getType();
    switch (type) {
      case ImagePlus.GRAY8:
        s += "Bits per pixel: 8 ";
        String lut = "LUT";
        if (imp.getProcessor().isColorLut()) lut = "color " + lut;
        else lut = "grayscale " + lut;
        if (imp.isInvertedLut()) lut = "inverting " + lut;
        s += "(" + lut + ")\n";
        if (imp.getNChannels() > 1) s += displayRanges(imp);
        else s += "Display range: " + (int) ip.getMin() + "-" + (int) ip.getMax() + "\n";
        break;
      case ImagePlus.GRAY16:
      case ImagePlus.GRAY32:
        if (type == ImagePlus.GRAY16) {
          String sign = cal.isSigned16Bit() ? "signed" : "unsigned";
          s += "Bits per pixel: 16 (" + sign + ")\n";
        } else s += "Bits per pixel: 32 (float)\n";
        if (imp.getNChannels() > 1) s += displayRanges(imp);
        else {
          s += "Display range: ";
          double min = ip.getMin();
          double max = ip.getMax();
          if (cal.calibrated()) {
            min = cal.getCValue((int) min);
            max = cal.getCValue((int) max);
          }
          s += IJ.d2s(min, digits) + " - " + IJ.d2s(max, digits) + "\n";
        }
        break;
      case ImagePlus.COLOR_256:
        s += "Bits per pixel: 8 (color LUT)\n";
        break;
      case ImagePlus.COLOR_RGB:
        s += "Bits per pixel: 32 (RGB)\n";
        break;
    }
    double interval = cal.frameInterval;
    double fps = cal.fps;
    if (stackSize > 1) {
      ImageStack stack = imp.getStack();
      int slice = imp.getCurrentSlice();
      String number = slice + "/" + stackSize;
      String label = stack.getShortSliceLabel(slice);
      if (label != null && label.length() > 0) label = " (" + label + ")";
      else label = "";
      if (interval > 0.0 || fps != 0.0) {
        s += "Frame: " + number + label + "\n";
        if (fps != 0.0) {
          String sRate =
              Math.abs(fps - Math.round(fps)) < 0.00001 ? IJ.d2s(fps, 0) : IJ.d2s(fps, 5);
          s += "Frame rate: " + sRate + " fps\n";
        }
        if (interval != 0.0)
          s +=
              "Frame interval: "
                  + ((int) interval == interval ? IJ.d2s(interval, 0) : IJ.d2s(interval, 5))
                  + " "
                  + cal.getTimeUnit()
                  + "\n";
      } else s += "Image: " + number + label + "\n";
      if (imp.isHyperStack()) {
        if (channels > 1) s += "  Channel: " + imp.getChannel() + "/" + channels + "\n";
        if (slices > 1) s += "  Slice: " + imp.getSlice() + "/" + slices + "\n";
        if (frames > 1) s += "  Frame: " + imp.getFrame() + "/" + frames + "\n";
      }
      if (imp.isComposite()) {
        if (!imp.isHyperStack() && channels > 1) s += "  Channels: " + channels + "\n";
        String mode = ((CompositeImage) imp).getModeAsString();
        s += "  Composite mode: \"" + mode + "\"\n";
      }
    }

    if (ip.getMinThreshold() == ImageProcessor.NO_THRESHOLD) s += "No Threshold\n";
    else {
      double lower = ip.getMinThreshold();
      double upper = ip.getMaxThreshold();
      int dp = digits;
      if (cal.calibrated()) {
        lower = cal.getCValue((int) lower);
        upper = cal.getCValue((int) upper);
        dp = cal.isSigned16Bit() ? 0 : 4;
      }
      s += "Threshold: " + IJ.d2s(lower, dp) + "-" + IJ.d2s(upper, dp) + "\n";
    }
    ImageCanvas ic = imp.getCanvas();
    double mag = ic != null ? ic.getMagnification() : 1.0;
    if (mag != 1.0) s += "Magnification: " + IJ.d2s(mag, 2) + "\n";

    if (cal.calibrated()) {
      s += " \n";
      int curveFit = cal.getFunction();
      s += "Calibration Function: ";
      if (curveFit == Calibration.UNCALIBRATED_OD) s += "Uncalibrated OD\n";
      else if (curveFit == Calibration.CUSTOM) s += "Custom lookup table\n";
      else s += CurveFitter.fList[curveFit] + "\n";
      double[] c = cal.getCoefficients();
      if (c != null) {
        s += "  a: " + IJ.d2s(c[0], 6) + "\n";
        s += "  b: " + IJ.d2s(c[1], 6) + "\n";
        if (c.length >= 3) s += "  c: " + IJ.d2s(c[2], 6) + "\n";
        if (c.length >= 4) s += "  c: " + IJ.d2s(c[3], 6) + "\n";
        if (c.length >= 5) s += "  c: " + IJ.d2s(c[4], 6) + "\n";
      }
      s += "  Unit: \"" + cal.getValueUnit() + "\"\n";
    } else s += "Uncalibrated\n";

    FileInfo fi = imp.getOriginalFileInfo();
    if (fi != null) {
      if (fi.url != null && !fi.url.equals("")) s += "URL: " + fi.url + "\n";
      else if (fi.directory != null && fi.fileName != null)
        s += "Path: " + fi.directory + fi.fileName + "\n";
    }

    ImageWindow win = imp.getWindow();
    if (win != null) {
      Point loc = win.getLocation();
      Dimension screen = IJ.getScreenSize();
      s +=
          "Screen location: "
              + loc.x
              + ","
              + loc.y
              + " ("
              + screen.width
              + "x"
              + screen.height
              + ")\n";
    }

    Overlay overlay = imp.getOverlay();
    if (overlay != null) {
      String hidden = imp.getHideOverlay() ? " (hidden)" : " ";
      int n = overlay.size();
      String elements = n == 1 ? " element" : " elements";
      s += "Overlay: " + n + elements + (imp.getHideOverlay() ? " (hidden)" : "") + "\n";
    } else s += "No Overlay\n";

    Roi roi = imp.getRoi();
    if (roi == null) {
      if (cal.calibrated()) s += " \n";
      s += "No Selection\n";
    } else if (roi instanceof EllipseRoi) {
      s += "\nElliptical Selection\n";
      double[] p = ((EllipseRoi) roi).getParams();
      double dx = p[2] - p[0];
      double dy = p[3] - p[1];
      double major = Math.sqrt(dx * dx + dy * dy);
      s += "  Major: " + IJ.d2s(major, 2) + "\n";
      s += "  Minor: " + IJ.d2s(major * p[4], 2) + "\n";
      s += "  X1: " + IJ.d2s(p[0], 2) + "\n";
      s += "  Y1: " + IJ.d2s(p[1], 2) + "\n";
      s += "  X2: " + IJ.d2s(p[2], 2) + "\n";
      s += "  Y2: " + IJ.d2s(p[3], 2) + "\n";
      s += "  Aspect ratio: " + IJ.d2s(p[4], 2) + "\n";
    } else {
      s += " \n";
      s += roi.getTypeAsString() + " Selection";
      String points = null;
      if (roi instanceof PointRoi) {
        int npoints = ((PolygonRoi) roi).getNCoordinates();
        String suffix = npoints > 1 ? "s)" : ")";
        points = " (" + npoints + " point" + suffix;
      }
      String name = roi.getName();
      if (name != null) {
        s += " (\"" + name + "\")";
        if (points != null) s += "\n " + points;
      } else if (points != null) s += points;
      s += "\n";
      Rectangle r = roi.getBounds();
      if (roi instanceof Line) {
        Line line = (Line) roi;
        s += "  X1: " + IJ.d2s(line.x1d * cal.pixelWidth) + "\n";
        s += "  Y1: " + IJ.d2s(yy(line.y1d, imp) * cal.pixelHeight) + "\n";
        s += "  X2: " + IJ.d2s(line.x2d * cal.pixelWidth) + "\n";
        s += "  Y2: " + IJ.d2s(yy(line.y2d, imp) * cal.pixelHeight) + "\n";
      } else if (cal.scaled()) {
        s += "  X: " + IJ.d2s(cal.getX(r.x)) + " (" + r.x + ")\n";
        s += "  Y: " + IJ.d2s(cal.getY(r.y, imp.getHeight())) + " (" + r.y + ")\n";
        s += "  Width: " + IJ.d2s(r.width * cal.pixelWidth) + " (" + r.width + ")\n";
        s += "  Height: " + IJ.d2s(r.height * cal.pixelHeight) + " (" + r.height + ")\n";
      } else {
        s += "  X: " + r.x + "\n";
        s += "  Y: " + yy(r.y, imp) + "\n";
        s += "  Width: " + r.width + "\n";
        s += "  Height: " + r.height + "\n";
      }
    }

    return s;
  }
コード例 #24
0
    ImageProcessor setup(ImagePlus imp) {

      ImageProcessor ip;
      int type = imp.getType();
      if (type != ImagePlus.COLOR_RGB) return null;
      ip = imp.getProcessor();
      int id = imp.getID();
      int slice = imp.getCurrentSlice();

      if ((id != previousImageID) | (slice != previousSlice) | (flag)) {
        flag = false; // if true, flags a change from HSB to RGB or viceversa
        numSlices = imp.getStackSize();
        stack = imp.getStack();
        width = stack.getWidth();
        height = stack.getHeight();
        numPixels = width * height;

        hSource = new byte[numPixels];
        sSource = new byte[numPixels];
        bSource = new byte[numPixels];

        // restore = (int[])ip.getPixelsCopy(); //This runs into trouble sometimes, so do it the
        // long way:
        int[] temp = (int[]) ip.getPixels();
        restore = new int[numPixels];
        for (int i = 0; i < numPixels; i++) restore[i] = temp[i];

        fillMask = new int[numPixels];

        // Get hsb or rgb from image.
        ColorProcessor cp = (ColorProcessor) ip;
        IJ.showStatus("Gathering data");

        if (isRGB) cp.getRGB(hSource, sSource, bSource);
        else cp.getHSB(hSource, sSource, bSource);

        IJ.showStatus("done");

        // Create a spectrum ColorModel for the Hue histogram plot.
        Color c;
        byte[] reds = new byte[256];
        byte[] greens = new byte[256];
        byte[] blues = new byte[256];
        for (int i = 0; i < 256; i++) {
          c = Color.getHSBColor(i / 255f, 1f, 1f);

          reds[i] = (byte) c.getRed();
          greens[i] = (byte) c.getGreen();
          blues[i] = (byte) c.getBlue();
        }
        ColorModel cm = new IndexColorModel(8, 256, reds, greens, blues);

        // Make an image with just the hue from the RGB image and the spectrum LUT.
        // This is just for a hue histogram for the plot.  Do not show it.
        // ByteProcessor bpHue = new ByteProcessor(width,height,h,cm);
        ByteProcessor bpHue = new ByteProcessor(width, height, hSource, cm);
        ImagePlus impHue = new ImagePlus("Hue", bpHue);
        // impHue.show();

        ByteProcessor bpSat = new ByteProcessor(width, height, sSource, cm);
        ImagePlus impSat = new ImagePlus("Sat", bpSat);
        // impSat.show();

        ByteProcessor bpBri = new ByteProcessor(width, height, bSource, cm);
        ImagePlus impBri = new ImagePlus("Bri", bpBri);
        // impBri.show();

        plot.setHistogram(impHue, 0);
        splot.setHistogram(impSat, 1);
        bplot.setHistogram(impBri, 2);

        updateLabels();
        updatePlot();
        updateScrollBars();
        imp.updateAndDraw();
      }
      previousImageID = id;
      previousSlice = slice;
      return ip;
    }
コード例 #25
0
  /** Ask for parameters and then execute. */
  public void run(String arg) {
    // 1 - Obtain the currently active image:
    ImagePlus imp = IJ.getImage();

    if (null == imp) {
      IJ.showMessage("There must be at least one image open");
      return;
    }

    if (imp.getBitDepth() != 8) {
      IJ.showMessage("Error", "Only 8-bit images are supported");
      return;
    }

    // 2 - Ask for parameters:
    GenericDialog gd = new GenericDialog("Auto Local Threshold");
    String[] methods = {
      "Try all",
      "Bernsen",
      "Contrast",
      "Mean",
      "Median",
      "MidGrey",
      "Niblack",
      "Otsu",
      "Phansalkar",
      "Sauvola"
    };
    gd.addMessage("Auto Local Threshold v1.5");
    gd.addChoice("Method", methods, methods[0]);
    gd.addNumericField("Radius", 15, 0);
    gd.addMessage("Special paramters (if different from default)");
    gd.addNumericField("Parameter_1", 0, 0);
    gd.addNumericField("Parameter_2", 0, 0);
    gd.addCheckbox("White objects on black background", true);
    if (imp.getStackSize() > 1) {
      gd.addCheckbox("Stack", false);
    }
    gd.addMessage("Thresholded result is always shown in white [255].");
    gd.showDialog();
    if (gd.wasCanceled()) return;

    // 3 - Retrieve parameters from the dialog
    String myMethod = gd.getNextChoice();
    int radius = (int) gd.getNextNumber();
    double par1 = (double) gd.getNextNumber();
    double par2 = (double) gd.getNextNumber();
    boolean doIwhite = gd.getNextBoolean();
    boolean doIstack = false;

    int stackSize = imp.getStackSize();
    if (stackSize > 1) doIstack = gd.getNextBoolean();

    // 4 - Execute!
    // long start = System.currentTimeMillis();
    if (myMethod.equals("Try all")) {
      ImageProcessor ip = imp.getProcessor();
      int xe = ip.getWidth();
      int ye = ip.getHeight();
      int ml = methods.length;
      ImagePlus imp2, imp3;
      ImageStack tstack = null, stackNew;
      if (stackSize > 1 && doIstack) {
        boolean doItAnyway = true;
        if (stackSize > 25) {
          YesNoCancelDialog d =
              new YesNoCancelDialog(
                  IJ.getInstance(),
                  "Auto Local Threshold",
                  "You might run out of memory.\n \nDisplay "
                      + stackSize
                      + " slices?\n \n \'No\' will process without display and\noutput results to the log window.");
          if (!d.yesPressed()) {
            //						doIlog=true; //will show in the log window
            doItAnyway = false;
          }
          if (d.cancelPressed()) return;
        }

        for (int j = 1; j <= stackSize; j++) {
          imp.setSlice(j);
          ip = imp.getProcessor();
          tstack = new ImageStack(xe, ye);
          for (int k = 1; k < ml; k++) tstack.addSlice(methods[k], ip.duplicate());
          imp2 = new ImagePlus("Auto Threshold", tstack);
          imp2.updateAndDraw();

          for (int k = 1; k < ml; k++) {
            imp2.setSlice(k);
            Object[] result = exec(imp2, methods[k], radius, par1, par2, doIwhite);
          }
          // if (doItAnyway){
          CanvasResizer cr = new CanvasResizer();
          stackNew = cr.expandStack(tstack, (xe + 2), (ye + 18), 1, 1);
          imp3 = new ImagePlus("Auto Threshold", stackNew);
          imp3.updateAndDraw();
          MontageMaker mm = new MontageMaker();
          mm.makeMontage(imp3, 3, 3, 1.0, 1, (ml - 1), 1, 0, true); // 3 columns and 3 rows
        }
        imp.setSlice(1);
        // if (doItAnyway)
        IJ.run("Images to Stack", "method=[Copy (center)] title=Montage");
        return;
      } else { // single image try all
        tstack = new ImageStack(xe, ye);
        for (int k = 1; k < ml; k++) tstack.addSlice(methods[k], ip.duplicate());
        imp2 = new ImagePlus("Auto Threshold", tstack);
        imp2.updateAndDraw();

        for (int k = 1; k < ml; k++) {
          imp2.setSlice(k);
          // IJ.log("analyzing slice with "+methods[k]);
          Object[] result = exec(imp2, methods[k], radius, par1, par2, doIwhite);
        }
        // imp2.setSlice(1);
        CanvasResizer cr = new CanvasResizer();
        stackNew = cr.expandStack(tstack, (xe + 2), (ye + 18), 1, 1);
        imp3 = new ImagePlus("Auto Threshold", stackNew);
        imp3.updateAndDraw();
        MontageMaker mm = new MontageMaker();
        mm.makeMontage(imp3, 3, 3, 1.0, 1, (ml - 1), 1, 0, true);
        return;
      }
    } else { // selected a method
      if (stackSize > 1 && doIstack) { // whole stack
        //				if (doIstackHistogram) {// one global histogram
        //					Object[] result = exec(imp, myMethod, noWhite, noBlack, doIwhite, doIset, doIlog,
        // doIstackHistogram );
        //				}
        //				else{ // slice by slice
        for (int k = 1; k <= stackSize; k++) {
          imp.setSlice(k);
          Object[] result = exec(imp, myMethod, radius, par1, par2, doIwhite);
        }
        //				}
        imp.setSlice(1);
      } else { // just one slice
        Object[] result = exec(imp, myMethod, radius, par1, par2, doIwhite);
      }
      // 5 - If all went well, show the image:
      // not needed here as the source image is binarised
    }
  }
コード例 #26
0
ファイル: ImageJ.java プロジェクト: chrisp87/ImageJA
  public void keyPressed(KeyEvent e) {
    // if (e.isConsumed()) return;
    int keyCode = e.getKeyCode();
    IJ.setKeyDown(keyCode);
    hotkey = false;
    if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT) return;
    char keyChar = e.getKeyChar();
    int flags = e.getModifiers();
    if (IJ.debugMode)
      IJ.log(
          "keyPressed: code="
              + keyCode
              + " ("
              + KeyEvent.getKeyText(keyCode)
              + "), char=\""
              + keyChar
              + "\" ("
              + (int) keyChar
              + "), flags="
              + KeyEvent.getKeyModifiersText(flags));
    boolean shift = (flags & KeyEvent.SHIFT_MASK) != 0;
    boolean control = (flags & KeyEvent.CTRL_MASK) != 0;
    boolean alt = (flags & KeyEvent.ALT_MASK) != 0;
    boolean meta = (flags & KeyEvent.META_MASK) != 0;
    String cmd = null;
    ImagePlus imp = WindowManager.getCurrentImage();
    boolean isStack = (imp != null) && (imp.getStackSize() > 1);

    if (imp != null
        && !control
        && ((keyChar >= 32 && keyChar <= 255) || keyChar == '\b' || keyChar == '\n')) {
      Roi roi = imp.getRoi();
      if (roi instanceof TextRoi) {
        if ((flags & KeyEvent.META_MASK) != 0 && IJ.isMacOSX()) return;
        if (alt) {
          switch (keyChar) {
            case 'u':
            case 'm':
              keyChar = IJ.micronSymbol;
              break;
            case 'A':
              keyChar = IJ.angstromSymbol;
              break;
            default:
          }
        }
        ((TextRoi) roi).addChar(keyChar);
        return;
      }
    }

    // Handle one character macro shortcuts
    if (!control && !meta) {
      Hashtable macroShortcuts = Menus.getMacroShortcuts();
      if (macroShortcuts.size() > 0) {
        if (shift) cmd = (String) macroShortcuts.get(new Integer(keyCode + 200));
        else cmd = (String) macroShortcuts.get(new Integer(keyCode));
        if (cmd != null) {
          // MacroInstaller.runMacroCommand(cmd);
          commandName = cmd;
          MacroInstaller.runMacroShortcut(cmd);
          return;
        }
      }
    }

    if ((!Prefs.requireControlKey || control || meta) && keyChar != '+') {
      Hashtable shortcuts = Menus.getShortcuts();
      if (shift) cmd = (String) shortcuts.get(new Integer(keyCode + 200));
      else cmd = (String) shortcuts.get(new Integer(keyCode));
    }

    if (cmd == null) {
      switch (keyChar) {
        case '<':
        case ',':
          if (isStack) cmd = "Previous Slice [<]";
          break;
        case '>':
        case '.':
        case ';':
          if (isStack) cmd = "Next Slice [>]";
          break;
        case '+':
        case '=':
          cmd = "In [+]";
          break;
        case '-':
          cmd = "Out [-]";
          break;
        case '/':
          cmd = "Reslice [/]...";
          break;
        default:
      }
    }

    if (cmd == null) {
      switch (keyCode) {
        case KeyEvent.VK_TAB:
          WindowManager.putBehind();
          return;
        case KeyEvent.VK_BACK_SPACE: // delete
          if (deleteOverlayRoi(imp)) return;
          cmd = "Clear";
          hotkey = true;
          break;
          // case KeyEvent.VK_BACK_SLASH: cmd=IJ.altKeyDown()?"Animation Options...":"Start
          // Animation"; break;
        case KeyEvent.VK_EQUALS:
          cmd = "In [+]";
          break;
        case KeyEvent.VK_MINUS:
          cmd = "Out [-]";
          break;
        case KeyEvent.VK_SLASH:
        case 0xbf:
          cmd = "Reslice [/]...";
          break;
        case KeyEvent.VK_COMMA:
        case 0xbc:
          if (isStack) cmd = "Previous Slice [<]";
          break;
        case KeyEvent.VK_PERIOD:
        case 0xbe:
          if (isStack) cmd = "Next Slice [>]";
          break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_DOWN: // arrow keys
          if (imp == null) return;
          Roi roi = imp.getRoi();
          if (IJ.shiftKeyDown() && imp == Orthogonal_Views.getImage()) return;
          boolean stackKey = imp.getStackSize() > 1 && (roi == null || IJ.shiftKeyDown());
          boolean zoomKey = roi == null || IJ.shiftKeyDown() || IJ.controlKeyDown();
          if (stackKey && keyCode == KeyEvent.VK_RIGHT) cmd = "Next Slice [>]";
          else if (stackKey && keyCode == KeyEvent.VK_LEFT) cmd = "Previous Slice [<]";
          else if (zoomKey
              && keyCode == KeyEvent.VK_DOWN
              && !ignoreArrowKeys(imp)
              && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "Out [-]";
          else if (zoomKey
              && keyCode == KeyEvent.VK_UP
              && !ignoreArrowKeys(imp)
              && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "In [+]";
          else if (roi != null) {
            if ((flags & KeyEvent.ALT_MASK) != 0) roi.nudgeCorner(keyCode);
            else roi.nudge(keyCode);
            return;
          }
          break;
        case KeyEvent.VK_ESCAPE:
          abortPluginOrMacro(imp);
          return;
        case KeyEvent.VK_ENTER:
          WindowManager.toFront(this);
          return;
        default:
          break;
      }
    }

    if (cmd != null && !cmd.equals("")) {
      commandName = cmd;
      if (cmd.equals("Fill") || cmd.equals("Draw")) hotkey = true;
      if (cmd.charAt(0) == MacroInstaller.commandPrefix) MacroInstaller.runMacroShortcut(cmd);
      else {
        doCommand(cmd);
        keyPressedTime = System.currentTimeMillis();
        lastKeyCommand = cmd;
      }
    }
  }
コード例 #27
0
ファイル: Scaler.java プロジェクト: BinRoot/Photometer
  boolean showDialog(ImageProcessor ip) {
    String macroOptions = Macro.getOptions();
    if (macroOptions != null) {
      if (macroOptions.indexOf(" interpolate") != -1)
        macroOptions.replaceAll(" interpolate", " interpolation=Bilinear");
      else if (macroOptions.indexOf(" interpolation=") == -1)
        macroOptions = macroOptions + " interpolation=None";
      Macro.setOptions(macroOptions);
    }
    int bitDepth = imp.getBitDepth();
    int stackSize = imp.getStackSize();
    boolean isStack = stackSize > 1;
    oldDepth = stackSize;
    if (isStack) {
      xstr = "1.0";
      ystr = "1.0";
      zstr = "1.0";
    }
    r = ip.getRoi();
    int width = newWidth;
    if (width == 0) width = r.width;
    int height = (int) ((double) width * r.height / r.width);
    xscale = Tools.parseDouble(xstr, 0.0);
    yscale = Tools.parseDouble(ystr, 0.0);
    zscale = 1.0;
    if (xscale != 0.0 && yscale != 0.0) {
      width = (int) (r.width * xscale);
      height = (int) (r.height * yscale);
    } else {
      xstr = "-";
      ystr = "-";
    }
    GenericDialog gd = new GenericDialog("Scale");
    gd.addStringField("X Scale:", xstr);
    gd.addStringField("Y Scale:", ystr);
    if (isStack) gd.addStringField("Z Scale:", zstr);
    gd.setInsets(5, 0, 5);
    gd.addStringField("Width (pixels):", "" + width);
    gd.addStringField("Height (pixels):", "" + height);
    if (isStack) {
      String label = "Depth (images):";
      if (imp.isHyperStack()) {
        int slices = imp.getNSlices();
        int frames = imp.getNFrames();
        if (slices == 1 && frames > 1) {
          label = "Depth (frames):";
          oldDepth = frames;
        } else {
          label = "Depth (slices):";
          oldDepth = slices;
        }
      }
      gd.addStringField(label, "" + oldDepth);
    }
    fields = gd.getStringFields();
    for (int i = 0; i < fields.size(); i++) {
      ((TextField) fields.elementAt(i)).addTextListener(this);
      ((TextField) fields.elementAt(i)).addFocusListener(this);
    }
    xField = (TextField) fields.elementAt(0);
    yField = (TextField) fields.elementAt(1);
    if (isStack) {
      zField = (TextField) fields.elementAt(2);
      widthField = (TextField) fields.elementAt(3);
      heightField = (TextField) fields.elementAt(4);
      depthField = (TextField) fields.elementAt(5);
    } else {
      widthField = (TextField) fields.elementAt(2);
      heightField = (TextField) fields.elementAt(3);
    }
    fieldWithFocus = xField;
    gd.addChoice("Interpolation:", methods, methods[interpolationMethod]);
    if (bitDepth == 8 || bitDepth == 24)
      gd.addCheckbox("Fill with background color", fillWithBackground);
    gd.addCheckbox("Average when downsizing", averageWhenDownsizing);
    boolean hyperstack = imp.isHyperStack() || imp.isComposite();
    if (isStack && !hyperstack) gd.addCheckbox("Process entire stack", processStack);
    gd.addCheckbox("Create new window", newWindow);
    title = WindowManager.getUniqueName(imp.getTitle());
    gd.setInsets(10, 0, 0);
    gd.addStringField("Title:", title, 12);
    gd.showDialog();
    if (gd.wasCanceled()) return false;
    xstr = gd.getNextString();
    ystr = gd.getNextString();
    xscale = Tools.parseDouble(xstr, 0.0);
    yscale = Tools.parseDouble(ystr, 0.0);
    if (isStack) {
      zstr = gd.getNextString();
      zscale = Tools.parseDouble(ystr, 0.0);
    }
    String wstr = gd.getNextString();
    newWidth = (int) Tools.parseDouble(wstr, 0);
    newHeight = (int) Tools.parseDouble(gd.getNextString(), 0);
    if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0")))
      newWidth = (int) (newHeight * (double) r.width / r.height);
    if (newWidth == 0 || newHeight == 0) {
      IJ.error("Scaler", "Width or height is 0");
      return false;
    }
    if (xscale > 0.0 && yscale > 0.0) {
      newWidth = (int) (r.width * xscale);
      newHeight = (int) (r.height * yscale);
    }
    if (isStack) newDepth = (int) Tools.parseDouble(gd.getNextString(), 0);
    interpolationMethod = gd.getNextChoiceIndex();
    if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean();
    averageWhenDownsizing = gd.getNextBoolean();
    if (isStack && !hyperstack) processStack = gd.getNextBoolean();
    if (hyperstack) processStack = true;
    newWindow = gd.getNextBoolean();
    if (xscale == 0.0) {
      xscale = (double) newWidth / r.width;
      yscale = (double) newHeight / r.height;
    }
    title = gd.getNextString();

    if (fillWithBackground) {
      Color bgc = Toolbar.getBackgroundColor();
      if (bitDepth == 8) bgValue = ip.getBestIndex(bgc);
      else if (bitDepth == 24) bgValue = bgc.getRGB();
    } else bgValue = 0.0;
    return true;
  }
コード例 #28
0
  /**
   * Performs particle analysis on the specified ImagePlus and ImageProcessor. Returns false if
   * there is an error.
   */
  public boolean analyze(ImagePlus imp, ImageProcessor ip) {
    if (this.imp == null) this.imp = imp;
    showResults = (options & SHOW_RESULTS) != 0;
    excludeEdgeParticles = (options & EXCLUDE_EDGE_PARTICLES) != 0;
    resetCounter = (options & CLEAR_WORKSHEET) != 0;
    showProgress = (options & SHOW_PROGRESS) != 0;
    floodFill = (options & INCLUDE_HOLES) == 0;
    recordStarts = (options & RECORD_STARTS) != 0;
    addToManager = (options & ADD_TO_MANAGER) != 0;
    displaySummary = (options & DISPLAY_SUMMARY) != 0;
    inSituShow = (options & IN_SITU_SHOW) != 0;
    outputImage = null;
    ip.snapshot();
    ip.setProgressBar(null);
    if (Analyzer.isRedirectImage()) {
      redirectImp = Analyzer.getRedirectImage(imp);
      if (redirectImp == null) return false;
      int depth = redirectImp.getStackSize();
      if (depth > 1 && depth == imp.getStackSize()) {
        ImageStack redirectStack = redirectImp.getStack();
        redirectIP = redirectStack.getProcessor(imp.getCurrentSlice());
      } else redirectIP = redirectImp.getProcessor();
    } else if (imp.getType() == ImagePlus.COLOR_RGB) {
      ImagePlus original = (ImagePlus) imp.getProperty("OriginalImage");
      if (original != null
          && original.getWidth() == imp.getWidth()
          && original.getHeight() == imp.getHeight()) {
        redirectImp = original;
        redirectIP = original.getProcessor();
      }
    }
    if (!setThresholdLevels(imp, ip)) return false;
    width = ip.getWidth();
    height = ip.getHeight();
    if (!(showChoice == NOTHING || showChoice == OVERLAY_OUTLINES || showChoice == OVERLAY_MASKS)) {
      blackBackground = Prefs.blackBackground && inSituShow;
      if (slice == 1) outlines = new ImageStack(width, height);
      if (showChoice == ROI_MASKS) drawIP = new ShortProcessor(width, height);
      else drawIP = new ByteProcessor(width, height);
      drawIP.setLineWidth(lineWidth);
      if (showChoice == ROI_MASKS) {
      } // Place holder for now...
      else if (showChoice == MASKS && !blackBackground) drawIP.invertLut();
      else if (showChoice == OUTLINES) {
        if (!inSituShow) {
          if (customLut == null) makeCustomLut();
          drawIP.setColorModel(customLut);
        }
        drawIP.setFont(new Font("SansSerif", Font.PLAIN, fontSize));
        if (fontSize > 12 && inSituShow) drawIP.setAntialiasedText(true);
      }
      outlines.addSlice(null, drawIP);

      if (showChoice == ROI_MASKS || blackBackground) {
        drawIP.setColor(Color.black);
        drawIP.fill();
        drawIP.setColor(Color.white);
      } else {
        drawIP.setColor(Color.white);
        drawIP.fill();
        drawIP.setColor(Color.black);
      }
    }
    calibration = redirectImp != null ? redirectImp.getCalibration() : imp.getCalibration();

    if (rt == null) {
      rt = Analyzer.getResultsTable();
      analyzer = new Analyzer(imp);
    } else analyzer = new Analyzer(imp, measurements, rt);
    if (resetCounter && slice == 1) {
      if (!Analyzer.resetCounter()) return false;
    }
    beginningCount = Analyzer.getCounter();

    byte[] pixels = null;
    if (ip instanceof ByteProcessor) pixels = (byte[]) ip.getPixels();
    if (r == null) {
      r = ip.getRoi();
      mask = ip.getMask();
      if (displaySummary) {
        if (mask != null) totalArea = ImageStatistics.getStatistics(ip, AREA, calibration).area;
        else totalArea = r.width * calibration.pixelWidth * r.height * calibration.pixelHeight;
      }
    }
    minX = r.x;
    maxX = r.x + r.width;
    minY = r.y;
    maxY = r.y + r.height;
    if (r.width < width || r.height < height || mask != null) {
      if (!eraseOutsideRoi(ip, r, mask)) return false;
    }
    int offset;
    double value;
    int inc = Math.max(r.height / 25, 1);
    int mi = 0;
    ImageWindow win = imp.getWindow();
    if (win != null) win.running = true;
    if (measurements == 0) measurements = Analyzer.getMeasurements();
    if (showChoice == ELLIPSES) measurements |= ELLIPSE;
    measurements &= ~LIMIT; // ignore "Limit to Threshold"
    roiNeedsImage =
        (measurements & PERIMETER) != 0
            || (measurements & SHAPE_DESCRIPTORS) != 0
            || (measurements & FERET) != 0;
    particleCount = 0;
    wand = new Wand(ip);
    pf = new PolygonFiller();
    if (floodFill) {
      ImageProcessor ipf = ip.duplicate();
      ipf.setValue(fillColor);
      ff = new FloodFiller(ipf);
    }
    roiType = Wand.allPoints() ? Roi.FREEROI : Roi.TRACED_ROI;

    for (int y = r.y; y < (r.y + r.height); y++) {
      offset = y * width;
      for (int x = r.x; x < (r.x + r.width); x++) {
        if (pixels != null) value = pixels[offset + x] & 255;
        else if (imageType == SHORT) value = ip.getPixel(x, y);
        else value = ip.getPixelValue(x, y);
        if (value >= level1 && value <= level2) analyzeParticle(x, y, imp, ip);
      }
      if (showProgress && ((y % inc) == 0)) IJ.showProgress((double) (y - r.y) / r.height);
      if (win != null) canceled = !win.running;
      if (canceled) {
        Macro.abort();
        break;
      }
    }
    if (showProgress) IJ.showProgress(1.0);
    if (showResults) rt.updateResults();
    imp.killRoi();
    ip.resetRoi();
    ip.reset();
    if (displaySummary && IJ.getInstance() != null) updateSliceSummary();
    if (addToManager && roiManager != null) roiManager.setEditMode(imp, true);
    maxParticleCount = (particleCount > maxParticleCount) ? particleCount : maxParticleCount;
    totalCount += particleCount;
    if (!canceled) showResults();
    return true;
  }
コード例 #29
0
ファイル: Scaler.java プロジェクト: BinRoot/Photometer
 public void textValueChanged(TextEvent e) {
   Object source = e.getSource();
   double newXScale = xscale;
   double newYScale = yscale;
   double newZScale = zscale;
   if (source == xField && fieldWithFocus == xField) {
     String newXText = xField.getText();
     newXScale = Tools.parseDouble(newXText, 0);
     if (newXScale == 0) return;
     if (newXScale != xscale) {
       int newWidth = (int) (newXScale * r.width);
       widthField.setText("" + newWidth);
       if (constainAspectRatio) {
         yField.setText(newXText);
         int newHeight = (int) (newXScale * r.height);
         heightField.setText("" + newHeight);
       }
     }
   } else if (source == yField && fieldWithFocus == yField) {
     String newYText = yField.getText();
     newYScale = Tools.parseDouble(newYText, 0);
     if (newYScale == 0) return;
     if (newYScale != yscale) {
       int newHeight = (int) (newYScale * r.height);
       heightField.setText("" + newHeight);
     }
   } else if (source == zField && fieldWithFocus == zField) {
     String newZText = zField.getText();
     newZScale = Tools.parseDouble(newZText, 0);
     if (newZScale == 0) return;
     if (newZScale != zscale) {
       int nSlices = imp.getStackSize();
       if (imp.isHyperStack()) {
         int slices = imp.getNSlices();
         int frames = imp.getNFrames();
         if (slices == 1 && frames > 1) nSlices = frames;
         else nSlices = slices;
       }
       int newDepth = (int) (newZScale * nSlices);
       depthField.setText("" + newDepth);
     }
   } else if (source == widthField && fieldWithFocus == widthField) {
     int newWidth = (int) Tools.parseDouble(widthField.getText(), 0.0);
     if (newWidth != 0) {
       int newHeight = (int) (newWidth * (double) r.height / r.width);
       heightField.setText("" + newHeight);
       xField.setText("-");
       yField.setText("-");
       newXScale = 0.0;
       newYScale = 0.0;
     }
   } else if (source == depthField && fieldWithFocus == depthField) {
     int newDepth = (int) Tools.parseDouble(depthField.getText(), 0.0);
     if (newDepth != 0) {
       zField.setText("-");
       newZScale = 0.0;
     }
   }
   xscale = newXScale;
   yscale = newYScale;
   zscale = newZScale;
 }
コード例 #30
0
ファイル: Scaler.java プロジェクト: TaihaoJin/ImgSigJ
  boolean showDialog(ImageProcessor ip) {
    int bitDepth = imp.getBitDepth();
    boolean isStack = imp.getStackSize() > 1;
    r = ip.getRoi();
    int width = newWidth;
    if (width == 0) width = r.width;
    int height = (int) ((double) width * r.height / r.width);
    xscale = Tools.parseDouble(xstr, 0.0);
    yscale = Tools.parseDouble(ystr, 0.0);
    if (xscale != 0.0 && yscale != 0.0) {
      width = (int) (r.width * xscale);
      height = (int) (r.height * yscale);
    } else {
      xstr = "-";
      ystr = "-";
    }
    GenericDialog gd = new GenericDialog("Scale");
    gd.addStringField("X Scale (0.05-25):", xstr);
    gd.addStringField("Y Scale (0.05-25):", ystr);
    gd.setInsets(5, 0, 5);
    gd.addStringField("Width (pixels):", "" + width);
    gd.addStringField("Height (pixels):", "" + height);
    fields = gd.getStringFields();
    for (int i = 0; i < 3; i++) {
      ((TextField) fields.elementAt(i)).addTextListener(this);
      ((TextField) fields.elementAt(i)).addFocusListener(this);
    }
    xField = (TextField) fields.elementAt(0);
    yField = (TextField) fields.elementAt(1);
    widthField = (TextField) fields.elementAt(2);
    heightField = (TextField) fields.elementAt(3);
    fieldWithFocus = xField;
    gd.addCheckbox("Interpolate", interpolate);
    if (bitDepth == 8 || bitDepth == 24)
      gd.addCheckbox("Fill with Background Color", fillWithBackground);
    if (isStack) gd.addCheckbox("Process Entire Stack", processStack);
    gd.addCheckbox("Create New Window", newWindow);
    title = WindowManager.getUniqueName(imp.getTitle());
    gd.setInsets(10, 0, 0);
    gd.addStringField("Title:", title, 12);
    gd.showDialog();
    if (gd.wasCanceled()) return false;
    xstr = gd.getNextString();
    ystr = gd.getNextString();
    xscale = Tools.parseDouble(xstr, 0.0);
    yscale = Tools.parseDouble(ystr, 0.0);
    String wstr = gd.getNextString();
    newWidth = (int) Tools.parseDouble(wstr, 0);
    newHeight = (int) Tools.parseDouble(gd.getNextString(), 0);
    if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0")))
      newWidth = (int) (newHeight * (double) r.width / r.height);
    if (newWidth == 0 || newHeight == 0) {
      IJ.error("Invalid width or height entered");
      return false;
    }
    if (xscale > 25.0) xscale = 25.0;
    if (yscale > 25.0) yscale = 25.0;
    if (xscale > 0.0 && yscale > 0.0) {
      newWidth = (int) (r.width * xscale);
      newHeight = (int) (r.height * yscale);
    }
    interpolate = gd.getNextBoolean();
    if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean();
    if (isStack) processStack = gd.getNextBoolean();
    newWindow = gd.getNextBoolean();
    if (!newWindow && xscale == 0.0) {
      xscale = (double) newWidth / r.width;
      yscale = (double) newHeight / r.height;
    }
    title = gd.getNextString();

    if (fillWithBackground) {
      Color bgc = Toolbar.getBackgroundColor();
      if (bitDepth == 8) bgValue = ip.getBestIndex(bgc);
      else if (bitDepth == 24) bgValue = bgc.getRGB();
    } else {
      if (bitDepth == 8) bgValue = ip.isInvertedLut() ? 0.0 : 255.0; // white
      else if (bitDepth == 24) bgValue = 0xffffffff; // white
    }
    return true;
  }