public AbstractSortedGrayLevelIterator(final Image<T> image) {
   this.image = image;
   this.position = image.createPositionArray();
   this.n = image.getNumPixels();
   this.maxIdx = this.n - 1;
   this.dimensions = image.getDimensions();
   createInternalCursor();
   this.sortedLinIdx = getLinearIndexArraySortedByGrayLevel();
   reset();
 }
Beispiel #2
0
  @Override
  public boolean process() {
    final long startTime = System.currentTimeMillis();

    final long imageSize = image.getNumPixels();

    final AtomicInteger ai = new AtomicInteger(0);
    final Thread[] threads = SimpleMultiThreading.newThreads(getNumThreads());

    final Vector<Chunk> threadChunks = SimpleMultiThreading.divideIntoChunks(imageSize, numThreads);

    final boolean isCompatible =
        image.getContainer().compareStorageContainerCompatibility(output.getContainer());

    for (int ithread = 0; ithread < threads.length; ++ithread)
      threads[ithread] =
          new Thread(
              new Runnable() {
                public void run() {
                  // Thread ID
                  final int myNumber = ai.getAndIncrement();

                  // get chunk of pixels to process
                  final Chunk myChunk = threadChunks.get(myNumber);

                  // check if all container types are comparable so that we can use simple iterators
                  // we assume transivity here
                  if (isCompatible) {
                    // we can simply use iterators
                    computeSimple(myChunk.getStartPosition(), myChunk.getLoopSize());
                  } else {
                    // we need a combination of Localizable and LocalizableByDim
                    computeAdvanced(myChunk.getStartPosition(), myChunk.getLoopSize());
                  }
                }
              });

    SimpleMultiThreading.startAndJoin(threads);

    processingTime = System.currentTimeMillis() - startTime;

    return true;
  }