net.imglib2.img.Img Java Examples

The following examples show how to use net.imglib2.img.Img. 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: ScaleViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testScaling() {
	Img<ByteType> in = generateByteArrayTestImg(true, new long[] { 10, 10 });
	double[] scaleFactors = new double[] { 2, 2 };
	@SuppressWarnings("unchecked")
	RandomAccessibleInterval<ByteType> out = (RandomAccessibleInterval<ByteType>) ops.run(DefaultScaleView.class, in,
		scaleFactors, new NLinearInterpolatorFactory<ByteType>());

	assertEquals(out.dimension(0), 20);
	assertEquals(out.dimension(1), 20);

	RandomAccess<ByteType> inRA = in.randomAccess();
	RandomAccess<ByteType> outRA = out.randomAccess();
	inRA.setPosition(new long[] { 5, 5 });
	outRA.setPosition(new long[] { 10, 10 });
	assertEquals(inRA.get().get(), outRA.get().get());

}
 
Example #2
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testDoubleTypeCustomInvert() {
	final Img<DoubleType> inDoubleType = generateDoubleArrayTestImg(true, 5, 5);
	final Img<DoubleType> outDoubleType = inDoubleType.factory().create(
		inDoubleType, new DoubleType());

	// set this array of doubles to be the pixel values.
	final double[] nums = new double[] { Double.MAX_VALUE, Double.MIN_VALUE, 1d,
		-1d, 0d, Double.MAX_VALUE + 1, -Double.MAX_VALUE - 1, Math.PI, Math.E,
		Math.sqrt(Math.PI), Math.pow(25, 25), 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
		Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
		Double.NEGATIVE_INFINITY };
	final Cursor<DoubleType> c = inDoubleType.localizingCursor();
	for (final double i : nums) {
		c.next();
		c.get().set(i);
	}
	assertDefaultInvert(inDoubleType, outDoubleType);
	assertDefaultInvertMinMaxProvided(inDoubleType, outDoubleType,
		new DoubleType(437d), new DoubleType(8008d));
}
 
