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

The following examples show how to use net.imglib2.view.Views#dropSingletonDimensions() . 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: CropRAI.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate(final RandomAccessibleInterval<T> input, final Interval interval) {
	boolean oneSizedDims = false;

	if (dropSingleDimensions) {
		for (int d = 0; d < interval.numDimensions(); d++) {
			if (interval.dimension(d) == 1) {
				oneSizedDims = true;
				break;
			}
		}
	}

	if (Intervals.equals(input, interval) && !oneSizedDims)
		return input;
	if (!Intervals.contains(input, interval))
		throw new RuntimeException("Intervals don't match!");
	IntervalView<T> res = Views.offsetInterval(input, interval);
	return oneSizedDims ? Views.dropSingletonDimensions(res) : res;
}
 
Example 2
Source File: SlicesII.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public RandomAccessibleInterval<T> get() {
	localize(tmpPosition);

	final long[] offset = tmpPosition.clone();
	for (int d = 0; d < max.length; d++) {
		offset[d] += sliceOffset[d];
	}

	final IntervalView<T> res = Views.offsetInterval(src, offset, sliceDims);

	return dropSingltonDimensions ? Views.dropSingletonDimensions(res) : res;
}
 
Example 3
Source File: DefaultDropSingletonDimensionsView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate(RandomAccessibleInterval<T> input) {
	return Views.dropSingletonDimensions(input);
}
 
Example 4
Source File: DropSingletonDimensionsViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 3 votes vote down vote up
@Test
public void dropSingletonDimensionsTest() {

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

	RandomAccessibleInterval<DoubleType> il2 = Views.dropSingletonDimensions(img);

	RandomAccessibleInterval<DoubleType> opr = ops.transform().dropSingletonDimensionsView(img);

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