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

The following examples show how to use net.imglib2.view.Views#collapseReal() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: ARGBCompositeColorConverterTest.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test()
{
	ARGBCompositeColorConverter<VolatileDoubleType, RealComposite<VolatileDoubleType>, Volatile<RealComposite<VolatileDoubleType>>> c = ARGBCompositeColorConverter.imp1(3);

	c.minProperty(0).set(0.0);
	c.minProperty(1).set(0.0);
	c.minProperty(2).set(0.0);

	c.maxProperty(0).set(1.0);
	c.maxProperty(1).set(1.0);
	c.maxProperty(2).set(1.0);

	c.colorProperty(0).set(Colors.toARGBType(Color.RED));
	// Color.GREEN is only 127 green
	c.colorProperty(1).set(Colors.toARGBType(Color.valueOf("#00ff00")));
	c.colorProperty(2).set(Colors.toARGBType(Color.BLUE));

	double[] data = {
			1.0, 1.0, 0.0, 0.0,
			1.0, 0.0, 1.0, 0.0,
			1.0, 0.0, 0.0, 1.0
	};
	RandomAccessibleInterval<DoubleType> img = ArrayImgs.doubles(data, data.length / 3, 3);
	RandomAccessibleInterval<VolatileDoubleType> asVolatile = Converters.convert(img, new TypeVolatileConverter<>(), new VolatileDoubleType());
	RandomAccessibleInterval<RealComposite<VolatileDoubleType>> collapsed = Views.collapseReal(asVolatile);

	int[] groundTruthData = {
			0xFFFFFFFF,
			0xFFFF0000,
			0xFF00FF00,
			0xFF0000FF
	};

	final Converter<RealComposite<VolatileDoubleType>, VolatileWithSet<RealComposite<VolatileDoubleType>>> viewerConverter = (source, target ) -> {
		target.setT(source);
		target.setValid(source.get(0).isValid());
	};

	final RandomAccessibleInterval<ARGBType> groundTruth = ArrayImgs.argbs(groundTruthData, groundTruthData.length);

	LOG.debug("Dimensions: {}", Intervals.dimensionsAsLongArray(collapsed));

	RandomAccessibleInterval<VolatileWithSet<RealComposite<VolatileDoubleType>>> volatileComposite =
			Converters.convert(collapsed, viewerConverter, new VolatileWithSet<>(null, true));

	RandomAccessibleInterval<ARGBType> asColor = Converters.convert(volatileComposite, c, new ARGBType(1));

	Views
			.interval(Views.pair(groundTruth, asColor), asColor)
			.forEach(p -> Assert.assertEquals(p.getA().get(), p.getB().get()));
}
 
Example 8
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 9
Source File: DefaultCollapseReal2CompositeView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public CompositeView<T, RealComposite<T>> calculate(RandomAccessible<T> input) {
	return Views.collapseReal(input, numChannels);
}