net.imglib2.img.array.ArrayImg Java Examples

The following examples show how to use net.imglib2.img.array.ArrayImg. 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: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 * @param img
 * @param viewId
 * @param model
 * @param locations
 * @param psfSize - dimensions of psf to extract
 */
public void extractNextImg(
		final RandomAccessibleInterval< T > img,
		final ViewId viewId,
		final AffineTransform3D model,
		final ArrayList< double[] > locations,
		final long[] psfSize )
{
	IOFunctions.println( "PSF size: " + Util.printCoordinates( psfSize ) );

	final ArrayImg< T, ? > originalPSF = extractPSFLocal( img, locations, psfSize );

	// normalize PSF
	normalize( originalPSF );

	final ArrayImg< T, ? > psf = transformPSF( originalPSF, model );

	viewIds.add( viewId );
	pointSpreadFunctions.put( viewId, psf );
	originalPSFs.put( viewId, originalPSF );
}
 
Example #2
Source File: MVDeconFFTThreads.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
final protected static void convolve1BlockCUDA(
		final Block blockStruct, final int deviceId, final Img< FloatType > image,
		final Img< FloatType > result, final Img< FloatType > block, final Img< FloatType > kernel1, final int i )
{
	long time = System.currentTimeMillis();
	blockStruct.copyBlock( Views.extendMirrorSingle( image ), block );
	System.out.println( " block " + i + "(CPU  " + deviceId + "): copy " + (System.currentTimeMillis() - time) );

	// convolve block with kernel1 using CUDA
	time = System.currentTimeMillis();
	final float[] blockF = ((FloatArray)((ArrayImg< net.imglib2.type.numeric.real.FloatType, ? > )block).update( null ) ).getCurrentStorageArray();
	final float[] kernel1F = ((FloatArray)((ArrayImg< net.imglib2.type.numeric.real.FloatType, ? > )kernel1).update( null ) ).getCurrentStorageArray();
	
	MVDeconFFT.cuda.convolution3DfftCUDAInPlace(
			blockF, getCUDACoordinates( CUDAOutput.getImgSizeInt( block ) ),
			kernel1F, getCUDACoordinates( CUDAOutput.getImgSizeInt( kernel1 ) ),
			deviceId );
	System.out.println( " block " + i + "(CUDA " + deviceId + "): compute " + (System.currentTimeMillis() - time) );

	time = System.currentTimeMillis();
	blockStruct.pasteBlock( result, block );
	System.out.println( " block " + i + "(CPU  " + deviceId + "): paste " + (System.currentTimeMillis() - time) );
}
 
Example #3
Source File: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void createVariables()
{
	LOG.debug("Updating images for screen scales {}", screenScales);
	if (renderingMayBeCancelled && projector != null)
		projector.cancel();
	renderImages = new ArrayImg[screenScales.length][0];
	renderMaskArrays = new byte[0][];
	screenImages = new ArrayList<>();
	bufferedImages = new ArrayList<>();
	for (int i = 0; i < screenScales.length; ++i)
	{
		screenImages.add(Arrays.asList(null, null, null));
		bufferedImages.add(Arrays.asList(null, null, null));
	}
	screenScaleTransforms = new AffineTransform3D[screenScales.length];
	pendingRepaintRequests = new Interval[screenScales.length];
	maxScreenScaleIndex = screenScales.length - 1;
	requestedScreenScaleIndex = maxScreenScaleIndex;
}
 
Example #4
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 #5
Source File: LegacyDHMImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view )
{
	final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view );
	final Dimensions d = vd.getViewSetup().getSize();
	final VoxelDimensions dv = vd.getViewSetup().getVoxelSize();

	final ArrayImg< UnsignedShortType, ? > img = ArrayImgs.unsignedShorts( d.dimension( 0 ), d.dimension( 1 ), d.dimension( 2 ) );

	final String ampOrPhaseDir;

	if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == ampChannelId )
		ampOrPhaseDir = amplitudeDir;
	else if ( vd.getViewSetup().getAttribute( Channel.class ).getId() ==  phaseChannelId )
		ampOrPhaseDir = phaseDir;
	else
		throw new RuntimeException( "viewSetupId=" + view.getViewSetupId() + " is not Amplitude nor phase." );

	populateImage( img, directory, stackDir, ampOrPhaseDir, zPlanes, timepoints.get( view.getTimePointId() ), extension );

	updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) );

	return img;
}
 
