net.imglib2.type.numeric.integer.ByteType Java Examples
The following examples show how to use
net.imglib2.type.numeric.integer.ByteType.
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: DefaultBilateralTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testArrayToCellImg() { final byte[] data = { 7, 8, 9, 1, 2, 3, 7, 9, 8, 1, 3, 2, 8, 7, 9, 2, 1, 3, 8, 9, 7, 2, 3, 1, 9, 7, 8, 3, 1, 2, 9, 8, 7, 3, 2, 1 }; final Img<ByteType> in = ArrayImgs.bytes(data, 6, 6); final Img<ByteType> out = generateByteArrayTestImg(false, 6, 6); final Img<ByteType> cellOut = generateByteTestCellImg(false, 6, 6); ops.run(DefaultBilateral.class, out, in, 15, 5, 2); ops.run(DefaultBilateral.class, cellOut, in, 15, 5, 2); Cursor<ByteType> cout = out.cursor(); Cursor<ByteType> cCellOut = cellOut.cursor(); while (cout.hasNext()) { byte expected = cout.next().get(); byte actual = cCellOut.next().get(); assertEquals(expected, actual); } }
Example #2
Source File: N5TypesTest.java From paintera with GNU General Public License v2.0 | 6 votes |
@Test public void testType() { final Set<DataType> toBeTested = Stream.of(DataType.values()).collect(Collectors.toSet()); final Set<DataType> wasTested = new HashSet<>(); testAndLogNativeTypeForType(DataType.FLOAT32, FloatType.class, wasTested); testAndLogNativeTypeForType(DataType.FLOAT64, DoubleType.class, wasTested); testAndLogNativeTypeForType(DataType.INT8, ByteType.class, wasTested); testAndLogNativeTypeForType(DataType.INT16, ShortType.class, wasTested); testAndLogNativeTypeForType(DataType.INT32, IntType.class, wasTested); testAndLogNativeTypeForType(DataType.INT64, LongType.class, wasTested); testAndLogNativeTypeForType(DataType.UINT8, UnsignedByteType.class, wasTested); testAndLogNativeTypeForType(DataType.UINT16, UnsignedShortType.class, wasTested); testAndLogNativeTypeForType(DataType.UINT32, UnsignedIntType.class, wasTested); testAndLogNativeTypeForType(DataType.UINT64, UnsignedLongType.class, wasTested); Assert.assertEquals(toBeTested, wasTested); }
Example #3
Source File: SquareIntegralImgTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private Img<ByteType> generateKnownSquareIntegralImage() { final long[] dims = new long[] { 3, 3 }; final byte[] array = new byte[9]; array[0] = (byte) 16; array[1] = (byte) 32; array[2] = (byte) 36; array[3] = (byte) 32; array[4] = (byte) 64; array[5] = (byte) 72; array[6] = (byte) 36; array[7] = (byte) 72; array[8] = (byte) 116; Img<ByteType> bytes = ArrayImgs.bytes(array, dims); return bytes; }
Example #4
Source File: DefaultCoarsenessFeature.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Apply mean filter with given size of reactangle shape * * @param input * Input image * @param i * Size of rectangle shape * @return Filered mean image */ @SuppressWarnings("unchecked") private Img<I> mean(final RandomAccessibleInterval<I> input, final int i) { long[] dims = new long[input.numDimensions()]; input.dimensions(dims); final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(dims))]; Img<I> meanImg = (Img<I>) ArrayImgs.unsignedBytes(array, dims); OutOfBoundsMirrorFactory<ByteType, Img<ByteType>> oobFactory = new OutOfBoundsMirrorFactory<>( Boundary.SINGLE); ops().run(MeanFilterOp.class, meanImg, input, new RectangleShape(i, true), oobFactory); return meanImg; }
Example #5
Source File: CreateImgTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testCreateFromRaiDifferentType() { final IntervalView<ByteType> input = Views.interval(PlanarImgs.bytes(10, 10, 10), new FinalInterval( new long[] { 10, 10, 1 })); final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input, new ShortType()); assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass()); assertArrayEquals("Image Dimensions: ", Intervals .dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res)); assertEquals("Image Factory: ", ArrayImgFactory.class, res.factory() .getClass()); }
Example #6
Source File: APNGWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") @Test public void testWriting_uint16() throws IOException { final ImgPlus<ByteType> sourceImg = (ImgPlus<ByteType>) opener.openImgs( new TestImgLocation.Builder().name("16bit-unsigned").pixelType("uint16") .axes("X", "Y", "C").lengths(100, 100, 3).build()).get(0); testWriting(sourceImg); final ImgPlus<ByteType> sourceImg2 = (ImgPlus<ByteType>) opener.openImgs( new TestImgLocation.Builder().name("16bit-unsigned").pixelType("uint16") .axes("X", "Y").lengths(100, 100).build()).get(0); testWriting(sourceImg2); }
Example #7
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImgLarge() { final long[] dims = new long[] { 3, 3 }; final byte[] array = new byte[9]; array[0] = (byte) 40; array[1] = (byte) 40; array[2] = (byte) 20; array[3] = (byte) 40; array[4] = (byte) 40; array[5] = (byte) 20; array[6] = (byte) 20; array[7] = (byte) 20; array[8] = (byte) 100; return ArrayImgs.bytes(array, dims); }
Example #8
Source File: SliceTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override @Before public void setUp() { context = new Context(OpService.class); ops = context.service(OpService.class); in = ArrayImgs.bytes(20, 20, 21); out = ArrayImgs.bytes(20, 20, 21); // fill array img with values (plane position = value in px); for (final Cursor<ByteType> cur = in.cursor(); cur.hasNext();) { cur.fwd(); cur.get().set((byte) cur.getIntPosition(2)); } }
Example #9
Source File: DefaultJsonServiceTest.java From imagej-server with Apache License 2.0 | 6 votes |
@Test public void deserializeSpecialTypes() throws Exception { final LinkedHashMap<String, Object> inputs = new LinkedHashMap<>(); final ByteType type = new ByteType(); final Img<ByteType> img0 = Imgs.create(new ArrayImgFactory<>(type), Intervals.createMinMax(0, 10, 0, 10), type); final Img<ByteType> img1 = Imgs.create(new PlanarImgFactory<>(type), Intervals.createMinMax(0, 10, 0, 10), type); final Foo foo = new Foo("test string"); inputs.put("img0", img0); inputs.put("img1", img1); inputs.put("foo", foo); objectService.register(img0, ""); objectService.register(img1, ""); objectService.register(foo, ""); @SuppressWarnings("unchecked") final Map<String, Object> deserialized = modifiedMapper.readValue(fixture( "fixtures/inputs/specialTypes.json"), Map.class); assertEquals(deserialized, inputs); }
Example #10
Source File: DilationTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testListDilate() { final List<Shape> shapes = new ArrayList<>(); shapes.add(new DiamondShape(1)); shapes.add(new DiamondShape(1)); shapes.add(new RectangleShape(1, false)); shapes.add(new HorizontalLineShape(2, 1, false)); @SuppressWarnings("unchecked") final IterableInterval<ByteType> out1 = (IterableInterval<ByteType>) ops .run(ListDilate.class, IterableInterval.class, in, shapes, false); final Img<ByteType> out2 = Dilation.dilate(in, shapes, 1); final Cursor<ByteType> c1 = out1.cursor(); final Cursor<ByteType> c2 = out2.cursor(); while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get()); }
Example #11
Source File: SliceTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testNonZeroMinimumInterval() { Img<ByteType> img3D = ArrayImgs.bytes(50, 50, 3); IntervalView<ByteType> interval2D = Views.interval(img3D, new FinalInterval(new long[] { 25, 25, 2 }, new long[] { 35, 35, 2 })); final int[] xyAxis = new int[] { 0, 1 }; // iterate through every slice, should return a single // RandomAccessibleInterval<?> from 25, 25, 2 to 35, 35, 2 final SlicesII<ByteType> hyperSlices = new SlicesII<>(interval2D, xyAxis, true); final Cursor<RandomAccessibleInterval<ByteType>> c = hyperSlices.cursor(); int i = 0; while (c.hasNext()) { c.next(); i++; } assertEquals(1, i); }
Example #12
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see LocalNiblackThresholdIntegral * @see LocalNiblackThreshold */ @Test public void testLocalNiblackResultsConsistency() { Img<BitType> out2 = null; Img<BitType> out3 = null; try { out2 = in.factory().imgFactory(new BitType()).create(in, new BitType()); out3 = in.factory().imgFactory(new BitType()).create(in, new BitType()); } catch (IncompatibleTypeException exc) { exc.printStackTrace(); } // Default implementation ops.run(LocalNiblackThreshold.class, out2, normalizedIn, new RectangleShape( 2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>( Boundary.SINGLE), 0.2, 1.0); // Integral image-based implementation ops.run(LocalNiblackThresholdIntegral.class, out3, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.2, 1.0); testIterableIntervalSimilarity(out2, out3); }
Example #13
Source File: MapTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIIAndIIInplaceParallelCellImg() { final Img<ByteType> first = generateByteTestCellImg(true, 40, 20); final Img<ByteType> firstCopy = first.copy(); final Img<ByteType> second = generateByteTestCellImg(false, 40, 20); for (final ByteType px : second) px.set((byte) 1); final Img<ByteType> secondCopy = second.copy(); sub = Inplaces.binary(ops, Ops.Math.Subtract.class, ByteType.class); final BinaryInplaceOp<? super Img<ByteType>, Img<ByteType>> map = Inplaces .binary(ops, MapIIAndIIInplaceParallel.class, firstCopy, second, sub); map.run(firstCopy, second, firstCopy); map.run(first, secondCopy, secondCopy); assertImgSubEquals(first, second, firstCopy); assertImgSubEquals(first, second, secondCopy); }
Example #14
Source File: DefaultBilateralTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testNegatives() { final byte[] data = { -7, -8, -9, -1, -2, -3, -7, -9, -8, -1, -3, -2, -8, -7, -9, -2, -1, -3, -8, -9, -7, -2, -3, -1, -9, -7, -8, -3, -1, -2, -9, -8, -7, -3, -2, -1 }; final Img<ByteType> in = ArrayImgs.bytes(data, 6, 6); final Img<ByteType> out = generateByteArrayTestImg(false, 6, 6); ops.run(DefaultBilateral.class, out, in, 15, 5, 2); final byte[] expected = { -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2 }; Cursor<ByteType> cout = out.cursor(); for (int i = 0; i < expected.length; i++) { assertEquals(cout.next().get(), expected[i]); } }
Example #15
Source File: MapCompatibleTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") @BeforeClass public static void init() { in1II = ArrayImgs.bytes(2, 2); in2II = ArrayImgs.bytes(2, 2); outII = ArrayImgs.bytes(2, 2); in1LargeII = ArrayImgs.bytes(3, 3); in2LargeII = ArrayImgs.bytes(3, 3); outLargeII = ArrayImgs.bytes(3, 3); in1RAI = (RandomAccessibleInterval<ByteType>) in1II; in2RAI = (RandomAccessibleInterval<ByteType>) in2II; outRAI = (RandomAccessibleInterval<ByteType>) outII; in1LargeRAI = (RandomAccessibleInterval<ByteType>) in1LargeII; in2LargeRAI = (RandomAccessibleInterval<ByteType>) in2LargeII; outLargeRAI = (RandomAccessibleInterval<ByteType>) outLargeII; }
Example #16
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see LocalMeanThresholdIntegral * @see LocalMeanThreshold */ @Test public void testLocalMeanResultsConsistency() { Img<BitType> out2 = null; Img<BitType> out3 = null; try { out2 = in.factory().imgFactory(new BitType()).create(in, new BitType()); out3 = in.factory().imgFactory(new BitType()).create(in, new BitType()); } catch (IncompatibleTypeException exc) { exc.printStackTrace(); } // Default implementation ops.run(LocalMeanThreshold.class, out2, in, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.0); // Integral image-based implementation ops.run(LocalMeanThresholdIntegral.class, out3, in, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>( Boundary.SINGLE), 0.0); testIterableIntervalSimilarity(out2, out3); }
Example #17
Source File: MergeLabelingTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMask() { final Img<BitType> mask = ops.create().img(in1, new BitType()); final RandomAccess<BitType> maskRA = mask.randomAccess(); maskRA.setPosition(new int[] { 0, 0 }); maskRA.get().set(true); maskRA.setPosition(new int[] { 1, 1 }); maskRA.get().set(true); @SuppressWarnings("unchecked") final MergeLabeling<Integer, ByteType, BitType> op = ops.op( MergeLabeling.class, out, in1, in2, mask); op.compute(in1, in2, out); final RandomAccess<LabelingType<Integer>> outRA = out.randomAccess(); outRA.setPosition(new int[] { 0, 0 }); assertTrue(outRA.get().contains(0)); assertTrue(outRA.get().contains(10)); outRA.setPosition(new int[] { 0, 1 }); assertTrue(outRA.get().isEmpty()); }
Example #18
Source File: DoGTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void dogRAITest() { final double[] sigmas1 = new double[] { 1, 1 }; final double[] sigmas2 = new double[] { 2, 2 }; final long[] dims = new long[] { 10, 10 }; final Img<ByteType> in = generateByteArrayTestImg(true, dims); final Img<ByteType> out1 = generateByteArrayTestImg(false, dims); final Img<ByteType> out2 = generateByteArrayTestImg(false, dims); ops.run(DoGVaryingSigmas.class, out1, in, sigmas1, sigmas2); // test against native imglib2 implementation DifferenceOfGaussian.DoG(sigmas1, sigmas2, Views.extendMirrorSingle(in), out2, Executors.newFixedThreadPool(10)); final Cursor<ByteType> out1Cursor = out1.cursor(); final Cursor<ByteType> out2Cursor = out2.cursor(); while (out1Cursor.hasNext()) { org.junit.Assert.assertEquals(out1Cursor.next().getRealDouble(), out2Cursor.next().getRealDouble(), 0); } }
Example #19
Source File: MapNeighborhoodTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Test if every neighborhood pixel of the image was really accessed during * the map operation. * * @see DefaultMapNeighborhood */ @Test public void testMapNeighborhoodsAccess() { final Op mapOp = ops.op(DefaultMapNeighborhood.class, out, in, new RectangleShape(1, false), new CountNeighbors()); mapOp.run(); for (final ByteType t : out) { assertEquals(9, t.get()); } }
Example #20
Source File: VolatileHierarchyProjector.java From paintera with GNU General Public License v2.0 | 5 votes |
/** * Clear target pixels that were never written. */ protected void clearUntouchedTargetPixels() { final Cursor< ByteType > maskCursor = Views.iterable( mask ).cursor(); for ( final B t : iterableTarget ) if ( maskCursor.next().get() == Byte.MAX_VALUE ) t.setZero(); }
Example #21
Source File: SliceTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void compute(final Iterable<ByteType> input, final Iterable<ByteType> output) { final Iterator<ByteType> itA = input.iterator(); final Iterator<ByteType> itB = output.iterator(); while (itA.hasNext() && itB.hasNext()) { itB.next().set(itA.next().get()); } }
Example #22
Source File: SquareIntegralImgTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see SquareIntegralImg */ @SuppressWarnings({ "unchecked" }) @Test public void testSquareIntegralImageCorrectness() { RandomAccessibleInterval<LongType> out1 = (RandomAccessibleInterval<LongType>) ops.run(SquareIntegralImg.class, generateKnownByteArrayTestImg()); Img<ByteType> bytes = generateKnownSquareIntegralImage(); LocalThresholdTest.testIterableIntervalSimilarity(Views.iterable(bytes), Views.iterable(out1)); }
Example #23
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see LocalYenThreshold */ @Test public void testLocalYenThreshold() { ops.run(Yen.class, out, in, new RectangleShape(1, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE)); assertEquals(false, out.firstElement().get()); }
Example #24
Source File: MapNeighborhoodTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void compute(final Iterable<ByteType> input, final ByteType output) { for (Iterator<ByteType> iter = input.iterator(); iter.hasNext(); iter .next()) { output.inc(); } }
Example #25
Source File: DilationTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testSingleDilateFull() { final Shape shape = new DiamondShape(1); @SuppressWarnings("unchecked") final Img<ByteType> out1 = (Img<ByteType>) ops.run(DefaultDilate.class, Img.class, in, shape, true); final Img<ByteType> out2 = Dilation.dilateFull(in, shape, 1); final Cursor<ByteType> c1 = out1.cursor(); final Cursor<ByteType> c2 = out2.cursor(); while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get()); }
Example #26
Source File: MapViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Before public void init() { final long[] dims = new long[] { 10, 10 }; in = generateByteArrayTestImg(false, dims); op = ops.op(NumericTypeBinaryMath.Add.class, null, NumericType.class, new ByteType((byte) 10)); }
Example #27
Source File: MapViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testRandomAccessibleIntervalView() { @SuppressWarnings("unchecked") final RandomAccessibleInterval<ByteType> res = (RandomAccessibleInterval<ByteType>) ops.run(MapViewRAIToRAI.class, in, op, new ByteType()); final Cursor<ByteType> iterable = Views.iterable(res).cursor(); while (iterable.hasNext()) { assertEquals((byte) 10, iterable.next().get()); } }
Example #28
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImgSmall() { final long[] dims = new long[] { 2, 2 }; final byte[] array = new byte[4]; array[0] = (byte) 10; array[1] = (byte) 20; array[2] = (byte) 30; array[3] = (byte) 40; return ArrayImgs.bytes(array, dims); }
Example #29
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see LocalBernsenThreshold */ @Test public void testLocalBernsenThreshold() { ops.run(LocalBernsenThreshold.class, out, in, new RectangleShape(3, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 1.0, Double.MAX_VALUE * 0.5); assertEquals(true, out.firstElement().get()); }
Example #30
Source File: DefaultImgUtilityService.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Converts ImgLib2 Type object to SCIFIO pixel type. */ @Override public int makeType(final Object type) throws ImgIOException { int pixelType = FormatTools.UINT8; if (type instanceof UnsignedByteType) { pixelType = FormatTools.UINT8; } else if (type instanceof ByteType) { pixelType = FormatTools.INT8; } else if (type instanceof UnsignedShortType) { pixelType = FormatTools.UINT16; } else if (type instanceof ShortType) { pixelType = FormatTools.INT16; } else if (type instanceof UnsignedIntType) { pixelType = FormatTools.UINT32; } else if (type instanceof IntType) { pixelType = FormatTools.INT32; } else if (type instanceof FloatType) { pixelType = FormatTools.FLOAT; } else if (type instanceof DoubleType) { pixelType = FormatTools.DOUBLE; } else { throw new ImgIOException("Pixel type not supported. " + "Please convert your image to a supported type."); } return pixelType; }