net.imglib2.img.array.ArrayImgFactory Java Examples

The following examples show how to use net.imglib2.img.array.ArrayImgFactory. 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: CollapseNumericViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultCollapseNumericTest() {

	Img<NativeARGBDoubleType> img = new ArrayImgFactory<NativeARGBDoubleType>().create(new int[] { 10, 10 },
			new NativeARGBDoubleType());

	CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2 = Views
			.collapseNumeric((RandomAccessibleInterval<NativeARGBDoubleType>) img);
	CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr = ops.transform()
			.collapseNumericView((RandomAccessibleInterval<NativeARGBDoubleType>) img);

	assertEquals(il2.numDimensions(), opr.numDimensions());

	CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2_2 = Views
			.collapseNumeric((RandomAccessible<NativeARGBDoubleType>) img, 1);
	CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr_2 = ops.transform()
			.collapseNumericView((RandomAccessible<NativeARGBDoubleType>) img, 1);

	assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
 
Example #2
Source File: MathBenchmarkTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Before
public void setUpImgs() {
	// create an input
	img1 = createConstantImg(new long[] { x, y }, 1.0f);
	img2 = createConstantImg(new long[] { x, y }, 2.0f);
	img3 = createConstantImg(new long[] { x, y }, 3.0f);
	imgzero = createConstantImg(new long[] { x, y }, 0.0f);

	byteimg = new ArrayImgFactory<ByteType>().create(new long[] { 20000,
		20000 }, new ByteType());

	float1 = new float[(int) size];
	float2 = new float[(int) size];
	float3 = new float[(int) size];
	float4 = new float[(int) size];

	for (int i = 0; i < size; i++) {
		float1[i] = 1.0f;
		float2[i] = 2.0f;
		float3[i] = 3.0f;
		float4[i] = 0.0f;

	}

}
 
Example #3
Source File: FastFusionTools.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args)
{
	final ImagePlus imp = IJ.openImage( "/Users/david/Desktop/stable HelaK-GFP-H2A.Z20000.tif" );
	new ImageJ();

	RandomAccessibleInterval< ? extends RealType > img = ImageJFunctions.wrapReal( imp );
	ArrayImg< FloatType, FloatArray > f = ArrayImgs.floats( 1024, 1024 );
	ArrayImg< FloatType, FloatArray > w = ArrayImgs.floats( 1024, 1024 );
	RandomAccessibleInterval< FloatType > interp = (RandomAccessibleInterval< FloatType >) getLinearInterpolation( img, new FloatType(), new float[] {0.5f,0.5f}, Executors.newSingleThreadExecutor() ).getA();
	
	RandomAccessibleInterval< FloatType > weight = new ArrayImgFactory( new FloatType() ).create( interp );
	applyWeights( interp, weight, new float[] {0.5f,0.5f}, new float[] {0,0}, new float[] {20,20}, false, Executors.newSingleThreadExecutor() );
	addTranslated( Views.iterable( interp ), f, new int[] {500, 700}, Executors.newSingleThreadExecutor() );
	addTranslated( Views.iterable( interp ), f, new int[] {400, 500}, Executors.newSingleThreadExecutor() );
	addTranslated( Views.iterable( weight ), w, new int[] {500, 700}, Executors.newSingleThreadExecutor() );
	addTranslated( Views.iterable( weight ), w, new int[] {400, 500}, Executors.newSingleThreadExecutor() );

	normalizeWeights( f, w, Executors.newSingleThreadExecutor() );
	
	ImageJFunctions.show( f );
}
 
Example #4
Source File: DefaultJsonServiceTest.java    From imagej-server with Apache License 2.0 6 votes vote down vote up
@Test
public void deserializeSpecialTypes() throws Exception {
	final LinkedHashMap<String, Object> inputs = new LinkedHashMap<>();
	final ByteType type = new ByteType();
	final Img<ByteType> img0 = Imgs.create(new ArrayImgFactory<>(type),
		Intervals.createMinMax(0, 10, 0, 10), type);
	final Img<ByteType> img1 = Imgs.create(new PlanarImgFactory<>(type),
		Intervals.createMinMax(0, 10, 0, 10), type);
	final Foo foo = new Foo("test string");
	inputs.put("img0", img0);
	inputs.put("img1", img1);
	inputs.put("foo", foo);

	objectService.register(img0, "");
	objectService.register(img1, "");
	objectService.register(foo, "");

	@SuppressWarnings("unchecked")
	final Map<String, Object> deserialized = modifiedMapper.readValue(fixture(
		"fixtures/inputs/specialTypes.json"), Map.class);

	assertEquals(deserialized, inputs);
}
 
