net.imglib2.view.composite.CompositeIntervalView Java Examples

The following examples show how to use net.imglib2.view.composite.CompositeIntervalView. 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: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static <D extends NativeType<D> & RealType<D>, T extends RealType<T>> RealComposite<T>  createExtension(
		final D d,
		final T t,
		final Converter<D, T> converter,
		final long size,
		IntFunction<D> valueAtIndex
)
{
	LOG.debug("Creating extension with size {}", size);
	final ArrayImg<D, ?> img = new ArrayImgFactory<>(d).create(1, size);
	img.setLinkedType((D) d.getNativeTypeFactory().createLinkedType((NativeImg)img));
	final CompositeIntervalView<D, RealComposite<D>> collapsed = Views.collapseReal(img);
	RealComposite<D> extensionCopy = collapsed.randomAccess().get();
	for (int channel = 0; channel < size; ++channel)
		extensionCopy.get(channel).set(valueAtIndex.apply(channel));
	return Views.collapseReal(Converters.convert((RandomAccessibleInterval<D>)img, converter, t.createVariable())).randomAccess().get();
}
 
Example #3
Source File: CollapseNumericViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultCollapseNumericTest() {

	Img<NativeARGBDoubleType> img = new ArrayImgFactory<NativeARGBDoubleType>().create(new int[] { 10, 10 },
			new NativeARGBDoubleType());

	CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2 = Views
			.collapseNumeric((RandomAccessibleInterval<NativeARGBDoubleType>) img);
	CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr = ops.transform()
			.collapseNumericView((RandomAccessibleInterval<NativeARGBDoubleType>) img);

	assertEquals(il2.numDimensions(), opr.numDimensions());

	CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2_2 = Views
			.collapseNumeric((RandomAccessible<NativeARGBDoubleType>) img, 1);
	CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr_2 = ops.transform()
			.collapseNumericView((RandomAccessible<NativeARGBDoubleType>) img, 1);

	assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
 
Example #4
Source File: CollapseRealViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultCollapseRealTest() {

	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 },
			new DoubleType());

	CompositeIntervalView<DoubleType, RealComposite<DoubleType>> il2 = Views
			.collapseReal((RandomAccessibleInterval<DoubleType>) img);
	CompositeIntervalView<DoubleType, RealComposite<DoubleType>> opr = ops.transform()
			.collapseRealView((RandomAccessibleInterval<DoubleType>) img);

	assertEquals(il2.numDimensions(), opr.numDimensions());

	CompositeView<DoubleType, RealComposite<DoubleType>> il2_2 = Views
			.collapseReal((RandomAccessible<DoubleType>) img, 1);
	CompositeView<DoubleType, RealComposite<DoubleType>> opr_2 = ops.transform()
			.collapseRealView((RandomAccessible<DoubleType>) img, 1);

	assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
 
Example #5
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 #6
Source File: CollapseViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void defaultCollapseTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 },
			new DoubleType());

	CompositeIntervalView<DoubleType, ? extends GenericComposite<DoubleType>> il2 = Views
			.collapse(img);
	CompositeIntervalView<DoubleType, ? extends GenericComposite<DoubleType>> opr = ops.transform()
			.collapseView(img);

	assertEquals(il2.numDimensions(), opr.numDimensions());
}
 
Example #7
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 #8
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 #9
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Executes the "partial derivative" operation on all dimensions */
@OpMethod(op = net.imagej.ops.filter.derivative.PartialDerivativesRAI.class)
public <T extends RealType<T>> CompositeIntervalView<T, RealComposite<T>>
	allPartialDerivatives(final RandomAccessibleInterval<T> in)
{
	@SuppressWarnings("unchecked")
	final CompositeIntervalView<T, RealComposite<T>> result =
		(CompositeIntervalView<T, RealComposite<T>>) ops().run(
			net.imagej.ops.filter.derivative.PartialDerivativesRAI.class, in);
	return result;
}
 
Example #10
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.filter.hessian.HessianRAI.class)
public <T extends RealType<T>> CompositeIntervalView<T, RealComposite<T>>
	hessian(final RandomAccessibleInterval<T> in)
{
	@SuppressWarnings("unchecked")
	final CompositeIntervalView<T, RealComposite<T>> result =
		(CompositeIntervalView<T, RealComposite<T>>) ops().run(
			net.imagej.ops.filter.hessian.HessianRAI.class, in);
	return result;
}
 
Example #11
Source File: DefaultCollapse2CompositeIntervalView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public CompositeIntervalView<T, ? extends GenericComposite<T>> calculate(RandomAccessibleInterval<T> input) {
	return Views.collapse(input);
}
 
Example #12
Source File: DefaultCollapseNumeric2CompositeIntervalView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public CompositeIntervalView<T, NumericComposite<T>> calculate(RandomAccessibleInterval<T> input) {
	return Views.collapseNumeric(input);
}
 
