コード例 #1
0
ファイル: ImageConverter.java プロジェクト: alex-krull/fiji
  protected void computeAdvanced(final long startPos, final long loopSize) {
    final LocalizableByDimCursor<S> cursorIn = image.createLocalizableByDimCursor();
    final LocalizableCursor<T> cursorOut = output.createLocalizableCursor();

    // move to the starting position of the current thread
    cursorOut.fwd(startPos);

    // do as many pixels as wanted by this thread
    for (long j = 0; j < loopSize; ++j) {
      cursorOut.fwd();
      cursorIn.setPosition(cursorOut);

      converter.convert(cursorIn.getType(), cursorOut.getType());
    }

    cursorIn.close();
    cursorOut.close();
  }
コード例 #2
0
  @Override
  public boolean process() {
    floatImage = null;
    if (output == null) {
      output = new Labeling<L>(labelingFactory, input.getDimensions(), null);
    } else {
      /*
       * Initialize the output to all background
       */
      LocalizableCursor<LabelingType<L>> c = output.createLocalizableCursor();
      List<L> background = c.getType().intern(new ArrayList<L>());
      for (LabelingType<L> t : c) {
        t.setLabeling(background);
      }
      c.close();
    }
    /*
     * Get the smoothed image.
     */
    Image<FloatType> kernel =
        FourierConvolution.createGaussianKernel(input.getContainerFactory(), scale);
    FourierConvolution<FloatType, FloatType> convolution =
        new FourierConvolution<FloatType, FloatType>(getFloatImage(), kernel);
    if (!convolution.process()) return false;
    Image<FloatType> smoothed = convolution.getResult();

    /*
     * Find the local maxima and label them individually.
     */
    PickImagePeaks<FloatType> peakPicker = new PickImagePeaks<FloatType>(smoothed);
    peakPicker.setSuppression(scale);
    peakPicker.process();
    Labeling<L> seeds = output.createNewLabeling();
    LocalizableByDimCursor<LabelingType<L>> lc = seeds.createLocalizableByDimCursor();
    LocalizableByDimCursor<FloatType> imageCursor = smoothed.createLocalizableByDimCursor();
    int[] dimensions = input.getDimensions();
    for (int[] peak : peakPicker.getPeakList()) {
      if (!filterPeak(imageCursor, peak, dimensions, false)) continue;
      lc.setPosition(peak);
      lc.getType().setLabel(names.next());
    }
    imageCursor.close();
    /*
     * Find the local minima and label them all the same.
     */
    List<L> background = lc.getType().intern(names.next());
    Converter<FloatType, FloatType> invert =
        new Converter<FloatType, FloatType>() {

          @Override
          public void convert(FloatType input, FloatType output) {
            output.setReal(-input.getRealFloat());
          }
        };
    ImageConverter<FloatType, FloatType> invSmoothed =
        new ImageConverter<FloatType, FloatType>(smoothed, smoothed, invert);
    invSmoothed.process();
    peakPicker = new PickImagePeaks<FloatType>(smoothed);
    peakPicker.setSuppression(scale);
    peakPicker.process();
    imageCursor = smoothed.createLocalizableByDimCursor();
    for (int[] peak : peakPicker.getPeakList()) {
      if (!filterPeak(imageCursor, peak, dimensions, true)) continue;
      lc.setPosition(peak);
      lc.getType().setLabeling(background);
    }
    lc.close();
    imageCursor.close();
    smoothed = null;
    invSmoothed = null;
    Image<FloatType> gradientImage = getGradientImage();
    if (gradientImage == null) return false;
    /*
     * Run the seeded watershed on the image.
     */
    Watershed.seededWatershed(gradientImage, seeds, structuringElement, output);
    return true;
  }