Example #5
Source File: CollapseRealViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultCollapseRealTest() {

	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 },
			new DoubleType());

	CompositeIntervalView<DoubleType, RealComposite<DoubleType>> il2 = Views
			.collapseReal((RandomAccessibleInterval<DoubleType>) img);
	CompositeIntervalView<DoubleType, RealComposite<DoubleType>> opr = ops.transform()
			.collapseRealView((RandomAccessibleInterval<DoubleType>) img);

	assertEquals(il2.numDimensions(), opr.numDimensions());

	CompositeView<DoubleType, RealComposite<DoubleType>> il2_2 = Views
			.collapseReal((RandomAccessible<DoubleType>) img, 1);
	CompositeView<DoubleType, RealComposite<DoubleType>> opr_2 = ops.transform()
			.collapseRealView((RandomAccessible<DoubleType>) img, 1);

	assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
 
Example #6
Source File: TestImageAccessor.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts an arbitrary image to a black/white version of it.
 * All image data lower or equal the splitValue will get black,
 * the rest will turn white.
 */
public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> makeBinaryImage(
		RandomAccessibleInterval<T> image, T splitValue) {
	Cursor<T> imgCursor = Views.iterable(image).localizingCursor();
	// make a new image of the same type, but binary
	long[] dim = new long[ image.numDimensions() ];
	image.dimensions(dim);
	ArrayImgFactory<T> imgFactory = new ArrayImgFactory<T>();
	RandomAccessibleInterval<T> binImg = imgFactory.create( dim,
			image.randomAccess().get().createVariable() ); // "Binary image of " + image.getName());
	RandomAccess<T> invCursor = binImg.randomAccess();

	while (imgCursor.hasNext()) {
		imgCursor.fwd();
		invCursor.setPosition(imgCursor);
		T currentValue = invCursor.get();
		if (currentValue.compareTo(splitValue) > 0)
			currentValue.setReal(  currentValue.getMaxValue() );
		else
			currentValue.setZero();
	}

	return binImg;
}
 
Example #7
Source File: ShearViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Tests {@link DefaultShearView}. */
@Test
public void defaultShearTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
	Cursor<DoubleType> imgC = img.cursor();
	while (imgC.hasNext()) {
		imgC.next().set(1);
	}

	TransformView<DoubleType> il2 = Views.shear(Views.extendZero(img), 0, 1);
	TransformView<DoubleType> opr = ops.transform().shearView(Views.extendZero(img), 0, 1);
	Cursor<DoubleType> il2C = Views.interval(il2, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }))
			.cursor();
	RandomAccess<DoubleType> oprRA = Views
			.interval(opr, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).randomAccess();

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
}
 
Example #8
Source File: RasterViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultRasterTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10,  10}, new DoubleType());
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}
	RealRandomAccessible<DoubleType> realImg = Views.interpolate(img, new FloorInterpolatorFactory<DoubleType>());
	
	RandomAccessibleOnRealRandomAccessible<DoubleType> il2 = Views.raster(realImg);
	RandomAccessibleOnRealRandomAccessible<DoubleType> opr = ops.transform().rasterView(realImg);
	
	Cursor<DoubleType> il2C = Views.interval(il2, img).localizingCursor();
	RandomAccess<DoubleType> oprRA = Views.interval(opr, img).randomAccess();
	
	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
}
 
Example #9
Source File: UnshearViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultUnshearTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
	Cursor<DoubleType> imgC = img.cursor();
	while (imgC.hasNext()) {
		imgC.next().set(1);
	}

	TransformView<DoubleType> il2 = Views.unshear(Views.shear(Views.extendZero(img), 0, 1), 0, 1);
	TransformView<DoubleType> opr = ops.transform().unshearView(Views.shear(Views.extendZero(img), 0, 1), 0, 1);
	Cursor<DoubleType> il2C = Views.interval(il2, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }))
			.cursor();
	RandomAccess<DoubleType> oprRA = Views
			.interval(opr, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).randomAccess();

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
}
 
