コード例 #1
0
ファイル: SpecifyROI.java プロジェクト: dannyZhou/imagej
 boolean validDialogValues() {
   Calibration cal = imp.getCalibration();
   double pw = cal.pixelWidth, ph = cal.pixelHeight;
   if (width / pw < 1 || height / ph < 1) return false;
   if (xRoi / pw > imp.getWidth() || yRoi / ph > imp.getHeight()) return false;
   return true;
 }
コード例 #2
0
ファイル: Selection.java プロジェクト: dannyZhou/imagej
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   Undo.setup(Undo.ROI, imp);
   Roi roi2 = null;
   if (roi.getType() == Roi.LINE) {
     double width = roi.getStrokeWidth();
     if (width <= 1.0) roi.setStrokeWidth(1.0000001);
     FloatPolygon p = roi.getFloatPolygon();
     roi.setStrokeWidth(width);
     roi2 = new PolygonRoi(p, Roi.POLYGON);
     roi2.setDrawOffset(roi.getDrawOffset());
   } else {
     ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
     ip2.setColor(255);
     roi.drawPixels(ip2);
     // new ImagePlus("ip2", ip2.duplicate()).show();
     ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
     ThresholdToSelection tts = new ThresholdToSelection();
     roi2 = tts.convert(ip2);
   }
   transferProperties(roi, roi2);
   roi2.setStrokeWidth(0);
   Color c = roi2.getStrokeColor();
   if (c != null) // remove any transparency
   roi2.setStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue()));
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
コード例 #3
0
ファイル: StackReducer.java プロジェクト: dannyZhou/imagej
 public void reduceHyperstack(ImagePlus imp, int factor, boolean reduceSlices) {
   int channels = imp.getNChannels();
   int slices = imp.getNSlices();
   int frames = imp.getNFrames();
   int zfactor = reduceSlices ? factor : 1;
   int tfactor = reduceSlices ? 1 : factor;
   ImageStack stack = imp.getStack();
   ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight());
   boolean virtual = stack.isVirtual();
   int slices2 = slices / zfactor + ((slices % zfactor) != 0 ? 1 : 0);
   int frames2 = frames / tfactor + ((frames % tfactor) != 0 ? 1 : 0);
   int n = channels * slices2 * frames2;
   int count = 1;
   for (int t = 1; t <= frames; t += tfactor) {
     for (int z = 1; z <= slices; z += zfactor) {
       for (int c = 1; c <= channels; c++) {
         int i = imp.getStackIndex(c, z, t);
         IJ.showProgress(i, n);
         ImageProcessor ip = stack.getProcessor(imp.getStackIndex(c, z, t));
         // IJ.log(count++ +"  "+i+" "+c+" "+z+" "+t);
         stack2.addSlice(stack.getSliceLabel(i), ip);
       }
     }
   }
   imp.setStack(stack2, channels, slices2, frames2);
   Calibration cal = imp.getCalibration();
   if (cal.scaled()) cal.pixelDepth *= zfactor;
   if (virtual) imp.setTitle(imp.getTitle());
   IJ.showProgress(1.0);
 }
コード例 #4
0
  /*------------------------------------------------------------------*/
  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 */
コード例 #5
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 public void run(String arg) {
   imp = WindowManager.getCurrentImage();
   if (arg.equals("add")) {
     addToRoiManager(imp);
     return;
   }
   if (imp == null) {
     IJ.noImage();
     return;
   }
   if (arg.equals("all")) imp.setRoi(0, 0, imp.getWidth(), imp.getHeight());
   else if (arg.equals("none")) imp.killRoi();
   else if (arg.equals("restore")) imp.restoreRoi();
   else if (arg.equals("spline")) fitSpline();
   else if (arg.equals("circle")) fitCircle(imp);
   else if (arg.equals("ellipse")) createEllipse(imp);
   else if (arg.equals("hull")) convexHull(imp);
   else if (arg.equals("mask")) createMask(imp);
   else if (arg.equals("from")) createSelectionFromMask(imp);
   else if (arg.equals("inverse")) invert(imp);
   else if (arg.equals("toarea")) lineToArea(imp);
   else if (arg.equals("toline")) areaToLine(imp);
   else if (arg.equals("properties")) {
     setProperties("Properties ", imp.getRoi());
     imp.draw();
   } else if (arg.equals("band")) makeBand(imp);
   else if (arg.equals("tobox")) toBoundingBox(imp);
   else runMacro(arg);
 }
