Exemplo n.º 1
0
 void interpolate() {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Interpolate");
     return;
   }
   if (roi.getType() == Roi.POINT) return;
   if (IJ.isMacro() && Macro.getOptions() == null) Macro.setOptions("interval=1");
   GenericDialog gd = new GenericDialog("Interpolate");
   gd.addNumericField("Interval:", 1.0, 1, 4, "pixel");
   gd.addCheckbox("Smooth", IJ.isMacro() ? false : smooth);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   double interval = gd.getNextNumber();
   smooth = gd.getNextBoolean();
   Undo.setup(Undo.ROI, imp);
   FloatPolygon poly = roi.getInterpolatedPolygon(interval, smooth);
   int t = roi.getType();
   int type = roi.isLine() ? Roi.FREELINE : Roi.FREEROI;
   if (t == Roi.POLYGON && interval > 1.0) type = Roi.POLYGON;
   if ((t == Roi.RECTANGLE || t == Roi.OVAL || t == Roi.FREEROI) && interval >= 5.0)
     type = Roi.POLYGON;
   if ((t == Roi.LINE || t == Roi.FREELINE) && interval >= 5.0) type = Roi.POLYLINE;
   if (t == Roi.POLYLINE && interval >= 1.0) type = Roi.POLYLINE;
   ImageCanvas ic = imp.getCanvas();
   if (poly.npoints <= 150 && ic != null && ic.getMagnification() >= 12.0)
     type = roi.isLine() ? Roi.POLYLINE : Roi.POLYGON;
   Roi p = new PolygonRoi(poly, type);
   if (roi.getStroke() != null) p.setStrokeWidth(roi.getStrokeWidth());
   p.setStrokeColor(roi.getStrokeColor());
   p.setName(roi.getName());
   transferProperties(roi, p);
   imp.setRoi(p);
 }
Exemplo n.º 2
0
 /* Sets the LUT of the current channel. */
 public void setChannelLut(LUT table) {
   int c = getChannelIndex();
   double min = lut[c].min;
   double max = lut[c].max;
   lut[c] = table;
   lut[c].min = min;
   lut[c].max = max;
   if (mode == COMPOSITE && cip != null && c < cip.length) {
     cip[c].setColorModel(lut[c]);
     imageSource = null;
     newPixels = true;
     img = null;
   }
   currentChannel = -1;
   getProcessor().setLut(table);
   customLuts = true;
   if (!IJ.isMacro()) ContrastAdjuster.update();
 }
Exemplo n.º 3
0
 void checkForCalibrationConflict(ImagePlus imp, Calibration cal) {
   Calibration gcal = imp.getGlobalCalibration();
   if (gcal == null || !showConflictMessage || IJ.isMacro()) return;
   if (cal.pixelWidth == gcal.pixelWidth && cal.getUnit().equals(gcal.getUnit())) return;
   GenericDialog gd = new GenericDialog(imp.getTitle());
   gd.addMessage("The calibration of this image conflicts\nwith the current global calibration.");
   gd.addCheckbox("Disable_Global Calibration", true);
   gd.addCheckbox("Disable_these Messages", false);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   boolean disable = gd.getNextBoolean();
   if (disable) {
     imp.setGlobalCalibration(null);
     imp.setCalibration(cal);
     WindowManager.repaintImageWindows();
   }
   boolean dontShow = gd.getNextBoolean();
   if (dontShow) showConflictMessage = false;
 }
Exemplo n.º 4
0
  public synchronized void updateImage() {
    int imageSize = width * height;
    int nChannels = getNChannels();
    int redValue, greenValue, blueValue;
    int ch = getChannel();

    // IJ.log("updateImage: "+ch+"/"+nChannels+" "+currentSlice+" "+currentFrame);
    if (ch > nChannels) ch = nChannels;
    boolean newChannel = false;
    if (ch - 1 != currentChannel) {
      previousChannel = currentChannel;
      currentChannel = ch - 1;
      newChannel = true;
    }

    ImageProcessor ip = getProcessor();
    if (mode != COMPOSITE) {
      if (newChannel) {
        setupLuts(nChannels);
        LUT cm = lut[currentChannel];
        if (mode == COLOR) ip.setColorModel(cm);
        if (!(cm.min == 0.0 && cm.max == 0.0)) ip.setMinAndMax(cm.min, cm.max);
        if (!IJ.isMacro()) ContrastAdjuster.update();
        for (int i = 0; i < MAX_CHANNELS; i++) active[i] = i == currentChannel ? true : false;
        Channels.updateChannels();
      }
      if (ip != null) img = ip.createImage();
      return;
    }

    if (nChannels == 1) {
      cip = null;
      rgbPixels = null;
      awtImage = null;
      if (ip != null) img = ip.createImage();
      return;
    }

    if (cip == null
        || cip[0].getWidth() != width
        || cip[0].getHeight() != height
        || getBitDepth() != bitDepth) {
      setup(nChannels, getImageStack());
      rgbPixels = null;
      rgbSampleModel = null;
      if (currentChannel >= nChannels) {
        setSlice(1);
        currentChannel = 0;
        newChannel = true;
      }
      bitDepth = getBitDepth();
    }

    if (newChannel) {
      getProcessor().setMinAndMax(cip[currentChannel].getMin(), cip[currentChannel].getMax());
      if (!IJ.isMacro()) ContrastAdjuster.update();
    }
    // IJ.log(nChannels+" "+ch+" "+currentChannel+"  "+newChannel);

    if (getSlice() != currentSlice || getFrame() != currentFrame) {
      currentSlice = getSlice();
      currentFrame = getFrame();
      int position = getStackIndex(1, currentSlice, currentFrame);
      if (cip == null) return;
      for (int i = 0; i < nChannels; ++i)
        cip[i].setPixels(getImageStack().getProcessor(position + i).getPixels());
    }

    if (rgbPixels == null) {
      rgbPixels = new int[imageSize];
      newPixels = true;
      imageSource = null;
      rgbRaster = null;
      rgbImage = null;
    }
    cip[currentChannel].setMinAndMax(ip.getMin(), ip.getMax());
    if (singleChannel && nChannels <= 3) {
      switch (currentChannel) {
        case 0:
          cip[0].updateComposite(rgbPixels, 1);
          break;
        case 1:
          cip[1].updateComposite(rgbPixels, 2);
          break;
        case 2:
          cip[2].updateComposite(rgbPixels, 3);
          break;
      }
    } else {
      if (cip == null) return;
      if (syncChannels) {
        ImageProcessor ip2 = getProcessor();
        double min = ip2.getMin(), max = ip2.getMax();
        for (int i = 0; i < nChannels; i++) {
          cip[i].setMinAndMax(min, max);
          lut[i].min = min;
          lut[i].max = max;
        }
        syncChannels = false;
      }
      if (active[0]) cip[0].updateComposite(rgbPixels, 4);
      else {
        for (int i = 1; i < imageSize; i++) rgbPixels[i] = 0;
      }
      if (cip == null || nChannels > cip.length) return;
      for (int i = 1; i < nChannels; i++) if (active[i]) cip[i].updateComposite(rgbPixels, 5);
    }
    if (IJ.isJava16()) createBufferedImage();
    else createImage();
    if (img == null && awtImage != null) img = awtImage;
    singleChannel = false;
  }