Example #10
Source File: UnshearViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void UnshearIntervalTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
	Cursor<DoubleType> imgC = img.cursor();
	while (imgC.hasNext()) {
		imgC.next().set(1);
	}

	Cursor<DoubleType> il2 = Views
			.unshear(Views.shear(Views.extendZero(img), 0, 1), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
			.cursor();
	RandomAccess<DoubleType> opr = ops.transform()
			.unshearView(Views.shear(Views.extendZero(img), 0, 1), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
			.randomAccess();

	while (il2.hasNext()) {
		il2.next();
		opr.setPosition(il2);
		assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	}
}
 
Example #11
Source File: HyperSliceViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultHyperSliceTest() {

	final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 },
			new DoubleType());

	final MixedTransformView<DoubleType> il2 = Views.hyperSlice((RandomAccessible<DoubleType>) img, 1, 8);
	final MixedTransformView<DoubleType> opr = ops.transform().hyperSliceView(deinterval(img), 1, 8);

	for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
		for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
			assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}
}
 
Example #12
Source File: HyperSliceViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void IntervalHyperSliceTest() {

	final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 },
			new DoubleType());

	final IntervalView<DoubleType> il2 = Views.hyperSlice((RandomAccessibleInterval<DoubleType>) img, 1, 8);
	final IntervalView<DoubleType> opr = ops.transform().hyperSliceView(img, 1, 8);

	for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
			.getMatrix().length; i++) {
		for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
				.getMatrix()[i].length; j++) {
			assertEquals(
					((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j],
					((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}

	assertEquals(img.numDimensions() - 1, opr.numDimensions());
}
 
Example #13
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void permuteCoordinatesOfDimensionTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType());
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}, 1).cursor();
	RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}, 1).randomAccess();
	
	while (il2.hasNext()) {
		il2.next();
		opr.setPosition(il2);
		assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	}
	
}
 
Example #14
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultPermuteCoordinatesInverseTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType());
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	Cursor<DoubleType> il2 = Views.permuteCoordinatesInverse(img, new int[]{0, 1}).cursor();
	RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}).randomAccess();
	
	while (il2.hasNext()) {
		il2.next();
		opr.setPosition(il2);
		assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	}
}
 
Example #15
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void permuteCoordinatesInverseOfDimensionTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType());
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	
	IntervalView<DoubleType> out = Views.permuteCoordinatesInverse(img, new int[]{0, 1}, 1);
	
	Cursor<DoubleType> il2 = out.cursor();
	RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 1).randomAccess();
	
	while (il2.hasNext()) {
		il2.next();
		opr.setPosition(il2);
		assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	}
}
 
Example #16
Source File: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static <D extends NativeType<D> & RealType<D>, T extends RealType<T>> RealComposite<T>  createExtension(
		final D d,
		final T t,
		final Converter<D, T> converter,
		final long size,
		IntFunction<D> valueAtIndex
)
{
	LOG.debug("Creating extension with size {}", size);
	final ArrayImg<D, ?> img = new ArrayImgFactory<>(d).create(1, size);
	img.setLinkedType((D) d.getNativeTypeFactory().createLinkedType((NativeImg)img));
	final CompositeIntervalView<D, RealComposite<D>> collapsed = Views.collapseReal(img);
	RealComposite<D> extensionCopy = collapsed.randomAccess().get();
	for (int channel = 0; channel < size; ++channel)
		extensionCopy.get(channel).set(valueAtIndex.apply(channel));
	return Views.collapseReal(Converters.convert((RandomAccessibleInterval<D>)img, converter, t.createVariable())).randomAccess().get();
}
 
Example #17
Source File: InterpolateViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultInterpolateTest() {
	
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType());
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}
	
	RealRandomAccess<DoubleType> il2 = Views.interpolate(img, new FloorInterpolatorFactory<DoubleType>()).realRandomAccess();
	RealRandomAccess<DoubleType> opr = ops.transform().interpolateView(img, new FloorInterpolatorFactory<DoubleType>()).realRandomAccess();
	
	il2.setPosition(new double[]{1.75, 5.34});
	opr.setPosition(new double[]{1.75, 5.34});
	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	
	il2.setPosition(new double[]{3, 7});
	opr.setPosition(new double[]{3, 7});
	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	
	il2.setPosition(new double[]{8.37, 3.97});
	opr.setPosition(new double[]{8.37, 3.97});
	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
 