コード例 #6
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   if (roi.getType() == Roi.LINE && roi.getStrokeWidth() == 1) {
     IJ.error("Line to Area", "Straight line width must be > 1");
     return;
   }
   ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
   ip2.setColor(255);
   if (roi.getType() == Roi.LINE) ip2.fillPolygon(roi.getPolygon());
   else {
     roi.drawPixels(ip2);
     // BufferedImage bi = new BufferedImage(imp.getWidth(), imp.getHeight(),
     // BufferedImage.TYPE_BYTE_GRAY);
     // Graphics g = bi.getGraphics();
     // Roi roi2 = (Roi)roi.clone();
     // roi2.setStrokeColor(Color.white);
     // roi2.drawOverlay(g);
     // ip2 = new ByteProcessor(bi);
   }
   // new ImagePlus("ip2", ip2.duplicate()).show();
   ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   ThresholdToSelection tts = new ThresholdToSelection();
   Roi roi2 = tts.convert(ip2);
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
コード例 #7
0
ファイル: ZProjector.java プロジェクト: halirutan/imagej1
  /** Generate output image whose type is same as input image. */
  private ImagePlus makeOutputImage(ImagePlus imp, FloatProcessor fp, int ptype) {
    int width = imp.getWidth();
    int height = imp.getHeight();
    float[] pixels = (float[]) fp.getPixels();
    ImageProcessor oip = null;

    // Create output image consistent w/ type of input image.
    int size = pixels.length;
    switch (ptype) {
      case BYTE_TYPE:
        oip = imp.getProcessor().createProcessor(width, height);
        byte[] pixels8 = (byte[]) oip.getPixels();
        for (int i = 0; i < size; i++) pixels8[i] = (byte) pixels[i];
        break;
      case SHORT_TYPE:
        oip = imp.getProcessor().createProcessor(width, height);
        short[] pixels16 = (short[]) oip.getPixels();
        for (int i = 0; i < size; i++) pixels16[i] = (short) pixels[i];
        break;
      case FLOAT_TYPE:
        oip = new FloatProcessor(width, height, pixels, null);
        break;
    }

    // Adjust for display.
    // Calling this on non-ByteProcessors ensures image
    // processor is set up to correctly display image.
    oip.resetMinAndMax();

    // Create new image plus object. Don't use
    // ImagePlus.createImagePlus here because there may be
    // attributes of input image that are not appropriate for
    // projection.
    return new ImagePlus(makeTitle(), oip);
  }
コード例 #8
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 void createMask(ImagePlus imp) {
   Roi roi = imp.getRoi();
   boolean useInvertingLut = Prefs.useInvertingLut;
   Prefs.useInvertingLut = false;
   if (roi == null || !(roi.isArea() || roi.getType() == Roi.POINT)) {
     createMaskFromThreshold(imp);
     Prefs.useInvertingLut = useInvertingLut;
     return;
   }
   ImagePlus maskImp = null;
   Frame frame = WindowManager.getFrame("Mask");
   if (frame != null && (frame instanceof ImageWindow))
     maskImp = ((ImageWindow) frame).getImagePlus();
   if (maskImp == null) {
     ImageProcessor ip = new ByteProcessor(imp.getWidth(), imp.getHeight());
     if (!Prefs.blackBackground) ip.invertLut();
     maskImp = new ImagePlus("Mask", ip);
     maskImp.show();
   }
   ImageProcessor ip = maskImp.getProcessor();
   ip.setRoi(roi);
   ip.setValue(255);
   ip.fill(ip.getMask());
   maskImp.updateAndDraw();
   Prefs.useInvertingLut = useInvertingLut;
 }
コード例 #9
0
ファイル: Grid_.java プロジェクト: RichardMyers/fiji-1
 void showDialog() {
   int width = imp.getWidth();
   int height = imp.getHeight();
   Calibration cal = imp.getCalibration();
   int places;
   if (cal.scaled()) {
     pixelWidth = cal.pixelWidth;
     pixelHeight = cal.pixelHeight;
     units = cal.getUnits();
     places = 2;
   } else {
     pixelWidth = 1.0;
     pixelHeight = 1.0;
     units = "pixels";
     places = 0;
   }
   if (areaPerPoint == 0.0)
     areaPerPoint =
         (width * cal.pixelWidth * height * cal.pixelHeight) / 81.0; // default to 9x9 grid
   ImageWindow win = imp.getWindow();
   GenericDialog gd = new GenericDialog("Grid...");
   gd.addChoice("Grid Type:", types, type);
   gd.addNumericField("Area per Point:", areaPerPoint, places, 6, units + "^2");
   gd.addChoice("Color:", colors, color);
   gd.addCheckbox("Random Offset", randomOffset);
   gd.addDialogListener(this);
   gd.showDialog();
   if (gd.wasCanceled()) showGrid(null);
 }
