Java Code Examples for net.imglib2.view.Views#extendBorder()

The following examples show how to use net.imglib2.view.Views#extendBorder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AffineWarpField.java    From render with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Logic stolen from
 * <a href='https://github.com/trakem2/TrakEM2/blob/master/TrakEM2_/src/main/java/org/janelia/intensity/LinearIntensityMap.java'>
 *   TrakEM2 LinearIntensityMap
 * </a>.
 *
 * @return an accessor for deriving warped pixel intensities.
 */
public RealRandomAccess<RealComposite<DoubleType>> getAccessor() {

    final ArrayImg<DoubleType, DoubleArray> warpField =
            ArrayImgs.doubles(values, columnCount, rowCount, VALUES_PER_AFFINE);

    final CompositeIntervalView<DoubleType, RealComposite<DoubleType>>
            collapsedSource = Views.collapseReal(warpField);

    final RandomAccessible<RealComposite<DoubleType>> extendedCollapsedSource = Views.extendBorder(collapsedSource);
    final RealRandomAccessible<RealComposite<DoubleType>> coefficients =
            Views.interpolate(extendedCollapsedSource, interpolatorFactory);

    final double xScale = getXScale();
    final double yScale = getYScale();
    final double[] scale = { xScale, yScale };
    final double[] shift = { 0.5 * xScale , 0.5 * yScale };

    final ScaleAndTranslation scaleAndTranslation = new ScaleAndTranslation(scale, shift);

    final RealRandomAccessible<RealComposite<DoubleType>> stretchedCoefficients =
            RealViews.transform(coefficients, scaleAndTranslation);

    return stretchedCoefficients.realRandomAccess();
}
 
Example 2
Source File: LinearIntensityMap.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public LinearIntensityMap( final RandomAccessibleInterval< T > source, final InterpolatorFactory< RealComposite< T >, RandomAccessible< RealComposite< T > > > interpolatorFactory )
{
	this.interpolatorFactory = interpolatorFactory;
	final CompositeIntervalView< T, RealComposite< T > > collapsedSource = Views.collapseReal( source );
	dimensions = new FinalInterval( collapsedSource );
	final double[] shift = new double[ dimensions.numDimensions() ];
	for ( int d = 0; d < shift.length; ++d )
		shift[ d ] = 0.5;
	translation = new Translation( shift );

	final RandomAccessible< RealComposite< T > > extendedCollapsedSource = Views.extendBorder( collapsedSource );
	coefficients = Views.interpolate( extendedCollapsedSource, interpolatorFactory );
}
 
Example 3
Source File: DefaultExtendBorderView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ExtendedRandomAccessibleInterval<T, F> calculate(F input) {
	return Views.extendBorder(input);
}
 
Example 4
Source File: AbstractThin.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<BitType> input,
	final RandomAccessibleInterval<BitType> output)
{
	// Create a new image as a buffer to store the thinning image in each
	// iteration.
	// This image and output are swapped each iteration since we need to work on
	// the image
	// without changing it.

	final Img<BitType> buffer = ops().create().img(input, new BitType());

	final IterableInterval<BitType> it1 = Views.iterable(buffer);
	final IterableInterval<BitType> it2 = Views.iterable(output);

	// Extend the buffer in order to be able to iterate care-free later.
	final RandomAccessible<BitType> ra1 = Views.extendBorder(buffer);
	final RandomAccessible<BitType> ra2 = Views.extendBorder(output);

	// Used only in first iteration.
	RandomAccessible<BitType> currRa = Views.extendBorder(input);

	// Create cursors.
	final Cursor<BitType> firstCursor = it1.localizingCursor();
	Cursor<BitType> currentCursor = Views.iterable(input).localizingCursor();
	final Cursor<BitType> secondCursor = it2.localizingCursor();

	// Create pointers to the current and next cursor and set them to Buffer and
	// output respectively.
	Cursor<BitType> nextCursor;
	nextCursor = secondCursor;

	// The main loop.
	boolean changes = true;
	int i = 0;
	// Until no more changes, do:
	final long[] coordinates = new long[currentCursor.numDimensions()];
	while (changes) {
		changes = false;
		// This For-Loop makes sure, that iterations only end on full cycles (as
		// defined by the strategies).
		for (int j = 0; j < m_strategy.getIterationsPerCycle(); ++j) {
			// For each pixel in the image.
			while (currentCursor.hasNext()) {
				// Move both cursors
				currentCursor.fwd();
				nextCursor.fwd();
				// Get the position of the current cursor.
				currentCursor.localize(coordinates);

				// Copy the value of the image currently operated upon.
				final boolean curr = currentCursor.get().get();
				nextCursor.get().set(curr);

				// Only foreground pixels may be thinned
				if (curr) {

					// Ask the strategy whether to flip the foreground pixel or not.
					final boolean flip = m_strategy.removePixel(coordinates, currRa, j);

					// If yes - change and keep track of the change.
					if (flip) {
						nextCursor.get().set(false);
						changes = true;
					}
				}
			}
			// One step of the cycle is finished, notify the strategy.
			m_strategy.afterCycle();

			// Reset the cursors to the beginning and assign pointers for the next
			// iteration.
			currentCursor.reset();
			nextCursor.reset();

			// Keep track of the most recent image. Needed for output.
			if (currRa == ra2) {
				currRa = ra1;
				currentCursor = firstCursor;
				nextCursor = secondCursor;
			}
			else {
				currRa = ra2;
				currentCursor = secondCursor;
				nextCursor = firstCursor;
			}

			// Keep track of iterations.
			++i;
		}
	}

	// Depending on the iteration count, the final image is either in ra1 or
	// ra2. Copy it to output.
	if (i % 2 == 0) {
		// Ra1 points to img1, ra2 points to output.
		copy(buffer, output);
	}
}
 
Example 5
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static <T> RandomAccessible<T> deinterval(
	RandomAccessibleInterval<T> input)
{
	return Views.extendBorder(input);
}