Example #18
Source File: AddDimensionViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void addDimensionTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
	
	MixedTransformView<DoubleType> il2 = Views.addDimension((RandomAccessible<DoubleType>)img);
	
	MixedTransformView<DoubleType> opr = ops.transform().addDimensionView((RandomAccessible<DoubleType>)img);
	
	assertEquals(il2.numDimensions(), opr.numDimensions());
	boolean[] il2Transform = new boolean[3];
	boolean[] oprTransform = new boolean[3];
	il2.getTransformToSource().getComponentZero(il2Transform);
	opr.getTransformToSource().getComponentZero(oprTransform);
	for (int i = 0; i < il2Transform.length; i++) {
		assertEquals(il2Transform[i], oprTransform[i]);
	}
}
 
Example #19
Source File: ExtendViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultExtendTest() {

	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	OutOfBounds<DoubleType> il2 = Views
			.extend(img, new OutOfBoundsBorderFactory<DoubleType, RandomAccessibleInterval<DoubleType>>())
			.randomAccess();

	OutOfBounds<DoubleType> opr = ops.transform()
			.extendView(img, new OutOfBoundsBorderFactory<DoubleType, RandomAccessibleInterval<DoubleType>>())
			.randomAccess();

	il2.setPosition(new int[] { -1, -1 });
	opr.setPosition(new int[] { -1, -1 });

	assertEquals(il2.get().get(), opr.get().get(), 1e-10);

	il2.setPosition(new int[] { 11, 11 });
	opr.setPosition(new int[] { 11, 11 });

	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
 
Example #20
Source File: SubsampleViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultSubsampleTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}

	SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2);
	SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2);

	Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor();
	RandomAccess<DoubleType> oprRA = opr.randomAccess();

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
}
 
Example #21
Source File: SubsampleViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultSubsampleStepsTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}

	SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2, 1);
	SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1);

	Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor();
	RandomAccess<DoubleType> oprRA = opr.randomAccess();

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
}
 
Example #22
Source File: InvertAxisViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void intervalInvertAxisTest() {

	final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	final IntervalView<DoubleType> il2 = Views.invertAxis(img, 1);
	final IntervalView<DoubleType> opr = ops.transform().invertAxisView(img, 1);

	for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
			.getMatrix().length; i++) {
		for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
				.getMatrix()[i].length; j++) {
			assertEquals(
					((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j],
					((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}
}
 
Example #23
Source File: IntervalViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultIntervalTest() {
	
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType());
	
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}
	
	Cursor<DoubleType> il2 = Views.interval(img, img).localizingCursor();
	RandomAccess<DoubleType> opr = ops.transform().intervalView(img, img).randomAccess();

	
	while (il2.hasNext()) {
		DoubleType e = il2.next();
		opr.setPosition(il2);
		
		assertEquals(e.get(), opr.get().get(), 1e-10);
	}
}
 
Example #24
Source File: IntervalViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void intervalMinMaxTest() {
	
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType());
	
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}
	
	Cursor<DoubleType> il2 = Views.interval(img, new long[]{1, 1}, new long[]{8,9}).localizingCursor();
	RandomAccess<DoubleType> opr = ops.transform().intervalView(img, new long[]{1, 1}, new long[]{8,9}).randomAccess();
	
	while (il2.hasNext()) {
		DoubleType e = il2.next();
		opr.setPosition(il2);
		
		assertEquals(e.get(), opr.get().get(), 1e-10);
	}
}
 
Example #25
Source File: TestImageAccessor.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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>> RandomAccessibleInterval<T> gaussianSmooth(
		RandomAccessibleInterval<T> img, double[] sigma) {
	Interval interval = Views.iterable(img);

	ImgFactory<T> outputFactory = new ArrayImgFactory<T>(Util.getTypeFromInterval(img));
	final long[] dim = new long[ img.numDimensions() ];
	img.dimensions(dim);
	RandomAccessibleInterval<T> output = outputFactory.create( dim );

	final long[] pos = new long[ img.numDimensions() ];
	Arrays.fill(pos, 0);
	Localizable origin = new Point(pos);

	ImgFactory<FloatType> tempFactory = new ArrayImgFactory<FloatType>(new FloatType());
	RandomAccessible<T> input = Views.extendMirrorSingle(img);
	Gauss.inFloat(sigma, input, interval, output, origin, tempFactory);

	return output;
}
 