コード例 #10
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;
   }
 }
コード例 #11
0
 void updateImage(ImagePlus imp) {
   this.imp = imp;
   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;
 }
コード例 #12
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;
  }
コード例 #13
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...");
 }
コード例 #14
0
 public static ImageStack getChannel(ImagePlus imp, int c) {
   ImageStack stack1 = imp.getStack();
   ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight());
   for (int t = 1; t <= imp.getNFrames(); t++) {
     for (int z = 1; z <= imp.getNSlices(); z++) {
       int n = imp.getStackIndex(c, z, t);
       stack2.addSlice(stack1.getProcessor(n));
     }
   }
   return stack2;
 }
コード例 #15
0
ファイル: ZProjector.java プロジェクト: halirutan/imagej1
  /** Performs actual projection using specified method. */
  public void doProjection() {
    if (imp == null) return;
    sliceCount = 0;
    if (method < AVG_METHOD || method > MEDIAN_METHOD) method = AVG_METHOD;
    for (int slice = startSlice; slice <= stopSlice; slice += increment) sliceCount++;
    if (method == MEDIAN_METHOD) {
      projImage = doMedianProjection();
      return;
    }

    // Create new float processor for projected pixels.
    FloatProcessor fp = new FloatProcessor(imp.getWidth(), imp.getHeight());
    ImageStack stack = imp.getStack();
    RayFunction rayFunc = getRayFunction(method, fp);
    if (IJ.debugMode == true) {
      IJ.log("\nProjecting stack from: " + startSlice + " to: " + stopSlice);
    }

    // Determine type of input image. Explicit determination of
    // processor type is required for subsequent pixel
    // manipulation.  This approach is more efficient than the
    // more general use of ImageProcessor's getPixelValue and
    // putPixel methods.
    int ptype;
    if (stack.getProcessor(1) instanceof ByteProcessor) ptype = BYTE_TYPE;
    else if (stack.getProcessor(1) instanceof ShortProcessor) ptype = SHORT_TYPE;
    else if (stack.getProcessor(1) instanceof FloatProcessor) ptype = FLOAT_TYPE;
    else {
      IJ.error("Z Project", "Non-RGB stack required");
      return;
    }

    // Do the projection.
    for (int n = startSlice; n <= stopSlice; n += increment) {
      IJ.showStatus("ZProjection " + color + ": " + n + "/" + stopSlice);
      IJ.showProgress(n - startSlice, stopSlice - startSlice);
      projectSlice(stack.getPixels(n), rayFunc, ptype);
    }

    // Finish up projection.
    if (method == SUM_METHOD) {
      fp.resetMinAndMax();
      projImage = new ImagePlus(makeTitle(), fp);
    } else if (method == SD_METHOD) {
      rayFunc.postProcess();
      fp.resetMinAndMax();
      projImage = new ImagePlus(makeTitle(), fp);
    } else {
      rayFunc.postProcess();
      projImage = makeOutputImage(imp, fp, ptype);
    }

    if (projImage == null) IJ.error("Z Project", "Error computing projection.");
  }
コード例 #16
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 void invert(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isArea()) {
     IJ.error("Inverse", "Area selection required");
     return;
   }
   ShapeRoi s1, s2;
   if (roi instanceof ShapeRoi) s1 = (ShapeRoi) roi;
   else s1 = new ShapeRoi(roi);
   s2 = new ShapeRoi(new Roi(0, 0, imp.getWidth(), imp.getHeight()));
   imp.setRoi(s1.xor(s2));
 }
コード例 #17
0
ファイル: Rotator.java プロジェクト: AlexJoz/docuensj
 public int setup(String arg, ImagePlus imp) {
   this.imp = imp;
   if (imp != null) {
     bitDepth = imp.getBitDepth();
     Roi roi = imp.getRoi();
     Rectangle r = roi != null ? roi.getBounds() : null;
     canEnlarge =
         r == null
             || (r.x == 0 && r.y == 0 && r.width == imp.getWidth() && r.height == imp.getHeight());
   }
   return flags;
 }
コード例 #18
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;
 }
