/** {@inheritDoc} */
  @Override
  public LL compute(I op, LL r) {

    initRegionGrowing(op);

    final LinkedList<Pair<int[], L>> q = new LinkedList<Pair<int[], L>>();

    // image and random access to keep track of the already visited
    // pixel
    // positions
    if (m_allowOverlap) {
      NativeImgLabeling<L, IntType> tmp =
          new NativeImgLabeling<L, IntType>(
              new ArrayImgFactory<IntType>().create(resultDims(op), new IntType()));
      m_visitedLabRA = tmp.randomAccess();
    } else {
      BitType bt = new BitType();
      Img<BitType> tmp = null;
      try {
        tmp = new ArrayImgFactory<BitType>().imgFactory(bt).create(op, bt);
      } catch (IncompatibleTypeException e) {
        //
      }
      m_visitedRA = tmp.randomAccess();
    }

    // access to the resulting labeling
    RandomAccess<LabelingType<L>> resRA = r.randomAccess();

    L label;
    int[] pos = new int[op.numDimensions()];
    do {
      while ((label = nextSeedPosition(pos)) != null) {

        // already visited?
        setVisitedPosition(pos);
        if (isMarkedAsVisited(label)) {
          continue;
        }
        markAsVisited(label);

        q.addLast(new Pair<int[], L>(pos.clone(), label));

        // set new labeling
        resRA.setPosition(pos);
        setLabel(resRA, label);

        if (m_mode == GrowingMode.ASYNCHRONOUS) {
          growProcess(q, resRA, op);
        }
      }
      if (m_mode == GrowingMode.SYNCHRONOUS) {
        growProcess(q, resRA, op);
      }
    } while (hasMoreSeedingPoints());

    return r;
  }
Exemplo n.º 2
0
  /**
   * create the output based on the input. If fast=true the size is determined such that the
   * underlying FFT implementation will run as fast as possible. If fast=false the size is
   * determined such that the underlying FFT implementation will use the smallest amount of memory
   * possible.
   */
  @Override
  public O createOutput(I input) {

    long[] inputSize = new long[input.numDimensions()];

    for (int d = 0; d < input.numDimensions(); d++) {
      inputSize[d] = input.dimension(d);

      if (borderSize != null) {
        inputSize[d] += borderSize[d];
      }
    }

    if (fast) {
      computeFFTFastSize(inputSize);
    } else {
      computeFFTSmallSize(inputSize);
    }

    return createFFTImg(input.factory());
  }