use of net.imglib2.Point in project imagej-ops by imagej.
the class PolygonFeatureTests method contour.
@Test
public void contour() {
// ground truth computed with matlab
final Polygon2D test = (Polygon2D) ops.run(DefaultContour.class, ROI, true);
final List<? extends RealLocalizable> expected = GeomUtils.vertices(contour);
final List<? extends RealLocalizable> received = GeomUtils.vertices(test);
assertEquals("Number of polygon points differs.", expected.size(), received.size());
for (int i = 0; i < contour.numVertices(); i++) {
assertEquals("Polygon point " + i + " differs in x-coordinate.", expected.get(i).getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
assertEquals("Polygon point " + i + " differs in y-coordinate.", expected.get(i).getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
}
}
use of net.imglib2.Point in project imagej-ops by imagej.
the class QuickHull3DTest method randomPointSet.
/**
* Creates a random point cloud.
*
* @param n number of points
* @param seed the seed
* @return random point cloud
*/
private LinkedHashSet<RealLocalizable> randomPointSet(int n, long seed) {
LinkedHashSet<RealLocalizable> points = new LinkedHashSet<>();
Random r = new Random(seed);
for (int i = 0; i < n; i++) {
points.add(new Vertex(r.nextDouble(), r.nextDouble(), r.nextDouble()));
}
return points;
}
use of net.imglib2.Point in project imagej-ops by imagej.
the class ConvolveTest method placeSphereInCenter.
// utility to place a small sphere at the center of the image
private void placeSphereInCenter(Img<FloatType> img) {
final Point center = new Point(img.numDimensions());
for (int d = 0; d < img.numDimensions(); d++) center.setPosition(img.dimension(d) / 2, d);
HyperSphere<FloatType> hyperSphere = new HyperSphere<>(img, center, 2);
for (final FloatType value : hyperSphere) {
value.setReal(1);
}
}
use of net.imglib2.Point in project imagej-ops by imagej.
the class ColocalisationTest method gaussianSmooth.
/**
* Gaussian Smooth of the input image using intermediate float format.
*
* @param <T>
* @param img
* @param sigma
* @return
*/
public static <T extends RealType<T> & NativeType<T>> Img<T> gaussianSmooth(RandomAccessibleInterval<T> img, double[] sigma) {
Interval interval = Views.iterable(img);
ImgFactory<T> outputFactory = new ArrayImgFactory<T>();
final long[] dim = new long[img.numDimensions()];
img.dimensions(dim);
Img<T> output = outputFactory.create(dim, img.randomAccess().get().createVariable());
final long[] pos = new long[img.numDimensions()];
Arrays.fill(pos, 0);
Localizable origin = new Point(pos);
ImgFactory<FloatType> tempFactory = new ArrayImgFactory<FloatType>();
RandomAccessible<T> input = Views.extendMirrorSingle(img);
Gauss.inFloat(sigma, input, interval, output, origin, tempFactory);
return output;
}
use of net.imglib2.Point 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