コード例 #19
0
 protected void handleRoiMouseDown(MouseEvent e) {
   int sx = e.getX();
   int sy = e.getY();
   int ox = offScreenX(sx);
   int oy = offScreenY(sy);
   Roi roi = imp.getRoi();
   int handle = roi != null ? roi.isHandle(sx, sy) : -1;
   boolean multiPointMode =
       roi != null
           && (roi instanceof PointRoi)
           && handle == -1
           && Toolbar.getToolId() == Toolbar.POINT
           && Toolbar.getMultiPointMode();
   if (multiPointMode) {
     imp.setRoi(((PointRoi) roi).addPoint(ox, oy));
     return;
   }
   setRoiModState(e, roi, handle);
   if (roi != null) {
     if (handle >= 0) {
       roi.mouseDownInHandle(handle, sx, sy);
       return;
     }
     Rectangle r = roi.getBounds();
     int type = roi.getType();
     if (type == Roi.RECTANGLE
         && r.width == imp.getWidth()
         && r.height == imp.getHeight()
         && roi.getPasteMode() == Roi.NOT_PASTING
         && !(roi instanceof ImageRoi)) {
       imp.killRoi();
       return;
     }
     if (roi.contains(ox, oy)) {
       if (roi.modState == Roi.NO_MODS) roi.handleMouseDown(sx, sy);
       else {
         imp.killRoi();
         imp.createNewRoi(sx, sy);
       }
       return;
     }
     if ((type == Roi.POLYGON || type == Roi.POLYLINE || type == Roi.ANGLE)
         && roi.getState() == roi.CONSTRUCTING) return;
     int tool = Toolbar.getToolId();
     if ((tool == Toolbar.POLYGON || tool == Toolbar.POLYLINE || tool == Toolbar.ANGLE)
         && !(IJ.shiftKeyDown() || IJ.altKeyDown())) {
       imp.killRoi();
       return;
     }
   }
   imp.createNewRoi(sx, sy);
 }
コード例 #20
0
ファイル: Selection.java プロジェクト: dannyZhou/imagej
 void createMask(ImagePlus imp) {
   Roi roi = imp.getRoi();
   boolean useInvertingLut = Prefs.useInvertingLut;
   Prefs.useInvertingLut = false;
   boolean selectAll =
       roi != null
           && roi.getType() == Roi.RECTANGLE
           && roi.getBounds().width == imp.getWidth()
           && roi.getBounds().height == imp.getHeight()
           && imp.isThreshold();
   if (roi == null || !(roi.isArea() || roi.getType() == Roi.POINT) || selectAll) {
     createMaskFromThreshold(imp);
     Prefs.useInvertingLut = useInvertingLut;
     return;
   }
   ImagePlus maskImp = null;
   Frame frame = WindowManager.getFrame("Mask");
   if (frame != null && (frame instanceof ImageWindow))
     maskImp = ((ImageWindow) frame).getImagePlus();
   if (maskImp == null) {
     ImageProcessor ip = new ByteProcessor(imp.getWidth(), imp.getHeight());
     if (!Prefs.blackBackground) ip.invertLut();
     maskImp = new ImagePlus("Mask", ip);
     maskImp.show();
   }
   ImageProcessor ip = maskImp.getProcessor();
   ip.setRoi(roi);
   ip.setValue(255);
   ip.fill(ip.getMask());
   Calibration cal = imp.getCalibration();
   if (cal.scaled()) {
     Calibration cal2 = maskImp.getCalibration();
     cal2.pixelWidth = cal.pixelWidth;
     cal2.pixelHeight = cal.pixelHeight;
     cal2.setUnit(cal.getUnit());
   }
   maskImp.updateAndRepaintWindow();
   Prefs.useInvertingLut = useInvertingLut;
 }
コード例 #21
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);
 }
コード例 #22
0
ファイル: Grid_.java プロジェクト: RichardMyers/fiji-1
 void drawLines() {
   GeneralPath path = new GeneralPath();
   int width = imp.getWidth();
   int height = imp.getHeight();
   for (int i = 0; i < linesV; i++) {
     float xoff = (float) (xstart + i * tileWidth);
     path.moveTo(xoff, 0f);
     path.lineTo(xoff, height);
   }
   for (int i = 0; i < linesH; i++) {
     float yoff = (float) (ystart + i * tileHeight);
     path.moveTo(0f, yoff);
     path.lineTo(width, yoff);
   }
   showGrid(path);
 }
