Search in sources :

Example 16 with Dimensions

use of net.imglib2.Dimensions in project imagej-ops by imagej.

the class CreateLabelingTest method testImageDimensions.

@Test
public void testImageDimensions() {
    final Random randomGenerator = new Random();
    for (int i = 0; i < TEST_SIZE; i++) {
        // between 2 and 5 dimensions
        final long[] dim = new long[randomGenerator.nextInt(4) + 2];
        // between 2 and 10 pixels per dimensions
        for (int j = 0; j < dim.length; j++) {
            dim[j] = randomGenerator.nextInt(9) + 2;
        }
        // create imglabeling
        @SuppressWarnings("unchecked") final ImgLabeling<String, ?> img = (ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim);
        assertArrayEquals("Labeling Dimensions:", dim, Intervals.dimensionsAsLongArray(img));
    }
}
Also used : Random(java.util.Random) DefaultCreateImgLabeling(net.imagej.ops.create.imgLabeling.DefaultCreateImgLabeling) ImgLabeling(net.imglib2.roi.labeling.ImgLabeling) DefaultCreateImgLabeling(net.imagej.ops.create.imgLabeling.DefaultCreateImgLabeling) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 17 with Dimensions

use of net.imglib2.Dimensions in project imagej-ops by imagej.

the class CreateKernelDiffractionTest method testKernelDiffraction.

@Test
public void testKernelDiffraction() {
    final Dimensions dims = new FinalDimensions(10, 10);
    // numerical aperture
    final double NA = 1.4;
    // wavelength
    final double lambda = 610E-09;
    // specimen refractive index
    final double ns = 1.33;
    // immersion refractive index, experimental
    final double ni = 1.5;
    // lateral pixel size
    final double resLateral = 100E-9;
    // axial pixel size
    final double resAxial = 250E-9;
    // position of particle
    final double pZ = 2000E-9D;
    // pixel type of created kernel
    final DoubleType type = new DoubleType();
    final // 
    Img<DoubleType> kernel = ops.create().kernelDiffraction(dims, NA, lambda, ns, ni, resLateral, resAxial, pZ, type);
    final double[] expected = { 0.03298495871588273, 0.04246786111102021, 0.0543588031627261, 0.06650574371357207, 0.07370280610722534, 0.07370280610722534, 0.06650574371357207, 0.0543588031627261, 0.04246786111102021, 0.03298495871588273, 0.04246786111102021, 0.05962205221267819, 0.08320071670150801, 0.10800022978800021, 0.1247473245002288, 0.1247473245002288, 0.10800022978800021, 0.08320071670150801, 0.05962205221267819, 0.04246786111102021, 0.0543588031627261, 0.08320071670150801, 0.1247473245002288, 0.1971468112729564, 0.2691722397359577, 0.2691722397359577, 0.1971468112729564, 0.1247473245002288, 0.08320071670150801, 0.0543588031627261, 0.06650574371357207, 0.10800022978800021, 0.1971468112729564, 0.40090474481128285, 0.6227157103102976, 0.6227157103102976, 0.40090474481128285, 0.1971468112729564, 0.10800022978800021, 0.06650574371357207, 0.07370280610722534, 0.1247473245002288, 0.2691722397359577, 0.6227157103102976, 1.0, 1.0, 0.6227157103102976, 0.2691722397359577, 0.1247473245002288, 0.07370280610722534, 0.07370280610722534, 0.1247473245002288, 0.2691722397359577, 0.6227157103102976, 1.0, 1.0, 0.6227157103102976, 0.2691722397359577, 0.1247473245002288, 0.07370280610722534, 0.06650574371357207, 0.10800022978800021, 0.1971468112729564, 0.40090474481128285, 0.6227157103102976, 0.6227157103102976, 0.40090474481128285, 0.1971468112729564, 0.10800022978800021, 0.06650574371357207, 0.0543588031627261, 0.08320071670150801, 0.1247473245002288, 0.1971468112729564, 0.2691722397359577, 0.2691722397359577, 0.1971468112729564, 0.1247473245002288, 0.08320071670150801, 0.0543588031627261, 0.04246786111102021, 0.05962205221267819, 0.08320071670150801, 0.10800022978800021, 0.1247473245002288, 0.1247473245002288, 0.10800022978800021, 0.08320071670150801, 0.05962205221267819, 0.04246786111102021, 0.03298495871588273, 0.04246786111102021, 0.0543588031627261, 0.06650574371357207, 0.07370280610722534, 0.07370280610722534, 0.06650574371357207, 0.0543588031627261, 0.04246786111102021, 0.03298495871588273 };
    assertArrayEquals(expected, asArray(kernel), 0.0);
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalDimensions(net.imglib2.FinalDimensions) Dimensions(net.imglib2.Dimensions) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 18 with Dimensions

use of net.imglib2.Dimensions in project imagej-ops by imagej.

the class BoxCount method countTranslatedGrids.

/**
 * Count foreground sections in all grids created from the translations
 *
 * @param input N-dimensional binary interval
 * @param translations Stream of translation coordinates in n-dimensions
 * @param sizes Sizes of the interval's dimensions in pixels
 * @param sectionSize Size of a section in the grids
 * @return Foreground sections counted in each grid
 */
private static <B extends BooleanType<B>> LongStream countTranslatedGrids(final RandomAccessibleInterval<B> input, final Stream<long[]> translations, final long[] sizes, final long sectionSize) {
    final int lastDimension = sizes.length - 1;
    final LongType foreground = new LongType();
    final long[] sectionPosition = new long[sizes.length];
    return translations.mapToLong(gridOffset -> {
        foreground.setZero();
        Arrays.fill(sectionPosition, 0);
        countGrid(input, lastDimension, sizes, gridOffset, sectionPosition, sectionSize, foreground);
        return foreground.get();
    });
}
Also used : LongType(net.imglib2.type.numeric.integer.LongType)

Example 19 with Dimensions

use of net.imglib2.Dimensions in project imagej-ops by imagej.

the class BoxCount method sectionView.

/**
 * Creates a {@link net.imglib2.View} of the given grid section in the
 * interval
 * <p>
 * Fits the view inside the bounds of the interval.
 * </p>
 *
 * @param interval An n-dimensional interval with binary elements
 * @param sizes Sizes of the interval's dimensions
 * @param coordinates Starting coordinates of the section
 * @param sectionSize Size of the section (n * n * ... n)
 * @return A view of the interval spanning n pixels in each dimension from the
 *         coordinates. Null if view couldn't be set inside the interval
 */
private static <B extends BooleanType<B>> IntervalView<B> sectionView(final RandomAccessibleInterval<B> interval, final long[] sizes, final long[] coordinates, final long sectionSize) {
    final int n = sizes.length;
    final long[] startPosition = IntStream.range(0, n).mapToLong(i -> Math.max(0, coordinates[i])).toArray();
    final long[] endPosition = IntStream.range(0, n).mapToLong(i -> Math.min((sizes[i] - 1), (coordinates[i] + sectionSize - 1))).toArray();
    final boolean badBox = IntStream.range(0, n).anyMatch(d -> (startPosition[d] >= sizes[d]) || (endPosition[d] < 0) || (endPosition[d] < startPosition[d]));
    if (badBox) {
        return null;
    }
    final BoundingBox box = new BoundingBox(n);
    box.update(startPosition);
    box.update(endPosition);
    return Views.offsetInterval(interval, box);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) LongStream(java.util.stream.LongStream) Parameter(org.scijava.plugin.Parameter) BoundingBox(net.imglib2.roi.labeling.BoundingBox) AbstractUnaryFunctionOp(net.imagej.ops.special.function.AbstractUnaryFunctionOp) ArrayList(java.util.ArrayList) ValuePair(net.imglib2.util.ValuePair) IntervalView(net.imglib2.view.IntervalView) Plugin(org.scijava.plugin.Plugin) List(java.util.List) Stream(java.util.stream.Stream) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) BooleanType(net.imglib2.type.BooleanType) DoubleType(net.imglib2.type.numeric.real.DoubleType) Ops(net.imagej.ops.Ops) StreamSupport(java.util.stream.StreamSupport) LongType(net.imglib2.type.numeric.integer.LongType) Spliterator(java.util.Spliterator) Views(net.imglib2.view.Views) BoundingBox(net.imglib2.roi.labeling.BoundingBox)