Example #6
Source File: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean checkRenewRenderImages(final int numVisibleSources)
{
	final int n = numVisibleSources > 1 ? numVisibleSources : 0;
	if (n != renderImages[0].length ||
			n != 0 &&
					(renderImages[0][0].dimension(0) != width.applyAsInt(screenImages.get(0).get(0)) ||
							renderImages[0][0].dimension(1) != height.applyAsInt(screenImages.get(0).get(0))))
	{
		renderImages = new ArrayImg[screenScales.length][n];
		for (int i = 0; i < screenScales.length; ++i)
		{
			final int w = width.applyAsInt(screenImages.get(i).get(0));
			final int h = height.applyAsInt(screenImages.get(i).get(0));
			for (int j = 0; j < n; ++j)
				renderImages[i][j] = i == 0
				                     ? ArrayImgs.argbs(w, h)
				                     : ArrayImgs.argbs(renderImages[0][j].update(null), w, h);
		}
		return true;
	}
	return false;
}
 
Example #7
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 #8
Source File: IntegralImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImgLarge() {
	final long[] dims = new long[] { 3, 3 };
	final byte[] array = new byte[9];

	array[0] = (byte) 40;
	array[1] = (byte) 40;
	array[2] = (byte) 20;

	array[3] = (byte) 40;
	array[4] = (byte) 40;
	array[5] = (byte) 20;

	array[6] = (byte) 20;
	array[7] = (byte) 20;
	array[8] = (byte) 100;

	return ArrayImgs.bytes(array, dims);
}
 
Example #9
Source File: IntegralCursorTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImg() {
	final long[] dims = new long[] { 3, 3 };
	final byte[] array = new byte[9];

	array[0] = (byte) 1;
	array[1] = (byte) 2;
	array[2] = (byte) 3;

	array[3] = (byte) 4;
	array[4] = (byte) 5;
	array[5] = (byte) 6;

	array[6] = (byte) 7;
	array[7] = (byte) 8;
	array[8] = (byte) 9;

	return ArrayImgs.bytes(array, dims);
}
 
Example #10
Source File: SquareIntegralImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImg() {
	final long[] dims = new long[] { 3, 3 };
	final byte[] array = new byte[9];

	array[0] = (byte) 4;
	array[1] = (byte) 4;
	array[2] = (byte) 2;

	array[3] = (byte) 4;
	array[4] = (byte) 4;
	array[5] = (byte) 2;

	array[6] = (byte) 2;
	array[7] = (byte) 2;
	array[8] = (byte) 6;

	return ArrayImgs.bytes(array, dims);
}
 
Example #11
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ArrayImg<UnsignedVariableBitLengthType, LongArray>
	generateUnsignedVariableBitLengthTypeArrayTestImg(final boolean fill,
		final int nbits, final long... dims)
{
	final long[] array = new long[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (long) (((pseudoRandom() / Integer.MAX_VALUE)) % (Math.pow(2, nbits))) ;
		}
	}

	final LongArray l = new LongArray(array);

	return ArrayImgs.unsignedVariableBitLengths(l, nbits, dims);
}
 
Example #12
Source File: MVDeconFFTThreads.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
final protected static void convolve2BlockCUDA(
		final Block blockStruct, final int deviceId, final Img< FloatType > image,
		final Img< FloatType > result, final Img< FloatType > block, final Img< FloatType > kernel2 )
{
	// ratio outside of the deconvolved space (psi) is 1
	blockStruct.copyBlock( Views.extendValue( image, new FloatType( 1.0f ) ), block );

	// convolve block with kernel2 using CUDA
	final float[] blockF = ((FloatArray)((ArrayImg< net.imglib2.type.numeric.real.FloatType, ? > )block).update( null ) ).getCurrentStorageArray();
	final float[] kernel2F = ((FloatArray)((ArrayImg< net.imglib2.type.numeric.real.FloatType, ? > )kernel2).update( null ) ).getCurrentStorageArray();

	MVDeconFFT.cuda.convolution3DfftCUDAInPlace(
			blockF, getCUDACoordinates( CUDAOutput.getImgSizeInt( block ) ),
			kernel2F, getCUDACoordinates( CUDAOutput.getImgSizeInt( kernel2 ) ),
			deviceId );

	blockStruct.pasteBlock( result, block );
}
 
