Example #1
0
 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);
   }
 }
Example #2
0
  /** Called by the PlugInFilterRunner to process the image or one frame of a stack */
  public void run(ImageProcessor ip) {
    if (interrupted) return;
    int width = ip.getWidth();
    int height = ip.getHeight();

    int backgroundValue =
        (processType == VORONOI)
            ? (background255 ? 0 : (byte) 255)
            : // Voronoi needs EDM of the background
            (background255 ? (byte) 255 : 0); // all others do EDM of the foreground
    if (USES_WATERSHED[processType]) nPasses = 0; // watershed has its own progress bar
    FloatProcessor floatEdm = makeFloatEDM(ip, backgroundValue, false);

    ByteProcessor maxIp = null;
    if (USES_MAX_FINDER[processType]) {
      if (processType == VORONOI) floatEdm.multiply(-1); // Voronoi starts from minima of EDM
      int maxOutputType =
          USES_WATERSHED[processType] ? MaximumFinder.SEGMENTED : MaximumFinder.SINGLE_POINTS;
      boolean isEDM = processType != VORONOI;
      maxIp =
          maxFinder.findMaxima(
              floatEdm,
              MAXFINDER_TOLERANCE,
              ImageProcessor.NO_THRESHOLD,
              maxOutputType,
              false,
              isEDM);
      if (maxIp == null) { // segmentation cancelled by user?
        interrupted = true;
        return;
      } else if (processType != WATERSHED) {
        if (processType == VORONOI) floatEdm.multiply(-1);
        resetMasked(floatEdm, maxIp, processType == VORONOI ? -1 : 0);
      }
    }

    ImageProcessor outIp = null;
    if (processType == WATERSHED) {
      if (background255) maxIp.invert();
      ip.copyBits(maxIp, 0, 0, Blitter.COPY);
      ip.setBinaryThreshold();
    } else
      switch (outImageType) { // for all these, output contains the values of the EDM
        case FLOAT:
          outIp = floatEdm;
          break;
        case SHORT:
          floatEdm.setMinAndMax(0., 65535.);
          outIp = floatEdm.convertToShort(true);
          break;
        case BYTE:
          floatEdm.setMinAndMax(0., 255.);
          outIp = floatEdm.convertToByte(true);
          break;
        case BYTE_OVERWRITE:
          ip.setPixels(0, floatEdm);
          if (floatEdm.getMax() > 255.) ip.resetMinAndMax(); // otherwise we have max of floatEdm
      }

    if (outImageType != BYTE_OVERWRITE) { // new output image
      if (outStack == null) {
        outImp = new ImagePlus(TITLE_PREFIX[processType] + imp.getShortTitle(), outIp);
      } else outStack.setPixels(outIp.getPixels(), pfr.getSliceNumber());
    }
  } // public void run