HyperstackUtils { public static <T extends RealType<T> & NativeType<T>> Stream<Subspace<T>> split3DSubspaces(final ImgPlus<T> hyperStack) { return splitSubspaces(hyperStack, Arrays.asList(Axes.X, Axes.Y, Axes.Z)); } private  HyperstackUtils(); static Stream<Subspace<T>> split3DSubspaces(final ImgPlus<T> hyperStack); static Stream<Subspace<T>> splitSubspaces(final ImgPlus<T> hyperStack,
			final Collection<AxisType> subspaceTypes);  }
@Test public void testSplitSubspacesIntervalData() { final long depth = 3; final long height = 3; final long width = 3; final long channels = 2; final long frames = 2; final Random random = new Random(0xC0FFEE); final ArrayImg<LongType, LongArray> img = ArrayImgs.longs(width, height, depth, channels, frames); final ImgPlus<LongType> imgPlus = new ImgPlus<>(img, "", X_AXIS, Y_AXIS, Z_AXIS, C_AXIS, T_AXIS); final List<long[]> positions = Arrays.asList(new long[] { 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 1, 0 }, new long[] { 0, 0, 0, 0, 1 }, new long[] { 0, 0, 0, 1, 1 }); final long[] sizes = { width, height, depth, 1, 1 }; final List<IntervalView<LongType>> expectedSubspaces = new ArrayList<>(); positions.forEach(position -> { final IntervalView<LongType> subspace = Views.offsetInterval(imgPlus, position, sizes); subspace.forEach(e -> e.set(random.nextLong())); expectedSubspaces.add(subspace); }); final Stream<Subspace<LongType>> subspaces = HyperstackUtils .split3DSubspaces(imgPlus); subspaces.forEach(subspace -> { final Iterator<LongType> expected = Views.flatIterable(expectedSubspaces .remove(0)).iterator(); final IterableInterval<LongType> resultIterable = Views.flatIterable( subspace.interval); resultIterable.forEach(result -> assertEquals(expected.next().get(), result.get())); }); }
@Test public void testViewMeta() { final AxisType[] expectedTypes = { W_TYPE, Axes.CHANNEL, Axes.TIME }; final Iterator<long[]> expectedPositions = Stream.of(new long[] { 0, 0, 0 }, new long[] { 1, 0, 0 }, new long[] { 0, 1, 0 }, new long[] { 1, 1, 0 }, new long[] { 0, 0, 1 }, new long[] { 1, 0, 1 }, new long[] { 0, 1, 1 }, new long[] { 1, 1, 1 }).iterator(); final Iterator<String> expectedStrings = Stream.of( "W: 0, Channel: 1, Time: 1", "W: 1, Channel: 1, Time: 1", "W: 0, Channel: 2, Time: 1", "W: 1, Channel: 2, Time: 1", "W: 0, Channel: 1, Time: 2", "W: 1, Channel: 1, Time: 2", "W: 0, Channel: 2, Time: 2", "W: 1, Channel: 2, Time: 2").iterator(); final Img<ByteType> img = ArrayImgs.bytes(2, 2, 2, 2, 2, 2); final ImgPlus<ByteType> imgPlus = new ImgPlus<>(img, "", X_AXIS, Y_AXIS, Z_AXIS, W_AXIS, C_AXIS, T_AXIS); final List<Subspace<ByteType>> subspaces = HyperstackUtils.split3DSubspaces( imgPlus).collect(Collectors.toList()); subspaces.forEach(subspace -> { assertArrayEquals(expectedTypes, subspace.getAxisTypes().toArray()); assertArrayEquals(expectedPositions.next(), subspace.getPosition() .toArray()); assertEquals(expectedStrings.next(), subspace.toString()); }); }