Example #3
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 #4
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test box counting with a hyper cube and one grid translation (should find a
 * better fit than in @see {@link #testHyperCube()})
 */
@Test
public void testHyperCubeTranslations() {
	final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
		i)).toArray();
	final double[] expectedCounts = DoubleStream.of(1, 1, 16).map(Math::log)
		.toArray();
	final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
	final IntervalView<BitType> hyperView = Views.offsetInterval(img,
		new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
	hyperView.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 4L, 1L, 2.0, 1L);

	// VERIFY
	for (int i = 0; i < expectedSizes.length; i++) {
		assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #5
Source File: MVDeconFFTThreads.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
final protected static void convolve1BlockCPU(
		final Block blockStruct, final Img< FloatType > image, final Img< FloatType > result,
		final Img< FloatType > block, final FFTConvolution< FloatType > fftConvolution1, final int i )
{
	long time = System.currentTimeMillis();
	blockStruct.copyBlock( Views.extendMirrorSingle( image ), block );
	System.out.println( " block " + i + "(CPU): copy " + (System.currentTimeMillis() - time) );

	time = System.currentTimeMillis();
	fftConvolution1.setImg( block );
	fftConvolution1.setOutput( block );
	fftConvolution1.convolve();
	System.out.println( " block " + i + "(CPU): compute " + (System.currentTimeMillis() - time) );

	time = System.currentTimeMillis();
	blockStruct.pasteBlock( result, block );
	System.out.println( " block " + i + "(CPU): paste " + (System.currentTimeMillis() - time) );
}
 
Example #6
Source File: WeightNormalizer.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args )
{
	new ImageJ();
	
	Img< FloatType > img = ArrayImgs.floats( 500, 500 );
	BlendingRealRandomAccess blend = new BlendingRealRandomAccess(
			img,
			new float[]{ 100, 0 },
			new float[]{ 12, 150 } );
	
	Cursor< FloatType > c = img.localizingCursor();
	
	while ( c.hasNext() )
	{
		c.fwd();
		blend.setPosition( c );
		c.get().setReal( blend.get().getRealFloat() );
	}
	
	ImageJFunctions.show( img );
}
 
Example #7
Source File: DefaultBilateralTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testMath() {
	final byte[] data = { 7, 4, 9, 1 };
	final Img<ByteType> in = ArrayImgs.bytes(data, 2, 2);
	final Img<ByteType> out = generateByteArrayTestImg(false, 2, 2);

	ops.run(DefaultBilateral.class, out, in, 15, 5, 1);

	Cursor<ByteType> cout = out.cursor();
	final byte[] expected = { 5, 5, 5, 5 };
	int counter = 0;
	while (cout.hasNext()) {
		byte actual = cout.next().get();
		assertEquals(expected[counter++], actual);
	}
}
 
Example #8
Source File: FFTTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testPadShiftKernel() {
	long[] dims = new long[] { 1024, 1024 };
	Img<ComplexDoubleType> test = ops.create().img(new FinalDimensions(dims),
		new ComplexDoubleType());

	RandomAccessibleInterval<ComplexDoubleType> shift =
		(RandomAccessibleInterval<ComplexDoubleType>) ops.run(
			PadShiftKernel.class, test, new FinalDimensions(dims));

	RandomAccessibleInterval<ComplexDoubleType> shift2 =
		(RandomAccessibleInterval<ComplexDoubleType>) ops.run(
			PadShiftKernelFFTMethods.class, test, new FinalDimensions(dims));

	// assert there was no additional padding done by PadShiftKernel
	assertEquals(1024, shift.dimension(0));
	// assert that PadShiftKernelFFTMethods padded to the FFTMethods fast size
	assertEquals(1120, shift2.dimension(0));

}
 
Example #9
Source File: FFTTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * test that a forward transform followed by an inverse transform gives us
 * back the original image
 */
@Test
public void testFFT3DOp() {
	final int min = expensiveTestsEnabled ? 115 : 9;
	final int max = expensiveTestsEnabled ? 120 : 11;
	for (int i = min; i < max; i++) {

		final long[] dimensions = new long[] { i, i, i };

		// create an input with a small sphere at the center
		final Img<FloatType> in = generateFloatArrayTestImg(false, dimensions);
		placeSphereInCenter(in);

		final Img<FloatType> inverse = generateFloatArrayTestImg(false,
			dimensions);

		@SuppressWarnings("unchecked")
		final Img<ComplexFloatType> out = (Img<ComplexFloatType>) ops.run(
			FFTMethodsOpF.class, in);
		ops.run(IFFTMethodsOpC.class, inverse, out);

		assertImagesEqual(in, inverse, .00005f);
	}

}
 
Example #10
Source File: ShearViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Tests {@link ShearViewInterval}. */
@Test
public void ShearIntervalTest() {
	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
			.shear(Views.extendZero(img), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
			.cursor();
	RandomAccess<DoubleType> opr = ops.transform()
			.shearView(Views.extendZero(img), 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: 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 #12
Source File: ListDilate.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<T> in1,
	final List<Shape> in2, final IterableInterval<T> out)
{
	final long[][] minSize = Morphologies.computeMinSize(in1, in2);
	final Interval interval = new FinalInterval(minSize[1]);
	Img<T> upstream = imgCreator.calculate(interval);
	Img<T> downstream = imgCreator.calculate(interval);
	Img<T> tmp;

	dilateComputer.compute(in1, in2.get(0), Views.translate(downstream,
		minSize[0]));
	for (int i = 1; i < in2.size(); i++) {
		// Ping-ponging intermediate results between upstream and downstream to
		// avoid repetitively creating new Imgs.
		tmp = downstream;
		downstream = upstream;
		upstream = tmp;
		dilateComputer.compute(upstream, in2.get(i), downstream);
	}
	if (isFull) copyImg.compute(downstream, out);
	else copyImg.compute(Views.interval(Views.translate(downstream,
		minSize[0]), out), out);
}
 
Example #13
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 #14
Source File: DefaultBilateralTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testBigImage() {
	final byte[] data = { 7, 8, 9, 1, 2, 3, 7, 9, 8, 1, 3, 2, 8, 7, 9, 2, 1, 3, 8, 9, 7, 2, 3, 1, 9, 7, 8, 3, 1, 2,
			9, 8, 7, 3, 2, 1 };
	final Img<ByteType> in = ArrayImgs.bytes(data, 6, 6);
	final Img<ByteType> out = generateByteArrayTestImg(false, 6, 6);

	ops.run(DefaultBilateral.class, out, in, 15, 5, 2);

	final byte[] expected = { 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3,
			2, 8, 7, 6, 4, 3, 2 };

	Cursor<ByteType> cout = out.cursor();
	for (int i = 0; i < expected.length; i++) {
		assertEquals(cout.next().get(), expected[i]);
	}
}
 
Example #15
Source File: MVDeconFFTThreads.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
final protected static Thread getCUDAThread1(
		final AtomicInteger ai, final ImgFactory< FloatType > blockFactory, final Block[] blocks, final int[] blockSize,
		final Img< FloatType > image, final Img< FloatType > result, final int deviceId, final Img< FloatType > kernel1 )
{
	final Thread cudaThread1 = new Thread( new Runnable()
	{
		public void run()
		{
			final Img< FloatType > block = blockFactory.create( Util.int2long( blockSize ), new FloatType() );

			int i;

			while ( ( i = ai.getAndIncrement() ) < blocks.length )
				convolve1BlockCUDA( blocks[ i ], deviceId, image, result, block, kernel1, i );
		}
	});
	
	return cudaThread1;
}
 
Example #16
Source File: BlendingRealRandomAccess.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args )
{
	new ImageJ();
	
	Img< FloatType > img = ArrayImgs.floats( 500, 500 );
	BlendingRealRandomAccess blend = new BlendingRealRandomAccess(
			img,
			new float[]{ 100, 0 },
			new float[]{ 12, 150 } );
	
	Cursor< FloatType > c = img.localizingCursor();
	
	while ( c.hasNext() )
	{
		c.fwd();
		blend.setPosition( c );
		c.get().setReal( blend.get().getRealFloat() );
	}
	
	ImageJFunctions.show( img );
}
 
Example #17
Source File: ConvertMapTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Img<UnsignedByteType> generateUnsignedByteImg(
	final byte[] values)
{

	final byte[] array =
		new byte[(int) Intervals.numElements(new FinalInterval(dims))];

	if (array.length != values.length) {
		throw new RuntimeException("Number of values doesn't match dimmensions");
	}

	for (int i = 0; i < array.length; i++) {
		array[i] = values[i];
	}

	return ArrayImgs.unsignedBytes(array, dims);
}
 
Example #18
Source File: TestHelper.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Img<BitType> drawCube(final long width, final long height, final long depth, final long padding) {
    final long totalPadding = 2 * padding;
    final Img<BitType> cube = ArrayImgs.bits(width + totalPadding, height + totalPadding, depth + totalPadding);
    final long x1 = padding + width;
    final long y1 = padding + height;
    final long z1 = padding + depth;
    final RandomAccess<BitType> access = cube.randomAccess();

    for (long z = padding; z < z1; z++) {
        access.setPosition(z, 2);
        for (long y = padding; y < y1; y++) {
            access.setPosition(y, 1);
            for (long x = padding; x < x1; x++) {
                access.setPosition(x, 0);
                access.get().setOne();
            }
        }
    }

    return cube;
}
 
Example #19
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testOneVoxel() {
	// SETUP
	final PrimitiveIterator.OfDouble sizes = DoubleStream.of(9, 3, 1).map(
		i -> -Math.log(i)).iterator();
	final PrimitiveIterator.OfDouble counts = DoubleStream.of(1, 1, 1).map(
		Math::log).iterator();
	final Img<BitType> img = ArrayImgs.bits(9, 9, 9);
	final RandomAccess<BitType> access = img.randomAccess();
	access.setPosition(new long[] { 4, 4, 4 });
	access.get().setOne();

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 9L, 3L, 3.0);

	// VERIFY
	points.forEach(p -> {
		assertEquals(p.a.get(), sizes.next(), 1e-12);
		assertEquals(p.b.get(), counts.next(), 1e-12);
	});
}
 
Example #20
Source File: OutlineTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test the op with a 3x3 square starting from (0,1) in a 5x5 img
 *
 * @see Outline#compute(RandomAccessibleInterval, Boolean,
 *      RandomAccessibleInterval)
 * @see #testEdgeSquare()
 */