Example #13
Source File: SliceTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void testXYZCropping(int t) {

		Img<ByteType> inSequence = ArrayImgs.bytes(20, 20, 21, t);
		ArrayImg<ByteType, ByteArray> outSequence = ArrayImgs.bytes(20, 20, 21, t);

		// fill array img with values (plane position = value in px);
		for (final Cursor<ByteType> cur = inSequence.cursor(); cur.hasNext();) {
			cur.fwd();
			cur.get().set((byte) cur.getIntPosition(2));
		}

		// selected interval XYZ
		final int[] xyAxis = new int[] { 0, 1, 2 };

		ops.run(SliceRAI2RAI.class, outSequence, inSequence, new DummyOp(), xyAxis);

		for (final Cursor<ByteType> cur = outSequence.cursor(); cur.hasNext();) {
			cur.fwd();
			assertEquals(cur.getIntPosition(2), cur.get().getRealDouble(), 0);
		}
	}
 
Example #14
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @param dim a long array with the desired dimensions of the image
 * @param constValue constant image value
 * @return an {@link Img} of {@link UnsignedByteType} filled with a constant
 *         value.
 */
public Img<UnsignedByteType> getConstantUnsignedByteImg(final long[] dim,
	final int constValue)
{
	final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
		dim);

	final UnsignedByteType type = img.firstElement();
	if (constValue < type.getMinValue() || constValue >= type.getMaxValue()) {
		throw new IllegalArgumentException("Can't create image for constant [" +
			constValue + "]");
	}

	final ArrayCursor<UnsignedByteType> cursor = img.cursor();
	while (cursor.hasNext()) {
		cursor.next().set(constValue);
	}

	return img;
}
 
Example #15
Source File: LocalThresholdTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImgLarge() {
	final long[] dims = new long[] { 3, 3 };
	final byte[] array = new byte[9];

	array[0] = (byte) 40;
	array[1] = (byte) 40;
	array[2] = (byte) 20;

	array[3] = (byte) 40;
	array[4] = (byte) 40;
	array[5] = (byte) 20;

	array[6] = (byte) 20;
	array[7] = (byte) 20;
	array[8] = (byte) 100;

	return ArrayImgs.bytes(array, dims);
}
 
Example #16
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<BitType, LongArray> generateBitArrayTestImg(
	final boolean fill, final long... dims)
{
	ArrayImg<BitType, LongArray> bits = ArrayImgs.bits(dims);

	if (fill) {
		MersenneTwisterFast betterRNG = new MersenneTwisterFast(0xf1eece);
		for (BitType b : bits) {
			b.set(betterRNG.nextBoolean());
		}
	}
	return bits;
}
 