コード例 #23
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
   ip2.setColor(255);
   if (roi.getType() == Roi.LINE && roi.getStrokeWidth() > 1) ip2.fillPolygon(roi.getPolygon());
   else roi.drawPixels(ip2);
   // new ImagePlus("ip2", ip2.duplicate()).show();
   ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   ThresholdToSelection tts = new ThresholdToSelection();
   Roi roi2 = tts.convert(ip2);
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
コード例 #24
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);
 }
コード例 #25
0
ファイル: ZProjector.java プロジェクト: halirutan/imagej1
 public void doHyperStackProjection(boolean allTimeFrames) {
   int start = startSlice;
   int stop = stopSlice;
   int firstFrame = 1;
   int lastFrame = imp.getNFrames();
   if (!allTimeFrames) firstFrame = lastFrame = imp.getFrame();
   ImageStack stack = new ImageStack(imp.getWidth(), imp.getHeight());
   int channels = imp.getNChannels();
   int slices = imp.getNSlices();
   if (slices == 1) {
     slices = imp.getNFrames();
     firstFrame = lastFrame = 1;
   }
   int frames = lastFrame - firstFrame + 1;
   increment = channels;
   boolean rgb = imp.getBitDepth() == 24;
   for (int frame = firstFrame; frame <= lastFrame; frame++) {
     for (int channel = 1; channel <= channels; channel++) {
       startSlice = (frame - 1) * channels * slices + (start - 1) * channels + channel;
       stopSlice = (frame - 1) * channels * slices + (stop - 1) * channels + channel;
       if (rgb) doHSRGBProjection(imp);
       else doProjection();
       stack.addSlice(null, projImage.getProcessor());
     }
   }
   projImage = new ImagePlus(makeTitle(), stack);
   projImage.setDimensions(channels, 1, frames);
   if (channels > 1) {
     projImage = new CompositeImage(projImage, 0);
     ((CompositeImage) projImage).copyLuts(imp);
     if (method == SUM_METHOD || method == SD_METHOD)
       ((CompositeImage) projImage).resetDisplayRanges();
   }
   if (frames > 1) projImage.setOpenAsHyperStack(true);
   Overlay overlay = imp.getOverlay();
   if (overlay != null) {
     startSlice = start;
     stopSlice = stop;
     if (imp.getType() == ImagePlus.COLOR_RGB)
       projImage.setOverlay(projectRGBHyperStackRois(overlay));
     else projImage.setOverlay(projectHyperStackRois(overlay));
   }
   IJ.showProgress(1, 1);
 }
コード例 #26
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 // Finds the index of the upper right point that is guaranteed to be on convex hull
 int findFirstPoint(int[] xCoordinates, int[] yCoordinates, int n, ImagePlus imp) {
   int smallestY = imp.getHeight();
   int x, y;
   for (int i = 0; i < n; i++) {
     y = yCoordinates[i];
     if (y < smallestY) smallestY = y;
   }
   int smallestX = imp.getWidth();
   int p1 = 0;
   for (int i = 0; i < n; i++) {
     x = xCoordinates[i];
     y = yCoordinates[i];
     if (y == smallestY && x < smallestX) {
       smallestX = x;
       p1 = i;
     }
   }
   return p1;
 }
コード例 #27
0
ファイル: Rotator.java プロジェクト: AlexJoz/docuensj
 void drawGridLines(int lines) {
   ImageCanvas ic = imp.getCanvas();
   if (ic == null) return;
   if (lines == 0) {
     ic.setDisplayList(null);
     return;
   }
   GeneralPath path = new GeneralPath();
   float width = imp.getWidth();
   float height = imp.getHeight();
   float xinc = width / lines;
   float yinc = height / lines;
   float xstart = xinc / 2f;
   float ystart = yinc / 2f;
   for (int i = 0; i < lines; i++) {
     path.moveTo(xstart + xinc * i, 0f);
     path.lineTo(xstart + xinc * i, height);
     path.moveTo(0f, ystart + yinc * i);
     path.lineTo(width, ystart + yinc * i);
   }
   ic.setDisplayList(path, null, null);
 }