@Test
public void testEdgeSquare() {
	// SETUP
	final Img<BitType> img = ArrayImgs.bits(5, 5);
	final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
		0, 1 }, new long[] { 3, 3 });
	square.cursor().forEachRemaining(BitType::setOne);

	// EXECUTION
	final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
		Boolean.TRUE);

	// VERIFY
	assertEquals("Wrong number of foreground elements in interval", 7,
		countForeground(result));
	final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
		new long[] { 0, 1 }, new long[] { 3, 3 });
	assertEquals("Wrong number of foreground elements in object", 7,
		countForeground(resultSquare));
	assertPositionBackground(result, new long[] { 0, 2 });
	assertPositionBackground(result, new long[] { 1, 2 });
}
 
Example #21
Source File: Fusion.java    From Stitching with GNU General Public License v2.0 6 votes vote down vote up
public TileProcessor(int threadNumber,
	List<ArrayList<RealRandomAccess<? extends RealType<?>>>> interpolators,
	ArrayList<? extends ImageInterpolation<? extends RealType<?>>> input,
	Vector<Chunk> threadChunks, int numImages, Img<T> output,
	PixelFusion fusion, ClassifiedRegion[] currentTile,
	ArrayList<InvertibleBoundable> transform, ImagePlus[] fusionImp,
	int[] count, double positionsPerThread, double[] offset, int[] loopDim)
{
	this.threadNumber = threadNumber;
	this.threadChunks = threadChunks;
	this.currentTile = currentTile;
	this.transform = transform;
	this.fusionImp = fusionImp;
	this.count = count;
	this.positionsPerThread = positionsPerThread;
	this.offset = offset;
	this.loopDim = loopDim;

	in = getThreadInterpolators(interpolators, threadNumber, input, numImages);
	inPos = new double[numImages][output.numDimensions()];
	myFusion = fusion.copy();
	out = output.randomAccess();
}
 
