Java Code Examples for net.imglib2.img.array.ArrayImgs#bits()
The following examples show how to use
net.imglib2.img.array.ArrayImgs#bits() .
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: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testOneVoxel() { // SETUP final PrimitiveIterator.OfDouble sizes = DoubleStream.of(9, 3, 1).map( i -> -Math.log(i)).iterator(); final PrimitiveIterator.OfDouble counts = DoubleStream.of(1, 1, 1).map( Math::log).iterator(); final Img<BitType> img = ArrayImgs.bits(9, 9, 9); final RandomAccess<BitType> access = img.randomAccess(); access.setPosition(new long[] { 4, 4, 4 }); access.get().setOne(); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, 9L, 3L, 3.0); // VERIFY points.forEach(p -> { assertEquals(p.a.get(), sizes.next(), 1e-12); assertEquals(p.b.get(), counts.next(), 1e-12); }); }
Example 2
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testUnevenBoxes() { // SETUP final int size = 10; final int max = size - 1; final long boxSize = size - 1; final Img<BitType> img = ArrayImgs.bits(size, size, size); final IntervalView<BitType> lastXYSlice = Views.interval(img, new long[] { 0, 0, max}, new long[] { max, max, max}); lastXYSlice.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, boxSize, boxSize, 3.0); // VERIFY final ValuePair<DoubleType, DoubleType> point = points.get(0); assertEquals(point.b.get(), Math.log(4), 1e-12); }
Example 3
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testHyperCube() { // SETUP final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log( i)).toArray(); final double[] expectedCounts = DoubleStream.of(1, 16, 16).map(Math::log) .toArray(); final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4); final IntervalView<BitType> hyperView = Views.offsetInterval(img, new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 }); hyperView.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, 4L, 1L, 2.0); // VERIFY for (int i = 0; i < expectedSizes.length; i++) { assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12); assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12); } }
Example 4
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testAllForeground() { // SETUP final double scalingPow = DoubleStream.generate(() -> SCALING).limit( DIMENSIONS).reduce((i, j) -> i * j).orElse(0); final double[] expectedCounts = DoubleStream.iterate(1.0, i -> i * scalingPow).map(Math::log).limit(ITERATIONS).toArray(); final Img<BitType> img = ArrayImgs.bits(TEST_DIMS); img.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, MAX_SIZE, MIN_SIZE, SCALING); // VERIFY for (int i = 0; i < ITERATIONS; i++) { assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12); assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12); } }
Example 5
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Test the op with a 3x3 square with a hole in the middle. The square is in * the middle of a 5x5 img */ @Test public void testOutlineSquare() { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 1, 1 }, new long[] { 3, 3 }); square.cursor().forEachRemaining(BitType::setOne); final RandomAccess<BitType> access = square.randomAccess(); access.setPosition(new long[] { 1, 1 }); access.get().setZero(); // EXECUTION final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 8, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 1, 1 }, new long[] { 3, 3 }); assertEquals("Wrong number of foreground elements in object", 8, countForeground(resultSquare)); assertPositionBackground(result, new long[] { 2, 2 }); }
Example 6
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Test the op with a 3x3 square starting from (0,1) in a 5x5 img * * @see Outline#compute(RandomAccessibleInterval, Boolean, * RandomAccessibleInterval) * @see #testEdgeSquare() */ @Test public void testEdgeSquare() { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 0, 1 }, new long[] { 3, 3 }); square.cursor().forEachRemaining(BitType::setOne); // EXECUTION final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 7, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 0, 1 }, new long[] { 3, 3 }); assertEquals("Wrong number of foreground elements in object", 7, countForeground(resultSquare)); assertPositionBackground(result, new long[] { 0, 2 }); assertPositionBackground(result, new long[] { 1, 2 }); }
Example 7
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Test the op with a 3x3 square starting from (0,1) in a 5x5 img without * excluding edges * * @see Outline#compute(RandomAccessibleInterval, Boolean, * RandomAccessibleInterval) * @see #testEdgeSquare() */ @Test public void testEdgeSquareExcludeEdgesFalse() { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 0, 1 }, new long[] { 3, 3 }); square.cursor().forEachRemaining(BitType::setOne); final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.FALSE); assertEquals("Wrong number of foreground elements in interval", 8, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 0, 1 }, new long[] { 3, 3 }); assertEquals("Wrong number of foreground elements in object", 8, countForeground(resultSquare)); assertPositionBackground(result, new long[] { 1, 2 }); }
Example 8
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Test the op with a 3x3x3x3 hypercube. The cube is in the middle of a * 5x5x5x5 img */ @Test public void testHyperCube() { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5, 5, 5); final IntervalView<BitType> hyperCube = Views.offsetInterval(img, new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 }); hyperCube.cursor().forEachRemaining(BitType::setOne); // EXECUTE final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 80, countForeground(result)); final IntervalView<BitType> resultHyperCube = Views.offsetInterval(result, new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 }); assertEquals("Wrong number of foreground elements in object", 80, countForeground(resultHyperCube)); assertPositionBackground(result, new long[] { 2, 2, 2, 2 }); }
Example 9
Source File: TestHelper.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
public static Img<BitType> drawCube(final long width, final long height, final long depth, final long padding) { final long totalPadding = 2 * padding; final Img<BitType> cube = ArrayImgs.bits(width + totalPadding, height + totalPadding, depth + totalPadding); final long x1 = padding + width; final long y1 = padding + height; final long z1 = padding + depth; final RandomAccess<BitType> access = cube.randomAccess(); for (long z = padding; z < z1; z++) { access.setPosition(z, 2); for (long y = padding; y < y1; y++) { access.setPosition(y, 1); for (long x = padding; x < x1; x++) { access.setPosition(x, 0); access.get().setOne(); } } } return cube; }
Example 10
Source File: WatershedSeededTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void test() { long[] dims = { 15, 30 }; // create input image Img<FloatType> input = ArrayImgs.floats(dims); MersenneTwisterFast random = new MersenneTwisterFast(SEED); for (FloatType b : input) { b.setReal(random.nextDouble()); } // create 3 seeds Img<BitType> bits = ArrayImgs.bits(dims); RandomAccess<BitType> ra = bits.randomAccess(); ra.setPosition(new int[] { 0, 0 }); ra.get().set(true); ra.setPosition(new int[] { 4, 6 }); ra.get().set(true); ra.setPosition(new int[] { 10, 20 }); ra.get().set(true); // compute labeled seeds final ImgLabeling<Integer, IntType> labeledSeeds = ops.labeling().cca(bits, StructuringElement.EIGHT_CONNECTED); testWithoutMask(input, labeledSeeds); testWithMask(input, labeledSeeds); }
Example 11
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<BitType, LongArray> generateBitArrayTestImg( final boolean fill, final long... dims) { ArrayImg<BitType, LongArray> bits = ArrayImgs.bits(dims); if (fill) { MersenneTwisterFast betterRNG = new MersenneTwisterFast(0xf1eece); for (BitType b : bits) { b.set(betterRNG.nextBoolean()); } } return bits; }
Example 12
Source File: ErosionTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Before public void initialize() { in = generateByteArrayTestImg(true, 10, 10); bitIn = ArrayImgs.bits(10, 10); final MersenneTwisterFast rnd = new MersenneTwisterFast(0x123456789caffee1L); for (BitType px : bitIn) px.set(rnd.nextBoolean()); }
Example 13
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** Test the op with an interval that's full of foreground elements */ @Test public void testAllForeground() { // SETUP final Img<BitType> img = ArrayImgs.bits(3, 3, 3); img.forEach(BitType::setOne); // EXECUTE final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Output should contain no foreground", 0, countForeground( result)); }
Example 14
Source File: EulerCorrectionTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testConforms() throws Exception { final Img<BitType> img = ArrayImgs.bits(3, 3); ops.run(EulerCorrection.class, img); }
Example 15
Source File: EulerCharacteristic26NFloatingTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testConforms() throws AssertionError { final Img<BitType> img = ArrayImgs.bits(3, 3); ops.topology().eulerCharacteristic26NFloating(img); }
Example 16
Source File: N5Test.java From sciview with BSD 2-Clause "Simplified" License | 4 votes |
private static Mesh generateMesh() { ImageJ imagej = new ImageJ(); // Generate an image Img<BitType> img = ArrayImgs.bits(25, 25, 25); RandomAccess<BitType> imgAccess = img.randomAccess(); imgAccess.setPosition(new long[]{12, 12, 12}); imgAccess.get().set(true); // Run marching cubes //return imagej.op().geom().marchingCubes(img); return (new DefaultMarchingCubes()).calculate(img); }
Example 17
Source File: WatershedSeededTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings("unchecked") private void testWithoutMask(final RandomAccessibleInterval<FloatType> in, final ImgLabeling<Integer, IntType> seeds) { // create mask which is 1 everywhere long[] dims = new long[in.numDimensions()]; in.dimensions(dims); Img<BitType> mask = ArrayImgs.bits(dims); for (BitType b : mask) { b.setOne(); } /* * use 8-connected neighborhood */ // compute result without watersheds ImgLabeling<Integer, IntType> out = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, false); assertResults(in, out, seeds, mask, false, false); // compute result with watersheds ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, true); assertResults(in, out2, seeds, mask, true, false); /* * use 4-connected neighborhood */ // compute result without watersheds ImgLabeling<Integer, IntType> out3 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, false); assertResults(in, out3, seeds, mask, false, false); // compute result with watersheds ImgLabeling<Integer, IntType> out4 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, true); assertResults(in, out4, seeds, mask, true, false); }
Example 18
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testThrowsIAEIfScalingLTOne() { final Img<BitType> img = ArrayImgs.bits(9, 9, 9); ops.topology().boxCount(img, 2L, 2L, 0.99); }
Example 19
Source File: WatershedTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings("unchecked") private void testWithMask(final RandomAccessibleInterval<FloatType> in) { // create mask which is 1 everywhere long[] dims = new long[in.numDimensions()]; in.dimensions(dims); Img<BitType> mask = ArrayImgs.bits(dims); RandomAccess<BitType> raMask = mask.randomAccess(); for (BitType b : mask) { b.setZero(); } for (int x = 0; x < dims[0] / 2; x++) { for (int y = 0; y < dims[1] / 2; y++) { raMask.setPosition(new int[] { x, y }); raMask.get().setOne(); } } /* * use 8-connected neighborhood */ // compute result without watersheds ImgLabeling<Integer, IntType> out = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, true, false, mask); assertResults(in, out, mask, true, false, true); // compute result with watersheds ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, true, true, mask); assertResults(in, out2, mask, true, true, true); /* * use 4-connected neighborhood */ // compute result without watersheds ImgLabeling<Integer, IntType> out3 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, false, false, mask); assertResults(in, out3, mask, false, false, true); // compute result with watersheds ImgLabeling<Integer, IntType> out4 = (ImgLabeling<Integer, IntType>) ops.run(Watershed.class, null, in, false, true, mask); assertResults(in, out4, mask, false, true, true); }
Example 20
Source File: WatershedSeededTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings("unchecked") private void testWithMask(final RandomAccessibleInterval<FloatType> in, final ImgLabeling<Integer, IntType> seeds) { // create mask which is 1 everywhere long[] dims = new long[in.numDimensions()]; in.dimensions(dims); Img<BitType> mask = ArrayImgs.bits(dims); RandomAccess<BitType> raMask = mask.randomAccess(); for (BitType b : mask) { b.setZero(); } for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { raMask.setPosition(new int[] { x, y }); raMask.get().setOne(); } } /* * use 8-connected neighborhood */ // compute result without watersheds ImgLabeling<Integer, IntType> out = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, false, mask); assertResults(in, out, seeds, mask, false, true); // compute result with watersheds ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, true, mask); assertResults(in, out2, seeds, mask, true, true); /* * use 4-connected neighborhood */ // compute result without watersheds ImgLabeling<Integer, IntType> out3 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, false, mask); assertResults(in, out3, seeds, mask, false, true); // compute result with watersheds ImgLabeling<Integer, IntType> out4 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, true, mask); assertResults(in, out4, seeds, mask, true, true); }