net.imglib2.type.logic.BitType Java Examples
The following examples show how to use
net.imglib2.type.logic.BitType.
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: DistanceTransform3DTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") @Test public void test() { // create 3D image final RandomAccessibleInterval<BitType> in = ops.create().img(new FinalInterval(20, 20, 5), new BitType()); generate3DImg(in); /* * test normal DT */ RandomAccessibleInterval<FloatType> out = (RandomAccessibleInterval<FloatType>) ops .run(DistanceTransform3D.class, null, in); compareResults(out, in, new double[] { 1, 1, 1 }); /* * test calibrated DT */ final double[] calibration = new double[] { 3.74, 5.19, 1.21 }; out = (RandomAccessibleInterval<FloatType>) ops.run(DistanceTransform3DCalibration.class, null, in, calibration); compareResults(out, in, calibration); }
Example #2
Source File: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the max of an image with respect to a mask. * * @param img The image to calculate the min of * @param mask The mask to respect * @return The min of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMax( final RandomAccessibleInterval<T> img, final RandomAccessibleInterval<BitType> mask ) { // create cursor to walk an image with respect to a mask final TwinCursor<T> cursor = new TwinCursor<T>( img.randomAccess(), img.randomAccess(), Views.iterable(mask).localizingCursor()); // forward one step to get the first value cursor.fwd(); final T max = cursor.getFirst().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.getFirst(); if ( currValue.compareTo( max ) > 0 ) max.set( currValue ); } return max; }
Example #3
Source File: DefaultDistanceTransformTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") @Test public void test() { // create 4D image final RandomAccessibleInterval<BitType> in = ops.create().img(new FinalInterval(20, 20, 5, 3), new BitType()); generate4DImg(in); /* * test normal DT */ RandomAccessibleInterval<FloatType> out = (RandomAccessibleInterval<FloatType>) ops .run(DefaultDistanceTransform.class, null, in); compareResults(out, in, new double[] { 1, 1, 1, 1 }); /* * test calibrated DT */ final double[] calibration = new double[] { 3.74, 5.19, 1.21, 2.21 }; out = (RandomAccessibleInterval<FloatType>) ops.run(DefaultDistanceTransformCalibration.class, null, in, calibration); compareResults(out, in, calibration); }
Example #4
Source File: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the min of an image with respect to a mask. * * @param img The image to calculate the min of * @param mask The mask to respect * @return The min of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMin( final RandomAccessibleInterval<T> img, final RandomAccessibleInterval<BitType> mask ) { // create cursor to walk an image with respect to a mask final TwinCursor<T> cursor = new TwinCursor<T>( img.randomAccess(), img.randomAccess(), Views.iterable(mask).localizingCursor()); // forward one step to get the first value cursor.fwd(); // copy first element as current minimum final T min = cursor.getFirst().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.getFirst(); if ( currValue.compareTo( min ) < 0 ) min.set( currValue ); } return min; }
Example #5
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 #6
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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); } }
Example #7
Source File: DistanceTransform2DTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") @Test public void test() { // create 2D image final RandomAccessibleInterval<BitType> in = ops.create().img(new FinalInterval(20, 20), new BitType()); generate2DImg(in); /* * test normal DT */ RandomAccessibleInterval<FloatType> out = (RandomAccessibleInterval<FloatType>) ops .run(DistanceTransform2D.class, null, in); compareResults(out, in, new double[] { 1, 1 }); /* * test calibrated DT */ final double[] calibration = new double[] { 2.54, 1.77 }; out = (RandomAccessibleInterval<FloatType>) ops.run(DistanceTransform2DCalibration.class, null, in, calibration); compareResults(out, in, calibration); }
Example #8
Source File: LiICQ.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
@Override public void execute(DataContainer<T> container) throws MissingPreconditionException { double mean1 = container.getMeanCh1(); double mean2 = container.getMeanCh2(); // get the 2 images for the calculation of Li's ICQ RandomAccessible<T> img1 = container.getSourceImage1(); RandomAccessible<T> img2 = container.getSourceImage2(); RandomAccessibleInterval<BitType> mask = container.getMask(); TwinCursor<T> cursor = new TwinCursor<T>(img1.randomAccess(), img2.randomAccess(), Views.iterable(mask).localizingCursor()); // calculate ICQ value icqValue = calculateLisICQ(cursor, mean1, mean2); }
Example #9
Source File: Morphologies.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Computes the min coordinate and the size of an {@link Interval} after * padding with a list of {@link Shape}s in a series morphology operations. * * @param source the interval to be applied with some morphology operation * @param shapes the list of Shapes for padding * @return a size-2 array storing the min coordinate and the size of the * padded interval */ public static final long[][] computeMinSize(final Interval source, final List<Shape> shapes) { final int numDims = source.numDimensions(); final long[] min = new long[numDims]; final long[] size = new long[numDims]; for (int i = 0; i < numDims; i++) { min[i] = source.min(i); size[i] = source.dimension(i); } for (final Shape shape : shapes) { final Neighborhood<BitType> nh = MorphologyUtils.getNeighborhood(shape, source); for (int i = 0; i < numDims; i++) { min[i] += nh.min(i); size[i] += nh.dimension(i) - 1; } } return new long[][] { min, size }; }
Example #10
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see LocalSauvolaThresholdIntegral * @see LocalSauvolaThreshold */ @Test public void testLocalSauvolaResultsConsistency() { 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(LocalSauvolaThreshold.class, out2, normalizedIn, new RectangleShape( 2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>( Boundary.SINGLE), 0.5, 0.5); // Integral image-based implementation ops.run(LocalSauvolaThresholdIntegral.class, out3, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.5, 0.5); testIterableIntervalSimilarity(out2, out3); }
Example #11
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.Percentile.class) public <T extends RealType<T>> IterableInterval<BitType> percentile(final IterableInterval<BitType> out, final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops().run( net.imagej.ops.Ops.Threshold.Percentile.class, out, in); return result; }
Example #12
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.Shanbhag.class) public <T extends RealType<T>> IterableInterval<BitType> shanbhag(final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops().run( net.imagej.ops.Ops.Threshold.Shanbhag.class, in); return result; }
Example #13
Source File: MaskAndRoiTest.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * This test creates first an "always true" mask and count the data * values. There should be as many as the number of vocels in total. * After that an "always false" mask is created. The predicate cursor * there should not return any values. */ @Test public void simpleMaskCreationTest() { final RandomAccessibleInterval<UnsignedByteType> img = positiveCorrelationImageCh1; // first, create an always true mask final long[] dim = new long[ img.numDimensions() ]; img.dimensions(dim); RandomAccessibleInterval<BitType> mask = MaskFactory.createMask(dim, true); final Predicate<BitType> predicate = new MaskPredicate(); Cursor<BitType> cursor = new PredicateCursor<BitType>( Views.iterable(mask).localizingCursor(), predicate); // iterate over mask and count values long count = 0; while (cursor.hasNext()) { cursor.fwd(); count++; assertTrue(cursor.get().get()); } assertEquals(ImageStatistics.getNumPixels(mask), count); // second, create an always false mask mask = MaskFactory.createMask(dim, false); cursor = new PredicateCursor<BitType>( Views.iterable(mask).localizingCursor(), predicate); // iterate over mask and count values count = 0; while (cursor.hasNext()) { cursor.fwd(); count++; } assertEquals(0, count); }
Example #14
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.Otsu.class) public <T extends RealType<T>> IterableInterval<BitType> otsu(final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops().run( net.imagej.ops.Ops.Threshold.Otsu.class, in); return result; }
Example #15
Source File: BooleanTypeLogicTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testNot() { assertFalse(((BitType) ops.run(BooleanTypeLogic.Not.class, new BitType( true))).get()); assertTrue(((BitType) ops.run(BooleanTypeLogic.Not.class, new BitType( false))).get()); }
Example #16
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.Moments.class) public <T extends RealType<T>> IterableInterval<BitType> moments(final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run( net.imagej.ops.Ops.Threshold.Moments.class, in); return result; }
Example #17
Source File: DefaultFillHoles.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void initialize() { createFunc = RAIs.function(ops(), CreateImgFromDimsAndType.class, in(), new BitType()); floodFillComp = (BinaryComputerOp) Computers.binary(ops(), Ops.Morphology.FloodFill.class, RandomAccessibleInterval.class, in(), Localizable.class, structElement); }
Example #18
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.MaxLikelihood.class) public <T extends RealType<T>> IterableInterval<BitType> maxLikelihood(final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run( net.imagej.ops.Ops.Threshold.MaxLikelihood.class, in); return result; }
Example #19
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.Yen.class) public <T extends RealType<T>> IterableInterval<BitType> yen(final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops().run( net.imagej.ops.Ops.Threshold.Yen.class, in); return result; }
Example #20
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.localSauvola.LocalSauvolaThresholdIntegral.class) public <T extends RealType<T>> IterableInterval<BitType> localSauvolaThreshold(final IterableInterval<BitType> out, final RandomAccessibleInterval<T> in, final RectangleShape shape) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run(net.imagej.ops.Ops.Threshold.LocalSauvolaThreshold.class, out, in, shape); return result; }
Example #21
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private int countForeground(final IterableInterval<BitType> interval) { int count = 0; for (final BitType element : interval) { count = count + element.getInteger(); } return count; }
Example #22
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.localSauvola.LocalSauvolaThresholdIntegral.class) public <T extends RealType<T>> IterableInterval<BitType> localSauvolaThreshold(final IterableInterval<BitType> out, final RandomAccessibleInterval<T> in, final RectangleShape shape, final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBounds, final double k, final double r) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run(net.imagej.ops.Ops.Threshold.LocalSauvolaThreshold.class, out, in, shape, outOfBounds, k, r); return result; }
Example #23
Source File: ThinningTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testThinHilditch() { @SuppressWarnings("unchecked") final Img<BitType> out = (Img<BitType>) ops.run(ThinHilditch.class, Img.class, in); final Img<BitType> target = ops.convert().bit(openFloatImg( AbstractThin.class, "result_hilditch.tif")); assertIterationsEqual(target, out); }
Example #24
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.ApplyThresholdMethod.Yen.class) public <T extends RealType<T>> IterableInterval<BitType> yen(final IterableInterval<BitType> out, final IterableInterval<T> in) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops().run( net.imagej.ops.Ops.Threshold.Yen.class, out, in); return result; }
Example #25
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.localPhansalkar.LocalPhansalkarThresholdIntegral.class) public <T extends RealType<T>> IterableInterval<BitType> localPhansalkarThreshold(final IterableInterval<BitType> out, final RandomAccessibleInterval<T> in, final RectangleShape shape, final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBounds, final double k, final double r) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run(net.imagej.ops.Ops.Threshold.LocalPhansalkarThreshold.class, out, in, shape, outOfBounds, k, r); return result; }
Example #26
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.localPhansalkar.LocalPhansalkarThreshold.class) public <T extends RealType<T>> IterableInterval<BitType> localPhansalkarThreshold(final IterableInterval<BitType> out, final RandomAccessibleInterval<T> in, final Shape shape) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run( net.imagej.ops.Ops.Threshold.LocalPhansalkarThreshold.class, out, in, shape); return result; }
Example #27
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod( op = net.imagej.ops.threshold.localPhansalkar.LocalPhansalkarThreshold.class) public <T extends RealType<T>> IterableInterval<BitType> localPhansalkarThreshold(final IterableInterval<BitType> out, final RandomAccessibleInterval<T> in, final Shape shape, final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBounds) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops() .run( net.imagej.ops.Ops.Threshold.LocalPhansalkarThreshold.class, out, in, shape, outOfBounds); return result; }
Example #28
Source File: ThresholdNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.threshold.localBernsen.LocalBernsenThreshold.class) public <T extends RealType<T>> IterableInterval<BitType> localBernsenThreshold( final IterableInterval<BitType> out, final RandomAccessibleInterval<T> in, final Shape shape, final double contrastThreshold, final double halfMaxValue) { @SuppressWarnings("unchecked") final IterableInterval<BitType> result = (IterableInterval<BitType>) ops().run( net.imagej.ops.Ops.Threshold.LocalBernsenThreshold.class, out, in, shape, contrastThreshold, halfMaxValue); return result; }
Example #29
Source File: MaskAndRoiTest.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * Tests against the implementation of irregular ROIs alias * masks. Masks can also be produced by mask images open in * another Fiji window. * * This test generates a random black/white noise image and * uses first itself and then an inverted version of it as * mask. While iterating over it, the pixel values are * checked. Is the first version only non-zero values should * be present, while only zeros should be there in the second * one. */ @Test public void irregularRoiTest() { // create a random noise 2D image -- set roiWidh/roiSize accordingly RandomAccessibleInterval<UnsignedByteType> img = TestImageAccessor.produceSticksNoiseImage(300, 300, 50, 2, 10); final long[] dim = new long[ img.numDimensions() ]; img.dimensions(dim); /* first test - using itself as a mask */ RandomAccessibleInterval<BitType> mask = MaskFactory.createMask(dim, img); TwinCursor<UnsignedByteType> cursor = new TwinCursor<UnsignedByteType>( img.randomAccess(), img.randomAccess(), Views.iterable(mask).localizingCursor()); while (cursor.hasNext()) { cursor.fwd(); assertTrue( cursor.getFirst().getInteger() != 0 ); } /* second test - using inverted image */ RandomAccessibleInterval<UnsignedByteType> invImg = TestImageAccessor.invertImage(img); RandomAccessibleInterval<BitType> invMask = MaskFactory.createMask(dim, invImg); cursor = new TwinCursor<UnsignedByteType>( img.randomAccess(), img.randomAccess(), Views.iterable(invMask).localizingCursor()); while (cursor.hasNext()) { cursor.fwd(); assertEquals( 0, cursor.getFirst().getInteger() ); } }
Example #30
Source File: MandersColocalization.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
@Override public void execute(DataContainer<T> container) throws MissingPreconditionException { // get the two images for the calculation of Manders' split coefficients RandomAccessible<T> img1 = container.getSourceImage1(); RandomAccessible<T> img2 = container.getSourceImage2(); RandomAccessibleInterval<BitType> mask = container.getMask(); TwinCursor<T> cursor = new TwinCursor<T>(img1.randomAccess(), img2.randomAccess(), Views.iterable(mask).localizingCursor()); // calculate Manders' split coefficients without threshold, M1 and M2. MandersResults results = calculateMandersCorrelation(cursor, img1.randomAccess().get().createVariable()); // save the results mandersM1 = results.m1; mandersM2 = results.m2; // calculate the thresholded Manders' split coefficients, tM1 and tM2, if possible AutoThresholdRegression<T> autoThreshold = container.getAutoThreshold(); if (autoThreshold != null ) { // thresholded Manders' split coefficients, tM1 and tM2 cursor.reset(); results = calculateMandersCorrelation(cursor, autoThreshold.getCh1MaxThreshold(), autoThreshold.getCh2MaxThreshold(), ThresholdMode.Above); // save the results mandersThresholdedM1 = results.m1; mandersThresholdedM2 = results.m2; } }