Example #17
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<UnsignedShortType, ShortArray>
	generateUnsignedShortArrayTestImg(final boolean fill, final long... dims)
{
	final short[] array = new short[(int) Intervals.numElements(
		new FinalInterval(dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (short) (pseudoRandom() / Integer.MAX_VALUE);
		}
	}

	return ArrayImgs.unsignedShorts(array, dims);
}
 
Example #18
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<Unsigned4BitType, LongArray> generateUnsigned4BitArrayTestImg(
	final boolean fill, final long... dims)
{
	ArrayImg<Unsigned4BitType, LongArray> bits = ArrayImgs.unsigned4Bits(dims);

	if (fill) {
		MersenneTwisterFast betterRNG = new MersenneTwisterFast(0xf1eece);
		for (Unsigned4BitType b : bits) {
			b.set(betterRNG.nextLong());
		}
	}
	return bits;
}
 
Example #19
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<Unsigned12BitType, LongArray>
	generateUnsigned12BitArrayTestImg(final boolean fill, final long... dims)
{
	ArrayImg<Unsigned12BitType, LongArray> bits = ArrayImgs.unsigned12Bits(
		dims);

	if (fill) {
		MersenneTwisterFast betterRNG = new MersenneTwisterFast(0xf1eece);
		for (Unsigned12BitType b : bits) {
			b.set(betterRNG.nextLong());
		}
	}
	return bits;
}
 
Example #20
Source File: Block.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private static final void copy3dArray( final int threadIdx, final int numThreads, final RandomAccessible< FloatType > source, final ArrayImg< FloatType, ? > block, final long[] offset )
{
	final int w = (int)block.dimension( 0 );
	final int h = (int)block.dimension( 1 );
	final int d = (int)block.dimension( 2 );

	final long offsetX = offset[ 0 ];
	final long offsetY = offset[ 1 ];
	final long offsetZ = offset[ 2 ];
	final float[] blockArray = ((FloatArray)block.update( null ) ).getCurrentStorageArray();

	// define where we will query the RandomAccess on the source
	final FinalInterval interval = new FinalInterval( new long[] { offsetX, offsetY, offsetZ }, new long[] { offsetX + w - 1, offsetY + h - 1, offsetZ + d - 1 } );
	final RandomAccess< FloatType > randomAccess = source.randomAccess( interval );

	final long[] tmp = new long[]{ offsetX, offsetY, 0 };

	for ( int z = threadIdx; z < d; z += numThreads )
	{
		tmp[ 2 ] = z + offsetZ;
		randomAccess.setPosition( tmp );

		int i = z * h * w;

		for ( int y = 0; y < h; ++y )
		{
			randomAccess.setPosition( offsetX, 0 );

			for ( int x = 0; x < w; ++x )
			{
				blockArray[ i++ ] = randomAccess.get().get();
				randomAccess.fwd( 0 );
			}

			randomAccess.move( -w, 0 );
			randomAccess.fwd( 1 );
		}
	}
}
 
Example #21
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<FloatType, FloatArray> generateFloatArrayTestImg(
	final boolean fill, final long... dims)
{
	final float[] array = new float[(int) Intervals.numElements(
		new FinalInterval(dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (float) pseudoRandom() / (float) Integer.MAX_VALUE;
		}
	}

	return ArrayImgs.floats(array, dims);
}
 
Example #22
Source File: LegacyDHMImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
	final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view );
	final Dimensions d = vd.getViewSetup().getSize();
	final VoxelDimensions dv = vd.getViewSetup().getVoxelSize();

	final ArrayImg< FloatType, ? > img = ArrayImgs.floats( d.dimension( 0 ), d.dimension( 1 ), d.dimension(  2 ) );

	final String ampOrPhaseDir;

	if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == ampChannelId )
		ampOrPhaseDir = amplitudeDir;
	else if ( vd.getViewSetup().getAttribute( Channel.class ).getId() ==  phaseChannelId )
		ampOrPhaseDir = phaseDir;
	else
		throw new RuntimeException( "viewSetupId=" + view.getViewSetupId() + " is not Amplitude nor phase." );

	populateImage( img, directory, stackDir, ampOrPhaseDir, zPlanes, timepoints.get( view.getTimePointId() ), extension );

	if ( normalize )
		normalize( img );

	updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) );

	return img;
}
 
Example #23
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testAllShuffle() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> actualInputImage = ArrayImgs
		.unsignedBytes(new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
	}, 6, 6);
	int[] blockSize = { 1, 1 };
	long seed = 0xdeadbeef;
	ShuffledView<UnsignedByteType> shuffled = new ShuffledView<>(
		actualInputImage, blockSize, seed);
	ArrayImg<UnsignedByteType, ByteArray> expected = ArrayImgs.unsignedBytes(
		new byte[] { //
			33, 19, 14, 36, 31, 32, //
			34, 21, 17, 30, 35, 1, //
			7, 28, 29, 20, 9, 12, //
			5, 18, 27, 3, 8, 2, //
			11, 25, 4, 24, 26, 6, //
			23, 10, 13, 15, 22, 16 //
		}, 6, 6);
	assertIterationsEqual(expected, Views.iterable(shuffled));
}
 
Example #24
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testNonSquareBlocks2() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> actualInputImage = ArrayImgs
		.unsignedBytes(new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
	}, 6, 6);
	int[] blockSize = { 3, 2 };
	long seed = 0xdeadbeef;
	ShuffledView<UnsignedByteType> shuffled = new ShuffledView<>(
		actualInputImage, blockSize, seed);
	ArrayImg<UnsignedByteType, ByteArray> expected = ArrayImgs.unsignedBytes(
		new byte[] { //
			25, 26, 27, 13, 14, 15, //
			31, 32, 33, 19, 20, 21, //
			1, 2, 3, 28, 29, 30, //
			7, 8, 9, 34, 35, 36, //
			4, 5, 6, 16, 17, 18, //
			10, 11, 12, 22, 23, 24 //
		}, 6, 6);
	assertIterationsEqual(expected, Views.iterable(shuffled));
}
 
