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));
}
}
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);
}
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();
});
}
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);
}
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;
}
Aggregations