Example #13
Source File: HessianFilterTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Test
public void test() {
	Img<FloatType> img = generateFloatArrayTestImg(false, new long[] { 50, 50 });

	Cursor<FloatType> cursorImg = img.cursor();
	int counterX = 0;
	int counterY = 0;
	while (cursorImg.hasNext()) {
		if (counterX > 20 && counterX < 30 || counterY > 20 && counterY < 30) {
			cursorImg.next().setOne();
		} else {
			cursorImg.next().setZero();
		}
		counterX++;
		if (counterX % 50 == 0) {
			counterY++;
		}
		if (counterX == 50) {
			counterX = 0;
		}
		if (counterY == 50) {
			counterY = 0;
		}
	}

	CompositeIntervalView<FloatType, RealComposite<FloatType>> out = ops.filter().hessian(img);
	
	
	Cursor<RealComposite<FloatType>> outCursor = Views.iterable(out).cursor();
	
	while (outCursor.hasNext()) {
		RealComposite<FloatType> values = outCursor.next();
		assertEquals(values.get(1), values.get(2));
	}

	CompositeView<FloatType, RealComposite<FloatType>>.CompositeRandomAccess outRA = out.randomAccess();
	
	// two numbers represent a coordinate: 20|0 ; 21|0 ...
	int[] positions = new int[] { 20, 0, 21, 0, 19, 31, 19, 30 };
	float[] valuesXX = new float[] { 16.0f, -16.0f, 15.0f, 11.0f };
	float[] valuesXY = new float[] { 0.0f, 0.0f, 1.0f, 3.0f };
	float[] valuesYY = new float[] { 0.0f, 0.0f, 15.0f, 15.0f };

	FloatType type = Util.getTypeFromInterval(img).createVariable();
	int i = 0;
	int j = 0;
	while (i < positions.length - 1) {
		int[] pos = new int[2];
		pos[0] = positions[i];
		pos[1] = positions[i + 1];

		outRA.setPosition(pos);
		type.set(valuesXX[j]);
		assertEquals(type, outRA.get().get(0));

		outRA.setPosition(pos);
		type.set(valuesXY[j]);
		assertEquals(type, outRA.get().get(1));

		outRA.setPosition(pos);
		type.set(valuesYY[j]);
		assertEquals(type, outRA.get().get(3));

		i += 2;
		j++;
	}
}
 
Example #14
Source File: DefaultCollapseReal2CompositeIntervalView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public CompositeIntervalView<T, RealComposite<T>> calculate(RandomAccessibleInterval<T> input) {
	return Views.collapseReal(input);
}
 
Example #15
Source File: TransformNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Collapse the <em>n</em><sup>th</sup> dimension of an <em>n</em>
 * -dimensional {@link RandomAccessibleInterval}&lt;T extends {@link RealType}
 * &lt;T&gt;&gt; into an (<em>n</em>-1)-dimensional
 * {@link RandomAccessibleInterval}&lt;{@link RealComposite}&lt;T&gt;&gt;
 *
 * @param input the source
 * @return an (<em>n</em>-1)-dimensional {@link CompositeIntervalView} of
 *         {@link RealComposite RealComposites}
 */
@OpMethod(
	op = net.imagej.ops.transform.collapseRealView.DefaultCollapseReal2CompositeIntervalView.class)
public <T extends Type<T>, R extends RealType<R>>
	CompositeIntervalView<R, RealComposite<R>> collapseRealView(
		final RandomAccessibleInterval<T> input)
{
	return (CompositeIntervalView<R, RealComposite<R>>) ops().run(
		Ops.Transform.CollapseRealView.class, input);
}
 
Example #16
Source File: TransformNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Collapse the <em>n</em><sup>th</sup> dimension of an <em>n</em>
 * -dimensional {@link RandomAccessibleInterval}&lt;T extends
 * {@link NumericType}&lt;T&gt;&gt; into an (<em>n</em>-1)-dimensional
 * {@link RandomAccessibleInterval}&lt;{@link NumericComposite}&lt;T&gt;&gt;
 *
 * @param input the source
 * @return an (<em>n</em>-1)-dimensional {@link CompositeIntervalView} of
 *         {@link NumericComposite NumericComposites}
 */
@OpMethod(
	op = net.imagej.ops.transform.collapseNumericView.DefaultCollapseNumeric2CompositeIntervalView.class)
public <N extends NumericType<N>>
	CompositeIntervalView<N, NumericComposite<N>> collapseNumericView(
		final RandomAccessibleInterval<N> input)
{
	return (CompositeIntervalView<N, NumericComposite<N>>) ops().run(
		Ops.Transform.CollapseNumericView.class, input);
}
 
Example #17
Source File: TransformNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Collapse the <em>n</em><sup>th</sup> dimension of an <em>n</em>
 * -dimensional {@link RandomAccessibleInterval}&lt;T&gt; into an ( <em>n</em>
 * -1)-dimensional {@link RandomAccessibleInterval}&lt;
 * {@link GenericComposite}&lt;T&gt;&gt;
 *
 * @param input the source
 * @return an (<em>n</em>-1)-dimensional {@link CompositeIntervalView} of
 *         {@link GenericComposite GenericComposites}
 */
@OpMethod(
	op = net.imagej.ops.transform.collapseView.DefaultCollapse2CompositeIntervalView.class)
public <T> CompositeIntervalView<T, ? extends GenericComposite<T>>
	collapseView(final RandomAccessibleInterval<T> input)
{
	return (CompositeIntervalView<T, ? extends GenericComposite<T>>) ops().run(
		Ops.Transform.CollapseView.class, input);
}
 
Example #18
Source File: CollapseViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 3 votes vote down vote up
@Test
public void collapseRAITest() {

	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 }, new DoubleType());

	CompositeIntervalView<DoubleType, ? extends GenericComposite<DoubleType>> il2 = Views
			.collapse((RandomAccessibleInterval<DoubleType>) img);

	CompositeIntervalView<DoubleType, ? extends GenericComposite<DoubleType>> opr = ops.transform()
			.collapseView((RandomAccessibleInterval<DoubleType>) img);

	assertEquals(il2.numDimensions(), opr.numDimensions());
}