Java Code Examples for net.imglib2.view.Views#extendMirrorSingle()

The following examples show how to use net.imglib2.view.Views#extendMirrorSingle() . 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: 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 2
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 3
Source File: DefaultExtendMirrorSingleView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ExtendedRandomAccessibleInterval<T, F> calculate(F input) {
	return Views.extendMirrorSingle(input);
}
 
Example 4
Source File: DifferenceOfGaussianCUDA.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean process()
{
	// do not operate at the edge, 80% of the memory is a good idea I think
	final long memAvail = Math.round( cudaDevice.getFreeDeviceMemory() * ( percentGPUMem / 100.0 ) );
	final long imgBytes = numPixels() * 4 * 2; // float, two images on the card at once

	final long[] numBlocksDim = net.imglib2.util.Util.int2long( computeNumBlocksDim( memAvail, imgBytes, percentGPUMem, img.numDimensions(), "CUDA-Device " + cudaDevice.getDeviceId() ) );
	final BlockGenerator< Block > generator;

	if ( accurate )
		generator = new BlockGeneratorVariableSizePrecise( numBlocksDim );
	else
		generator = new BlockGeneratorVariableSizeSimple( numBlocksDim );

	final Block[] blocks = generator.divideIntoBlocks( getImgSize( img ), getKernelSize( sigma ) );

	if ( !accurate && blocks.length == 1 && ArrayImg.class.isInstance( img ) )
	{
		IOFunctions.println( "Conovlving image as one single block." );
		long time = System.currentTimeMillis();

		// copy the only directly into the result
		blocks[ 0 ].copyBlock( img, result );
		long copy = System.currentTimeMillis();
		IOFunctions.println( "Copying data took " + ( copy - time ) + "ms" );

		// convolve
		final float[] resultF = ((FloatArray)((ArrayImg< net.imglib2.type.numeric.real.FloatType, ? > )result).update( null ) ).getCurrentStorageArray();
		cudaconvolve.gauss( resultF, getImgSizeInt( result ), sigma, OutOfBounds.EXTEND_BORDER_PIXELS, 0 );
		IOFunctions.println( "Convolution took " + ( System.currentTimeMillis() - copy ) + "ms using device=" + cudaDevice.getDeviceName() + " (id=" + cudaDevice.getDeviceId() + ")" );

		// no copy back required
	}
	else
	{
		final RandomAccessible< net.imglib2.type.numeric.real.FloatType > input;
		
		if ( accurate )
			input = Views.extendMirrorSingle( img );
		else
			input = img;
		
		for( final Block block : blocks )
		{
			//long time = System.currentTimeMillis();
			final ArrayImg< net.imglib2.type.numeric.real.FloatType, FloatArray > imgBlock = ArrayImgs.floats( block.getBlockSize() );

			// copy the block
			block.copyBlock( input, imgBlock );
			//long copy = System.currentTimeMillis();
			//IOFunctions.println( "Copying block took " + ( copy - time ) + "ms" );

			// convolve
			final float[] imgBlockF = ((FloatArray)((ArrayImg< net.imglib2.type.numeric.real.FloatType, ? > )imgBlock).update( null ) ).getCurrentStorageArray();
			cudaconvolve.gauss( imgBlockF, getImgSizeInt( imgBlock ), sigma, OutOfBounds.EXTEND_BORDER_PIXELS, 0 );
			//long convolve = System.currentTimeMillis();
			//IOFunctions.println( "Convolution took " + ( convolve - copy ) + "ms using device=" + cudaDevice.getDeviceName() + " (id=" + cudaDevice.getDeviceId() + ")" );

			// no copy back required
			block.pasteBlock( result, imgBlock );
			//IOFunctions.println( "Pasting block took " + ( System.currentTimeMillis() - convolve ) + "ms" );
		}
	}

	return true;
}