Example #26
Source File: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testCreateFromRaiDifferentType() {
	final IntervalView<ByteType> input =
		Views.interval(PlanarImgs.bytes(10, 10, 10), new FinalInterval(
			new long[] { 10, 10, 1 }));

	final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input,
		new ShortType());

	assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass());

	assertArrayEquals("Image Dimensions: ", Intervals
		.dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res));

	assertEquals("Image Factory: ", ArrayImgFactory.class, res.factory()
		.getClass());
}
 
Example #27
Source File: TestImageAccessor.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method creates a noise image that has a specified mean.
 * Every pixel has a value uniformly distributed around mean with
 * the maximum spread specified.
 *
 * @return a new noise image
 * @throws MissingPreconditionException if specified means and spreads are not valid
 */
public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> produceMeanBasedNoiseImage(T type, int width,
		int height, double mean, double spread, double[] smoothingSigma, long seed) throws MissingPreconditionException {
	if (mean < spread || (mean + spread) > type.getMaxValue()) {
		throw new MissingPreconditionException("Mean must be larger than spread, and mean plus spread must be smaller than max of the type");
	}
	// create the new image
	ImgFactory<T> imgFactory = new ArrayImgFactory<T>();
	RandomAccessibleInterval<T> noiseImage = imgFactory.create( new int[] {width, height}, type); // "Noise image");

	Random r = new Random(seed);
	for (T value : Views.iterable(noiseImage)) {
		value.setReal( mean + ( (r.nextDouble() - 0.5) * spread ) );
	}

	return gaussianSmooth(noiseImage, smoothingSigma);
}
 
Example #28
Source File: ColocalisationTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method creates a noise image that has a specified mean. Every pixel
 * has a value uniformly distributed around mean with the maximum spread
 * specified.
 *
 * @return IllegalArgumentException if specified means and spreads are not
 *         valid
 */
public static <T extends RealType<T> & NativeType<T>>
	Img<T> produceMeanBasedNoiseImage(T type, int width,
		int height, double mean, double spread, double[] smoothingSigma,
		long seed) throws IllegalArgumentException
{
	if (mean < spread || (mean + spread) > type.getMaxValue()) {
		throw new IllegalArgumentException(
			"Mean must be larger than spread, and mean plus spread must be smaller than max of the type");
	}
	// create the new image
	ImgFactory<T> imgFactory = new ArrayImgFactory<>(type);
	Img<T> noiseImage = imgFactory.create(width, height);

	Random r = new Random(seed);
	for (T value : Views.iterable(noiseImage)) {
		value.setReal(mean + ((r.nextDouble() - 0.5) * spread));
	}

	// TODO: call Ops filter.gauss instead
	return gaussianSmooth(noiseImage, smoothingSigma);
}
 
Example #29
Source File: ColocalisationTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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<>(Util.getTypeFromInterval(img));
	final long[] dim = new long[img.numDimensions()];
	img.dimensions(dim);
	Img<T> output = outputFactory.create(dim);

	final long[] pos = new long[img.numDimensions()];
	Arrays.fill(pos, 0);
	Localizable origin = new Point(pos);

	ImgFactory<FloatType> tempFactory = new ArrayImgFactory<>(new FloatType());
	RandomAccessible<T> input = Views.extendMirrorSingle(img);
	Gauss.inFloat(sigma, input, interval, output, origin, tempFactory);

	return output;
}
 
Example #30
Source File: SlideBook6.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected ImgFactory<? extends NativeType<?>> selectImgFactory(final SlideBook6MetaData meta) {
    int[] dims = meta.imageSize(0);
    long maxNumPixels = dims[0];
    maxNumPixels *= dims[1];
    maxNumPixels *= dims[2];

    String s = "Maximum number of pixels in any view: n=" + Long.toString(maxNumPixels) +
            " px ";

    if (maxNumPixels < Integer.MAX_VALUE) {
        IOFunctions.println(s + "< " + Integer.MAX_VALUE + ", using ArrayImg.");
        return new ArrayImgFactory<FloatType>();
    } else {
        IOFunctions.println(s + ">= " + Integer.MAX_VALUE + ", using CellImg.");
        return new CellImgFactory<FloatType>(256);
    }
}