本文整理汇总了Java中net.imglib2.img.array.ArrayImgs.bits方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayImgs.bits方法的具体用法?Java ArrayImgs.bits怎么用?Java ArrayImgs.bits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.img.array.ArrayImgs
的用法示例。
在下文中一共展示了ArrayImgs.bits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIsAxesMatchingSpatialCalibrationDifferentScales
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testIsAxesMatchingSpatialCalibrationDifferentScales()
throws Exception
{
// Create a test image with different scales in calibration
final String unit = "mm";
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, 0.5);
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, 0.6);
final Img<BitType> img = ArrayImgs.bits(1, 1);
final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis);
final boolean result = IsosurfaceWrapper.isAxesMatchingSpatialCalibration(
imgPlus);
assertFalse(
"Different scales in axes should mean that calibration doesn't match",
result);
}
示例2: testIsAxesMatchingSpatialCalibrationDifferentUnits
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testIsAxesMatchingSpatialCalibrationDifferentUnits()
throws Exception
{
// Create a test image with different units in calibration
final double scale = 0.75;
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "cm", scale);
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "mm", scale);
final Img<BitType> img = ArrayImgs.bits(1, 1);
final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis);
final boolean result = IsosurfaceWrapper.isAxesMatchingSpatialCalibration(
imgPlus);
assertFalse(
"Different units in axes should mean that calibration doesn't match",
result);
}
示例3: testIsAxesMatchingSpatialCalibration
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testIsAxesMatchingSpatialCalibration() throws Exception {
// Create a test image with uniform calibration
final String unit = "mm";
final double scale = 0.75;
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, scale);
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, scale);
final Img<BitType> img = ArrayImgs.bits(1, 1);
final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis);
final boolean result = IsosurfaceWrapper.isAxesMatchingSpatialCalibration(
imgPlus);
assertTrue("Axes should have matching calibration", result);
}
示例4: testCube
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* Tests the op on a cube. All vectors should enter and exit it, i.e. their
* length should be 0.5.
*/
@Test
public void testCube() {
final Img<BitType> cube = ArrayImgs.bits(100, 100, 100);
final IntervalView<BitType> foreground = Views.interval(cube, new long[] {
1, 1, 1 }, new long[] { 98, 98, 98 });
foreground.cursor().forEachRemaining(BitType::setOne);
final double expectedLength = 1.0 / 2.0;
@SuppressWarnings("unchecked")
final List<Vector3d> milVectors =
(List<Vector3d>) ((ArrayList<Object>) IMAGE_J.op().run(MILGrid.class,
cube, IDENTITY_ROTATION, 10L, DEFAULT_INCREMENT, new Random(0xc0ff33)))
.get(0);
assertEquals("Regression test failed: some vectors have unexpected length",
milVectors.size(), milVectors.stream().filter(v -> v
.length() == expectedLength).count());
}
示例5: testHyperCube
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@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);
}
}
示例6: testAllForeground
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@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);
}
}
示例7: testOutput
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/** Test basic properties of the op's output */
@Test
public void testOutput() throws Exception {
// SETUP
final long[] inputDims = { 3, 3, 3 };
final Img<BitType> img = ArrayImgs.bits(inputDims);
// EXECUTE
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.TRUE);
// VERIFY
assertNotNull(result);
final long[] outputDims = new long[result.numDimensions()];
result.dimensions(outputDims);
assertArrayEquals(inputDims, outputDims);
}
示例8: testSquare
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/** Test the op with a 2x2 square. The square is in the middle of a 4x4 img */
@Test
public void testSquare() throws Exception {
// SETUP
final Img<BitType> img = ArrayImgs.bits(4, 4);
final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
1, 1 }, new long[] { 2, 2 });
square.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", 4,
countForeground(result));
final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
new long[] { 1, 1 }, new long[] { 2, 2 });
assertTrue("Wrong number of foreground elements in object", allForeground(
resultSquare));
}
示例9: testOutlineSquare
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* 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() throws Exception {
// 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 });
}
示例10: testEdgeSquare
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* 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() throws Exception {
// 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 });
}
示例11: testHyperCubeTranslations
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* Test box counting with a hyper cube and one grid translation (should find a
* better fit than in @see {@link #testHyperCube()})
*/
@Test
public void testHyperCubeTranslations() {
final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
i)).toArray();
final double[] expectedCounts = DoubleStream.of(1, 1, 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, 1L);
// 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);
}
}
示例12: testHyperCube
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* Test the op with a 3x3x3x3 hypercube. The cube is in the middle of a
* 5x5x5x5 img
*/
@Test
public void testHyperCube() throws Exception {
// 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 });
}
示例13: testAllBackground
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testAllBackground() throws Exception {
// SETUP
final double expectedCount = Math.log(0.0);
final Img<BitType> img = ArrayImgs.bits(TEST_DIMS);
// EXECUTE
final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
.boxCount(img, MAX_SIZE, MIN_SIZE, SCALING);
// VERIFY
assertNotNull(points);
assertEquals(ITERATIONS, points.size());
for (int i = 0; i < ITERATIONS; i++) {
assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12);
assertEquals(expectedCount, points.get(i).b.get(), 1e-12);
}
}
示例14: testSetNeighborhood
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testSetNeighborhood() throws Exception {
final Img<BitType> img = ArrayImgs.bits(3, 3, 3);
Octant<BitType> octant = new Octant<>(img);
final RandomAccess<BitType> access = img.randomAccess();
for (int z = 0; z < 2; z++) {
access.setPosition(z, 2);
for (int y = 0; y < 2; y++) {
access.setPosition(y, 1);
for (int x = 0; x < 2; x++) {
access.setPosition(x, 0);
access.get().setOne();
}
}
}
octant.setNeighborhood(1, 1, 1);
assertEquals("All neighbours should be foreground", 8, octant.getNeighborCount());
octant.setNeighborhood(2, 2, 2);
assertEquals("Wrong number of foreground neighbors", 1, octant.getNeighborCount());
}
示例15: testFileWritingExceptionsShowErrorDialog
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testFileWritingExceptionsShowErrorDialog() throws Exception {
// Mock a File that will cause an exception
final File exceptionsThrowingFile = mock(File.class);
// Directory path throws an exception
when(exceptionsThrowingFile.getAbsolutePath()).thenReturn("/.stl/");
// Create a test image
final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "mm");
final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "mm");
final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, "mm");
final Img<BitType> img = ArrayImgs.bits(1, 1, 1);
final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis,
yAxis, zAxis);
// Mock UI
final UserInterface mockUI = mock(UserInterface.class);
final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class);
when(mockUI.chooseFile(any(File.class), anyString())).thenReturn(
exceptionsThrowingFile);
when(mockUI.dialogPrompt(startsWith(STL_WRITE_ERROR), anyString(), eq(
ERROR_MESSAGE), any())).thenReturn(mockPrompt);
IMAGE_J.ui().setDefaultUI(mockUI);
// Run plugin
IMAGE_J.command().run(IsosurfaceWrapper.class, true, "inputImage", imgPlus,
"exportSTL", true).get();
// Verify that write error dialog got shown
verify(mockUI, timeout(1000).times(1)).dialogPrompt(startsWith(
STL_WRITE_ERROR), anyString(), eq(ERROR_MESSAGE), any());
}