Example 20 with Dimensions

use of net.imglib2.Dimensions in project imagej-ops by imagej.

the class BoxCount method calculate.

/**
 * Counts the number of foreground sections in the interval repeatedly with
 * different size sections
 *
 * @param input an n-dimensional binary interval
 * @return A list of (log(foreground count), -log(section size))
 *         {@link ValuePair} objects for curve fitting
 */
@Override
public List<ValuePair<DoubleType, DoubleType>> calculate(final RandomAccessibleInterval<B> input) {
    final List<ValuePair<DoubleType, DoubleType>> points = new ArrayList<>();
    final int dimensions = input.numDimensions();
    final long[] sizes = new long[dimensions];
    final long numTranslations = 1 + gridMoves;
    input.dimensions(sizes);
    for (long sectionSize = maxSize; sectionSize >= minSize; sectionSize /= scaling) {
        final long translationAmount = Math.max(1, sectionSize / numTranslations);
        final Stream<long[]> translations = translationStream(numTranslations, translationAmount, dimensions - 1, new long[dimensions]);
        final LongStream foregroundCounts = countTranslatedGrids(input, translations, sizes, sectionSize);
        final long foreground = foregroundCounts.min().orElse(0);
        final double logSize = -Math.log(sectionSize);
        final double logCount = Math.log(foreground);
        final ValuePair<DoubleType, DoubleType> point = new ValuePair<>(new DoubleType(logSize), new DoubleType(logCount));
        points.add(point);
    }
    return points;
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ValuePair(net.imglib2.util.ValuePair) ArrayList(java.util.ArrayList) LongStream(java.util.stream.LongStream)

Aggregations

AbstractOpTest (net.imagej.ops.AbstractOpTest)14 Img (net.imglib2.img.Img)14 Test (org.junit.Test)14 DoubleType (net.imglib2.type.numeric.real.DoubleType)13 FinalDimensions (net.imglib2.FinalDimensions)12 Dimensions (net.imglib2.Dimensions)10 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)9 FinalInterval (net.imglib2.FinalInterval)8 FloatType (net.imglib2.type.numeric.real.FloatType)8 Ops (net.imagej.ops.Ops)6 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)5 BitType (net.imglib2.type.logic.BitType)5 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)4 File (java.io.File)3 Dataset (net.imagej.Dataset)3 IntegralCursor (net.imagej.ops.image.integral.IntegralCursor)3 ByteType (net.imglib2.type.numeric.integer.ByteType)3 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)3