コード例 #28
0
ファイル: ObjectManager.java プロジェクト: cmci/tango
  public void showRois3D() {
    registerActiveImage();
    if (currentImage == null) return;
    // verifier que l'image active a les memes dimentions
    Object[] os = this.list.getSelectedValues();

    if (os.length == 1) {
      mcib3d.geom.Object3D o = ((Object3DGui) os[0]).getObject3D();
      currentImage.setSlice((o.getZmax() + o.getZmin()) / 2 + 1);
    }
    int nSlices = currentImage.getNSlices();

    currentROIs = new HashMap<Integer, Roi>(nSlices);
    // stores the roi mask to save memory..
    if (roiMask == null || !roiMask.sameDimentions(currentImage)) {
      roiMask = new ImageByte("mask", currentImage.getWidth(), currentImage.getHeight(), nSlices);
    } else {
      roiMask.erase();
    }
    ImageStack maskStack = roiMask.getImageStack();
    Object3DGui obj;
    for (Object o : os) {
      obj = (Object3DGui) o;
      obj.getObject3D().draw(maskStack, 255);
    }
    // roiMask.show();

    for (int i = 1; i <= nSlices; i++) {
      ImagePlus im = new ImagePlus("mask", maskStack.getProcessor(i));
      im.getProcessor().setThreshold(1, 255, ImageProcessor.NO_LUT_UPDATE);
      ThresholdToSelection tts = new ThresholdToSelection();
      tts.setup("", im);
      tts.run(im.getProcessor());
      Roi r = im.getRoi();
      if (r != null) currentROIs.put(i, r);
    }
    updateRoi();
  }
コード例 #29
0
ファイル: Grid_.java プロジェクト: RichardMyers/fiji-1
  public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
    int width = imp.getWidth();
    int height = imp.getHeight();
    type = gd.getNextChoice();
    areaPerPoint = gd.getNextNumber();
    color = gd.getNextChoice();
    randomOffset = gd.getNextBoolean();

    double minArea = (width * height) / 50000.0;
    if (type.equals(types[1]) && minArea < 144.0) minArea = 144.0;
    else if (minArea < 16) minArea = 16.0;
    if (areaPerPoint / (pixelWidth * pixelHeight) < minArea) {
      String err = "\"Area per Point\" too small";
      if (gd.wasOKed()) IJ.error("Grid", err);
      else IJ.showStatus(err);
      return true;
    }
    double tileSize = Math.sqrt(areaPerPoint);
    tileWidth = tileSize / pixelWidth;
    tileHeight = tileSize / pixelHeight;
    if (randomOffset) {
      xstart = (int) (random.nextDouble() * tileWidth);
      ystart = (int) (random.nextDouble() * tileHeight);
    } else {
      xstart = (int) (tileWidth / 2.0 + 0.5);
      ystart = (int) (tileHeight / 2.0 + 0.5);
    }
    linesV = (int) ((width - xstart) / tileWidth) + 1;
    linesH = (int) ((height - ystart) / tileHeight) + 1;
    if (gd.invalidNumber()) return true;
    if (type.equals(types[0])) drawLines();
    else if (type.equals(types[1])) drawCrosses();
    else if (type.equals(types[2])) drawPoints();
    else showGrid(null);
    return true;
  }
コード例 #30
0
 /** Splits the specified image into separate channels. */
 public static ImagePlus[] split(ImagePlus imp) {
   if (imp.getType() == ImagePlus.COLOR_RGB) {
     ImageStack[] stacks = splitRGB(imp.getStack(), true);
     ImagePlus[] images = new ImagePlus[3];
     images[0] = new ImagePlus("red", stacks[0]);
     images[1] = new ImagePlus("green", stacks[1]);
     images[2] = new ImagePlus("blue", stacks[2]);
     return images;
   }
   int width = imp.getWidth();
   int height = imp.getHeight();
   int channels = imp.getNChannels();
   int slices = imp.getNSlices();
   int frames = imp.getNFrames();
   int bitDepth = imp.getBitDepth();
   int size = slices * frames;
   Vector images = new Vector();
   HyperStackReducer reducer = new HyperStackReducer(imp);
   for (int c = 1; c <= channels; c++) {
     ImageStack stack2 = new ImageStack(width, height, size); // create empty stack
     stack2.setPixels(
         imp.getProcessor().getPixels(), 1); // can't create ImagePlus will null 1st image
     ImagePlus imp2 = new ImagePlus("C" + c + "-" + imp.getTitle(), stack2);
     stack2.setPixels(null, 1);
     imp.setPosition(c, 1, 1);
     imp2.setDimensions(1, slices, frames);
     imp2.setCalibration(imp.getCalibration());
     reducer.reduce(imp2);
     if (imp.isComposite() && ((CompositeImage) imp).getMode() == IJ.GRAYSCALE)
       IJ.run(imp2, "Grays", "");
     if (imp2.getNDimensions() > 3) imp2.setOpenAsHyperStack(true);
     images.add(imp2);
   }
   ImagePlus[] array = new ImagePlus[images.size()];
   return (ImagePlus[]) images.toArray(array);
 }