Example #25
Source File: ShuffledViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public <T extends RealType<T>, U extends RealType<U>> void testDiffSeeds() {
	// FIRST - create 6x6 image filled with known values
	ArrayImg<UnsignedByteType, ByteArray> inputImage = ArrayImgs.unsignedBytes(
		new byte[] { //
			1, 2, 3, 4, 5, 6, //
			7, 8, 9, 10, 11, 12, //
			13, 14, 15, 16, 17, 18, //
			19, 20, 21, 22, 23, 24, //
			25, 26, 27, 28, 29, 30, //
			31, 32, 33, 34, 35, 36 //
		}, 6, 6);
	int[] blockSize = { 2, 2 };
	long seed1 = 0xdeadbeef;
	long seed2 = 0x22334455;
	ShuffledView<UnsignedByteType> shuffled1 = new ShuffledView<>(inputImage,
		blockSize, seed1);
	ArrayImg<UnsignedByteType, ByteArray> expected1 = ArrayImgs.unsignedBytes(
		new byte[] { //
			27, 28, 3, 4, 15, 16, //
			33, 34, 9, 10, 21, 22, //
			5, 6, 17, 18, 13, 14, //
			11, 12, 23, 24, 19, 20, //
			1, 2, 29, 30, 25, 26, //
			7, 8, 35, 36, 31, 32 //
		}, 6, 6);
	ShuffledView<UnsignedByteType> shuffled2 = new ShuffledView<>(inputImage,
		blockSize, seed2);
	ArrayImg<UnsignedByteType, ByteArray> expected2 = ArrayImgs.unsignedBytes(
		new byte[] { //
			29, 30, 25, 26, 17, 18, //
			35, 36, 31, 32, 23, 24, //
			5, 6, 27, 28, 15, 16, //
			11, 12, 33, 34, 21, 22, //
			3, 4, 13, 14, 1, 2, //
			9, 10, 19, 20, 7, 8 //
		}, 6, 6);
	assertIterationsEqual(expected1, Views.iterable(shuffled1));
	assertIterationsEqual(expected2, Views.iterable(shuffled2));
}
 
Example #26
Source File: MVDeconFFT.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static ArrayImg< FloatType, ? > computeExponentialKernel( final ArrayImg< FloatType, ? > kernel, final int numViews )
{
	final ArrayImg< FloatType, ? > exponentialKernel = kernel.copy();

	for ( final FloatType f : exponentialKernel )
		f.set( pow( f.get(), numViews ) );

	return exponentialKernel;
}
 
Example #27
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param dim dimensions of the image
 * @param radii of the ellipse
 * @param offset of the ellipse
 * @return an {@link Img} of {@link BitType} filled with a ellipse
 */
@SuppressWarnings({ "deprecation" })
public Img<UnsignedByteType> getEllipsedBitImage(final long[] dim,
	final double[] radii, final double[] offset)
{

	// create empty bittype image with desired dimensions
	final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
		dim);

	// create ellipse
	final EllipseRegionOfInterest ellipse = new EllipseRegionOfInterest();
	ellipse.setRadii(radii);

	// set origin in the center of image
	final double[] origin = new double[dim.length];
	for (int i = 0; i < dim.length; i++)
		origin[i] = dim[i] / 2;
	ellipse.setOrigin(origin);

	// get iterable intervall and cursor of ellipse
	final IterableInterval<UnsignedByteType> ii = ellipse
		.getIterableIntervalOverROI(img);
	final Cursor<UnsignedByteType> cursor = ii.cursor();

	// fill image with ellipse
	while (cursor.hasNext()) {
		cursor.next();
		cursor.get().set(255);
	}

	return img;
}
 
Example #28
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param dim a long array with the desired dimensions of the image
 * @return an {@link Img} of {@link UnsignedByteType} filled with random
 *         values.
 */
public Img<UnsignedByteType> getRandomUnsignedByteImg(final long[] dim) {
	final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
		dim);

	final UnsignedByteType type = img.firstElement();

	final ArrayCursor<UnsignedByteType> cursor = img.cursor();
	while (cursor.hasNext()) {
		cursor.next().set(rand.nextInt((int) type.getMaxValue()));
	}

	return img;
}
 
Example #29
Source File: LocalThresholdTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImgSmall() {
	final long[] dims = new long[] { 2, 2 };
	final byte[] array = new byte[4];

	array[0] = (byte) 10;
	array[1] = (byte) 20;
	array[2] = (byte) 30;
	array[3] = (byte) 40;

	return ArrayImgs.bytes(array, dims);
}
 
Example #30
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateByteArrayTestImg(
	final boolean fill, final long... dims)
{
	final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (byte) pseudoRandom();
		}
	}

	return ArrayImgs.bytes(array, dims);
}