Example #22
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testAllForeground() {
	// SETUP
	final double scalingPow = DoubleStream.generate(() -> SCALING).limit(
		DIMENSIONS).reduce((i, j) -> i * j).orElse(0);
	final double[] expectedCounts = DoubleStream.iterate(1.0, i -> i *
		scalingPow).map(Math::log).limit(ITERATIONS).toArray();
	final Img<BitType> img = ArrayImgs.bits(TEST_DIMS);
	img.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, MAX_SIZE, MIN_SIZE, SCALING);

	// VERIFY
	for (int i = 0; i < ITERATIONS; i++) {
		assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #23
Source File: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testImageMinimum() {

	final MersenneTwisterFast randomGenerator = new MersenneTwisterFast(SEED);

	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));
	}
}
 
Example #24
Source File: LocalThresholdTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see LocalMinErrorThreshold
 */
@Test
public void testLocalMinErrorThreshold() {
	ops.run(MinError.class, out, in, new RectangleShape(1, false),
		new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE));

	assertEquals(true, out.firstElement().get());
}
 
Example #25
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return - maximal dimensions of the transformed PSFs
 */
public long[] computeMaxDimTransformedPSF()
{
	final int numDimensions = 3;
	
	final long[] maxSize = new long[ numDimensions ];

	for ( final Img< T > transformedPSF : pointSpreadFunctions.values() )
		for ( int d = 0; d < numDimensions; ++d )
			maxSize[ d ] = Math.max( maxSize[ d ], transformedPSF.dimension( d ) );

	return maxSize;
}
 
Example #26
Source File: DefaultDetectRidgesTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testTooManyDimensions() {
	Img<FloatType> input = generateFloatArrayTestImg(false, 30, 30, 30, 30);
	
	// run the image through ridge detection
	int width = 1, ridgeLengthMin = 4;
	double lowerThreshold = 2, higherThreshold = 4;

	List<DefaultWritablePolyline> polylines = (List<DefaultWritablePolyline>) ops.run(
		Ops.Segment.DetectRidges.class, input, width, lowerThreshold,
		higherThreshold, ridgeLengthMin);
}
 
Example #27
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Img<UnsignedByteType>
	generateRandomlyFilledUnsignedByteTestImgWithSeed(final long[] dims,
		final long tempSeed)
{

	final Img<UnsignedByteType> img = ArrayImgs.unsignedBytes(dims);

	final Random rand = new Random(tempSeed);
	final Cursor<UnsignedByteType> cursor = img.cursor();
	while (cursor.hasNext()) {
		cursor.next().set(rand.nextInt((int) img.firstElement().getMaxValue()));
	}

	return img;
}
 
Example #28
Source File: CreateNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.create.imgPlus.DefaultCreateImgPlus.class)
public <T> ImgPlus<T>
	imgPlus(final Img<T> img, final ImgPlusMetadata metadata)
{
	@SuppressWarnings("unchecked")
	final ImgPlus<T> result =
		(ImgPlus<T>) ops()
			.run(Ops.Create.ImgPlus.class, img,
				metadata);
	return result;
}
 
Example #29
Source File: LocalThresholdTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see LocalMeanThreshold
 */
@Test
public void testLocalThresholdMean() {
	ops.run(LocalMeanThreshold.class, out, in, new RectangleShape(1, false),
		new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE),
		0.0);

	assertEquals(true, out.firstElement().get());
}
 
Example #30
Source File: InvertTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testUnsignedIntTypeInvert() {
	final Img<UnsignedIntType> inUnsignedIntType =
		generateUnsignedIntArrayTestImg(true, 5, 5);
	final Img<UnsignedIntType> outUnsignedIntType = inUnsignedIntType.factory()
		.create(inUnsignedIntType, new UnsignedIntType());
	assertDefaultInvert(inUnsignedIntType, outUnsignedIntType);
	assertDefaultInvertMinMaxProvided(inUnsignedIntType, outUnsignedIntType,
		new UnsignedIntType(237), new UnsignedIntType(257));
	assertDefaultInvertMinMaxProvided(inUnsignedIntType, outUnsignedIntType,
		new UnsignedIntType(10), new UnsignedIntType(-10));
}