private <T extends Comparable<T>> OutOfBounds<LabelingType<T>> makeOOB(
     final long[] dimensions, final long[][] coordinates, final List<T> values) {
   final Labeling<T> labeling =
       new NativeImgLabeling<T, IntType>(
           new ArrayImgFactory<IntType>().create(dimensions, new IntType()));
   final LabelingOutOfBoundsRandomAccessFactory<T, Labeling<T>> oobFactory =
       new LabelingOutOfBoundsRandomAccessFactory<T, Labeling<T>>();
   final OutOfBounds<LabelingType<T>> result = oobFactory.create(labeling);
   final RandomAccess<LabelingType<T>> ra = labeling.randomAccess();
   for (int i = 0; i < coordinates.length; i++) {
     ra.setPosition(coordinates[i]);
     ra.get().setLabel(values.get(i));
   }
   return result;
 }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public Labeling<L> compute(final RandomAccessibleInterval<T> op, final Labeling<L> r) {

    initRegionGrowing(op);

    final LinkedList<ValuePair<int[], L>> q = new LinkedList<ValuePair<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 ValuePair<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;
  }