use of net.imglib2.Dimensions in project imagej-ops by imagej.
the class CreateLabelingTest method testImageFactory.
@SuppressWarnings("unchecked")
@Test
public void testImageFactory() {
final Dimensions dim = new FinalDimensions(10, 10, 10);
assertEquals("Labeling Factory: ", ArrayImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim, null, new ArrayImgFactory<IntType>())).getIndexImg()).factory().getClass());
assertEquals("Labeling Factory: ", CellImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim, null, new CellImgFactory<IntType>())).getIndexImg()).factory().getClass());
}
use of net.imglib2.Dimensions in project imagej-ops by imagej.
the class CreateImgTest method testImageMinimum.
@Test
public void testImageMinimum() {
final Random randomGenerator = new Random();
for (int i = 0; i < TEST_SIZE; i++) {
// between 2 and 5 dimensions
final long[] max = new long[randomGenerator.nextInt(4) + 2];
final long[] min = new long[max.length];
// between 2 and 10 pixels per dimensions
for (int j = 0; j < max.length; j++) {
max[j] = randomGenerator.nextInt(9) + 2;
min[j] = Math.max(0, max[j] - randomGenerator.nextInt(4));
}
// create img
final Img<?> img = (Img<?>) ops.run(CreateImgFromInterval.class, new FinalInterval(min, max));
assertArrayEquals("Image Minimum:", min, Intervals.minAsLongArray(img));
assertArrayEquals("Image Maximum:", max, Intervals.maxAsLongArray(img));
}
}
use of net.imglib2.Dimensions in project TrakEM2 by trakem2.
the class LinearIntensityMap method run.
@SuppressWarnings({ "rawtypes", "unchecked" })
public <S extends NumericType<S>> void run(final RandomAccessibleInterval<S> image) {
assert image.numDimensions() == dimensions.numDimensions() : "Number of dimensions do not match.";
final double[] s = new double[dimensions.numDimensions()];
for (int d = 0; d < s.length; ++d) s[d] = image.dimension(d) / dimensions.dimension(d);
final Scale scale = new Scale(s);
// System.out.println( "translation-n " + translation.numDimensions() );
final RandomAccessibleInterval<RealComposite<T>> stretchedCoefficients = Views.offsetInterval(Views.raster(RealViews.transform(RealViews.transform(coefficients, translation), scale)), image);
/* decide on type which mapping to use */
final S t = image.randomAccess().get();
if (ARGBType.class.isInstance(t))
mapARGB(Views.flatIterable((RandomAccessibleInterval<ARGBType>) image), Views.flatIterable(stretchedCoefficients));
else if (RealComposite.class.isInstance(t))
mapComposite(Views.flatIterable((RandomAccessibleInterval) image), Views.flatIterable(stretchedCoefficients));
else if (RealType.class.isInstance(t)) {
final RealType<?> r = (RealType) t;
if (r.getMinValue() > -Double.MAX_VALUE || r.getMaxValue() < Double.MAX_VALUE)
// TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
mapCrop(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
else
// TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
map(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
}
}
Aggregations