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

The following examples show how to use net.imglib2.view.Views#stack() . 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: ShapeInterpolationMode.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <R extends RealType<R>, T extends NativeType<T> & RealType<T>> RealRandomAccessible<T> getInterpolatedDistanceTransformMask(
		final RandomAccessibleInterval<R> dt1,
		final RandomAccessibleInterval<R> dt2,
		final double distance,
		final T targetValue,
		final AffineTransform3D transformToSource)
{
	final RandomAccessibleInterval<R> distanceTransformStack = Views.stack(dt1, dt2);

	final R extendValue = Util.getTypeFromInterval(distanceTransformStack).createVariable();
	extendValue.setReal(extendValue.getMaxValue());
	final RealRandomAccessible<R> interpolatedDistanceTransform = Views.interpolate(
			Views.extendValue(distanceTransformStack, extendValue),
			new NLinearInterpolatorFactory<>()
		);

	final RealRandomAccessible<R> scaledInterpolatedDistanceTransform = RealViews.affineReal(
			interpolatedDistanceTransform,
			new Scale3D(1, 1, -distance)
		);

	final T emptyValue = targetValue.createVariable();
	final RealRandomAccessible<T> interpolatedShape = Converters.convert(
			scaledInterpolatedDistanceTransform,
			(in, out) -> out.set(in.getRealDouble() <= 0 ? targetValue : emptyValue),
			emptyValue.createVariable()
		);

	return RealViews.affineReal(interpolatedShape, transformToSource);
}
 
Example 2
Source File: LocalThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void compute(final RandomAccessibleInterval<I> input,
	final IterableInterval<BitType> output)
{

	final List<RandomAccessibleInterval<RealType>> listOfIntegralImages =
		new ArrayList<>();
	for (final int order : requiredIntegralImages()) {
		final RandomAccessibleInterval<RealType> requiredIntegralImg =
			getIntegralImage(input, order);
		listOfIntegralImages.add(requiredIntegralImg);
	}

	// Composite image of integral images of order 1 and 2
	final RandomAccessibleInterval<RealType> stacked = Views.stack(
		listOfIntegralImages);
	final RandomAccessibleInterval<? extends Composite<RealType>> compositeRAI =
		Views.collapse(stacked);
	final RandomAccessibleInterval<? extends Composite<RealType>> extendedCompositeRAI =
		removeLeadingZeros(compositeRAI);

	final NeighborhoodsIterableInterval<? extends Composite<RealType>> neighborhoods =
		shape.neighborhoodsSafe(extendedCompositeRAI);

	if (map == null) {
		map = (BinaryComputerOp) ops().op(Map.class, out(), in(), neighborhoods,
			filterOp);
	}

	map.compute(input, neighborhoods, output);
}
 
Example 3
Source File: HessianRAI.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public CompositeIntervalView<T, RealComposite<T>> calculate(RandomAccessibleInterval<T> input) {
	List<RandomAccessibleInterval<T>> derivatives = new ArrayList<>();
	for (int i = 0; i < derivativeComputers.length; i++) {
		RandomAccessibleInterval<T> derivative = createRAI.calculate(input);
		derivativeComputers[i].compute(input, derivative);
		for (int j = 0; j < derivativeComputers.length; j++) {
			RandomAccessibleInterval<T> out = createRAI.calculate(input);
			derivativeComputers[j].compute(derivative, out);
			derivatives.add(out);
		}
	}
	RandomAccessibleInterval<T> stackedDerivatives = Views.stack(derivatives);
	return Views.collapseReal(stackedDerivatives);
}
 
Example 4
Source File: PartialDerivativesRAI.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public CompositeIntervalView<T, RealComposite<T>> calculate(RandomAccessibleInterval<T> input) {
	List<RandomAccessibleInterval<T>> derivatives = new ArrayList<>();
	for (int i = 0; i < derivativeFunctions.length; i++) {
		RandomAccessibleInterval<T> derivative = derivativeFunctions[i].calculate(input);
		derivatives.add(derivative);
	}

	RandomAccessibleInterval<T> stacked = Views.stack(derivatives);
	return Views.collapseReal(stacked);
}
 
Example 5
Source File: StackViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void defaultStackTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	List<Img<DoubleType>> list = new ArrayList<>();
	list.add(img);
	list.add(img);
	
	RandomAccessibleInterval<DoubleType> il2 = Views.stack(list);
	RandomAccessibleInterval<DoubleType> opr = ops.transform().stackView(list);

	assertEquals(il2.dimension(2), opr.dimension(2));
}
 
Example 6
Source File: StackViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void stackWithAccessModeTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	List<Img<DoubleType>> list = new ArrayList<>();
	list.add(img);
	list.add(img);
	
	RandomAccessibleInterval<DoubleType> il2 = Views.stack(StackAccessMode.DEFAULT, list);
	RandomAccessibleInterval<DoubleType> opr = ops.transform().stackView(list, StackAccessMode.DEFAULT);

	assertEquals(il2.dimension(2), opr.dimension(2));
}
 
Example 7
Source File: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private <U> VolatileProjector createSingleSourceProjector(
		final SourceAndConverter<U> source,
		final int timepoint,
		final AffineTransform3D viewerTransform,
		final int screenScaleIndex,
		final RandomAccessibleInterval<ARGBType> screenImage,
		final RandomAccessibleInterval<ByteType> mask,
		final Interpolation interpolation,
		final boolean preMultiply)
{
	if (useVolatileIfAvailable)
		if (source.asVolatile() != null)
		{
			LOG.debug(
					"Volatile is available for source={} (name={})",
					source.getSpimSource(),
					source.getSpimSource().getName()
			         );
			return createSingleSourceVolatileProjector(
					source.asVolatile(),
					timepoint,
					screenScaleIndex,
					viewerTransform,
					screenImage,
					mask,
					interpolation,
					preMultiply
			                                          );
		}
		else if (source.getSpimSource().getType() instanceof Volatile)
		{
			LOG.debug(
					"Casting to volatile source:{} (name={})",
					source.getSpimSource(),
					source.getSpimSource().getName()
			         );
			@SuppressWarnings("unchecked") final SourceAndConverter<? extends Volatile<?>> vsource =
					(SourceAndConverter<? extends Volatile<?>>) source;
			return createSingleSourceVolatileProjector(
					vsource,
					timepoint,
					screenScaleIndex,
					viewerTransform,
					screenImage,
					mask,
					interpolation,
					preMultiply
			                                          );
		}

	final AffineTransform3D screenScaleTransform = screenScaleTransforms[currentScreenScaleIndex];
	final AffineTransform3D screenTransform      = viewerTransform.copy();
	screenTransform.preConcatenate(screenScaleTransform);
	final int bestLevel = MipmapTransforms.getBestMipMapLevel(screenTransform, source.getSpimSource(), timepoint);
	LOG.debug("Using bestLevel={}", bestLevel);
	return new SimpleVolatileProjector<>(
			getTransformedSource(
					source.getSpimSource(),
					timepoint,
					viewerTransform,
					screenScaleTransform,
					bestLevel,
					null,
					interpolation
				),
			source.getConverter(),
			Views.stack(screenImage),
			numRenderingThreads,
			renderingExecutorService
	);
}
 
Example 8
Source File: DefaultStackView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate(List<? extends RandomAccessibleInterval<T>> input) {
	return Views.stack(input);
}
 
Example 9
Source File: StackViewWithAccessMode.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate(List<? extends RandomAccessibleInterval<T>> input) {
	return Views.stack(stackAccessMode, input);
}