Esempio n. 1
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
 /**
  * Sets the pixels, and min&max values from a FloatProcessor. Also the values are taken from the
  * FloatProcessor.
  *
  * @param channelNumber Ignored (needed for compatibility with ColorProcessor.toFloat)
  * @param fp The FloatProcessor where the image data are read from.
  */
 public void setPixels(int channelNumber, FloatProcessor fp) {
   if (fp.getPixels() != getPixels()) setPixels(fp.getPixels());
   setMinAndMax(fp.getMin(), fp.getMax());
 }