net.imglib2.type.numeric.real.FloatType Java Examples

The following examples show how to use net.imglib2.type.numeric.real.FloatType. 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: PaddingTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void theTest() {

	Img<FloatType> ramp = ArrayImgs.floats(256, 256);
	Img<FloatType> average = ArrayImgs.floats(64, 64);

	int i = 0;
	for (FloatType iv : ramp)
		iv.set(i / 256 + (i++) % 256);
	for (FloatType kv : average)
		kv.set(1f / (64 * 64));

	RandomAccessibleInterval<FloatType> one=ops.filter().convolve(ramp, average);
	RandomAccessibleInterval<FloatType> two=ops.filter().convolve(ramp, average, new OutOfBoundsPeriodicFactory<>());

	assertEquals(ops.stats().mean(Views.iterable(one)).getRealDouble(), 224.5312520918087, 0.0);
	assertEquals(ops.stats().mean(Views.iterable(two)).getRealDouble(), 255.0000066360226, 0.0);
}
 
Example #2
Source File: DefaultDistanceTransformTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test() {
	// create 4D image
	final RandomAccessibleInterval<BitType> in = ops.create().img(new FinalInterval(20, 20, 5, 3), new BitType());
	generate4DImg(in);

	/*
	 * test normal DT
	 */
	RandomAccessibleInterval<FloatType> out = (RandomAccessibleInterval<FloatType>) ops
			.run(DefaultDistanceTransform.class, null, in);
	compareResults(out, in, new double[] { 1, 1, 1, 1 });

	/*
	 * test calibrated DT
	 */
	final double[] calibration = new double[] { 3.74, 5.19, 1.21, 2.21 };
	out = (RandomAccessibleInterval<FloatType>) ops.run(DefaultDistanceTransformCalibration.class, null, in,
			calibration);
	compareResults(out, in, calibration);
}
 
Example #3
Source File: TransformWeights.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public TransformWeights(
		final ImagePortion portion,
		final Interval imgInterval,
		final Blending blending,
		final AffineTransform3D transform,
		final RandomAccessibleInterval< FloatType > overlapImg,
		final RandomAccessibleInterval< FloatType > blendingImg,
		final long[] offset )
{
	this.portion = portion;
	this.blendingImg = blendingImg;
	this.transform = transform;
	this.overlapImg = overlapImg;
	this.blending = blending;

	this.offsetX = (int)offset[ 0 ];
	this.offsetY = (int)offset[ 1 ];
	this.offsetZ = (int)offset[ 2 ];

	this.imgSizeX = (int)imgInterval.dimension( 0 );
	this.imgSizeY = (int)imgInterval.dimension( 1 );
	this.imgSizeZ = (int)imgInterval.dimension( 2 );
}
 
Example #4
Source File: MinimalTest.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RandomAccessibleInterval< FloatType > getFloatImage(
		int timepointId, boolean normalize, ImgLoaderHint... hints )
{
	final Random rnd = new Random( setupId );

	final Img< FloatType > img = ArrayImgs.floats( 512, 512, 86 );

	final float scale;
	
	if ( normalize )
		scale = 1;
	else
		scale = 20000;
	
	for ( final FloatType t : img )
		t.set( rnd.nextFloat() * scale);

	return img;
}
 
Example #5
Source File: TransformInputAndWeights.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public TransformInputAndWeights(
		final ImagePortion portion,
		final RandomAccessibleInterval< FloatType > img,
		final Blending blending,
		final AffineTransform3D transform,
		final RandomAccessibleInterval< FloatType > transformedImg,
		final RandomAccessibleInterval< FloatType > weightImg,
		final long[] offset )
{
	this.portion = portion;
	this.img = img;
	this.weightImg = weightImg;
	this.transform = transform;
	this.transformedImg = transformedImg;
	this.blending = blending;

	this.offsetX = (int)offset[ 0 ];
	this.offsetY = (int)offset[ 1 ];
	this.offsetZ = (int)offset[ 2 ];

	this.imgSizeX = (int)img.dimension( 0 );
	this.imgSizeY = (int)img.dimension( 1 );
	this.imgSizeZ = (int)img.dimension( 2 );
}
 
Example #6
Source File: HistogramOfOrientedGradients2D.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Void call() throws Exception {

	final FinalInterval interval = new FinalInterval(in.dimension(0), in.dimension(1));
	for (int j = 0; j < in.dimension(1); j++) {
		// sum up the magnitudes of all bins in a neighborhood
		raNeighbor.setPosition(new long[] { i, j });
		final Cursor<FloatType> cursorNeighborHood = raNeighbor.get().cursor();
		while (cursorNeighborHood.hasNext()) {
			cursorNeighborHood.next();
			if (Intervals.contains(interval, cursorNeighborHood)) {
				raAngles.setPosition(cursorNeighborHood);
				raMagnitudes.setPosition(cursorNeighborHood);
				raOut.setPosition(new long[] { i, j,
						(int) (raAngles.get().getRealFloat() / (360 / numOrientations) - 0.5) });
				raOut.get().add(raMagnitudes.get());
			}
		}
	}
	return null;
}
 
Example #7
Source File: DistanceTransform2DTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void compareResults(final RandomAccessibleInterval<FloatType> out,
		final RandomAccessibleInterval<BitType> in, final double[] calibration) {
	final RandomAccess<FloatType> raOut = out.randomAccess();
	final RandomAccess<BitType> raIn = in.randomAccess();
	for (int x0 = 0; x0 < in.dimension(0); x0++) {
		for (int y0 = 0; y0 < in.dimension(1); y0++) {
			raIn.setPosition(new int[] { x0, y0 });
			raOut.setPosition(new int[] { x0, y0 });
			if (!raIn.get().get()) {
				assertEquals(0, raOut.get().get(), EPSILON);
			} else {
				double actualValue = in.dimension(0) * in.dimension(0) + in.dimension(1) * in.dimension(1);
				for (int x = 0; x < in.dimension(0); x++) {
					for (int y = 0; y < in.dimension(1); y++) {
						raIn.setPosition(new int[] { x, y });
						final double dist = calibration[0] * calibration[0] * (x0 - x) * (x0 - x)
								+ calibration[1] * calibration[1] * (y0 - y) * (y0 - y);
						if ((!raIn.get().get()) && (dist < actualValue))
							actualValue = dist;
					}
				}
				assertEquals(Math.sqrt(actualValue), raOut.get().get(), EPSILON);
			}
		}
	}
}
 
Example #8
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 #9
Source File: StatisticsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void MinMaxTest() {
	float min1 = Float.MAX_VALUE;
	float max1 = Float.MIN_VALUE;

	// loop through the array calculating min and max
	for (int i = 0; i < arraySize; i++) {
		if (array[i] < min1) min1 = array[i];
		if (array[i] > max1) max1 = array[i];
	}

	// calculate min using ops
	FloatType min2 = new FloatType();
	min2.setReal(Float.MAX_VALUE);
	ops.run(IterableMin.class, min2, img);

	// calculate max using ops
	FloatType max2 = new FloatType();
	max2.setReal(Float.MIN_VALUE);
	ops.run(IterableMax.class, max2, img);

	// check to see if everything matches
	Assert.assertEquals(min1, min2.getRealFloat(), delta);
	Assert.assertEquals(max1, max2.getRealFloat(), delta);
}
 
Example #10
Source File: FrangiVesselness.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void run() {
	// parse the spacing, and scales strings.
	spacing = checkDimensions(spacingString, input.numDimensions(), "Spacings");
	scales = Arrays.stream(scaleString.split(regex)).mapToInt(Integer::parseInt)
		.toArray();
	Dimensions resultDims = Views.addDimension(input, 0, scales.length - 1);
	// create output image, potentially-filtered input
	result = opService.create().img(resultDims, new FloatType());

	for (int s = 0; s < scales.length; s++) {
		// Determine whether or not the user would like to apply the gaussian
		// beforehand and do it.
		RandomAccessibleInterval<T> vesselnessInput = doGauss ? opService.filter()
			.gauss(input, scales[s]) : input;
		IntervalView<FloatType> scaleResult = Views.hyperSlice(result, result
			.numDimensions() - 1, s);
		opService.filter().frangiVesselness(scaleResult, vesselnessInput, spacing,
			scales[s]);
	}
}
 
Example #11
Source File: BlendingRealRandomAccess.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * RealRandomAccess that computes a blending function for a certain {@link Interval}
 * 
 * @param interval - the interval it is defined on (return zero outside of it)
 * @param border - how many pixels to skip before starting blending (on each side of each dimension)
 * @param blending - how many pixels to compute the blending function on (on each side of each dimension)
 */
public BlendingRealRandomAccess(
		final Interval interval,
		final float[] border,
		final float[] blending )
{
	this.interval = interval;
	this.n = interval.numDimensions();
	this.l = new float[ n ];
	this.border = border;
	this.blending = blending;
	this.v = new FloatType();
	
	this.min = new int[ n ];
	this.dimMinus1 = new int[ n ];
	
	for ( int d = 0; d < n; ++d )
	{
		this.min[ d ] = (int)interval.min( d );
		this.dimMinus1[ d ] = (int)interval.max( d ) - min[ d ];
	}
}
 
Example #12
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 #13
Source File: Align.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public Align(final RandomAccessibleInterval< T > template, final ImgFactory< FloatType > factory, WarpFunction model)
{
	this.template = template;

	n = template.numDimensions();
	warpFunction = model;
	numParameters = warpFunction.numParameters();
	
	currentTransform = new AffineTransform( n );
	
	final long[] dim = new long[n + 1];
	for ( int d = 0; d < n; ++d )
		dim[d] = template.dimension( d );
	dim[n] = n;
	final Img< FloatType > gradients = factory.create( dim, new FloatType() );
	gradients( Views.extendBorder( template ), gradients );

	dim[n] = numParameters;
	descent = factory.create( dim, new FloatType() );
	computeSteepestDescents( gradients, warpFunction, descent );

	Hinv = computeInverseHessian( descent );

	error = factory.create( template, new FloatType() );
}
 
Example #14
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 #15
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 #16
Source File: LegacyMicroManagerImgLoader.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 )
{
	try
	{
		final MultipageTiffReader r = new MultipageTiffReader( mmFile );

		final ArrayImg< FloatType, ? > img = ArrayImgs.floats( r.width(), r.height(), r.depth() );
		final BasicViewDescription< ? > vd = sequenceDescription.getViewDescriptions().get( view );

		populateImage( img, vd, r );

		if ( normalize )
			normalize( img );

		updateMetaDataCache( view, r.width(), r.height(), r.depth(), r.calX(), r.calY(), r.calZ() );

		r.close();

		return img;
	}
	catch ( Exception e )
	{
		IOFunctions.printlnSafe( "Failed to load viewsetup=" + view.getViewSetupId() + " timepoint=" + view.getTimePointId() + ": " + e );
		e.printStackTrace();
		return null;
	}
}
 
Example #17
Source File: Resave_TIFF.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static Parameters getParameters()
{
	final GenericDialogPlus gd = new GenericDialogPlus( "Resave dataset as TIFF" );

	if ( defaultPath == null )
		defaultPath = LoadParseQueryXML.defaultXMLfilename;

	PluginHelper.addSaveAsFileField( gd, "Select new XML", defaultPath, 80 );
	
	gd.addChoice( "ImgLib2_data_container", StackList.imglib2Container, StackList.imglib2Container[ defaultContainer ] );
	gd.addCheckbox( "Lossless compression of TIFF files (ZIP)", defaultCompress );
	gd.addMessage( "Use ArrayImg if -ALL- input views are smaller than ~2048x2048x500 px (2^31 px), or if the\n" +
				   "program throws an OutOfMemory exception while processing.  CellImg is slower, but more\n" +
			       "memory efficient and supports much larger file sizes only limited by the RAM of the machine.", 
			       new Font( Font.SANS_SERIF, Font.ITALIC, 11 ) );

	gd.showDialog();
	
	if ( gd.wasCanceled() )
		return null;

	final Parameters params = new Parameters();
	
	params.xmlFile = gd.getNextString();
	
	if ( !params.xmlFile.endsWith( ".xml" ) )
		params.xmlFile += ".xml";

	params.compress = defaultCompress = gd.getNextBoolean();

	defaultPath = LoadParseQueryXML.defaultXMLfilename = params.xmlFile;

	if ( ( defaultContainer = gd.getNextChoiceIndex() ) == 0 )
		params.imgFactory = new ArrayImgFactory< FloatType >();
	else
		params.imgFactory = new CellImgFactory< FloatType >();

	return params;
}
 
Example #18
Source File: MathBenchmarkTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ArrayImg<FloatType, ?> createConstantImg(long[] dims,
	float constant)
{
	// create an input
	ArrayImg<FloatType, ?> img = new ArrayImgFactory<FloatType>().create(dims,
		new FloatType());

	for (final FloatType value : img) {
		value.setReal(constant);
	}

	return img;

}
 
Example #19
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 #20
Source File: ConvertNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.convert.ConvertImages.Float32.class)
public <C extends ComplexType<C>> Img<FloatType> float32(
	final IterableInterval<C> in)
{
	@SuppressWarnings("unchecked")
	final Img<FloatType> result = (Img<FloatType>) ops().run(
		Ops.Convert.Float32.class, in);
	return result;
}
 
Example #21
Source File: ProcessSequentialPortionWeights.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public ProcessSequentialPortionWeights(
		final ImagePortion portion,
		final ArrayList< RandomAccessibleInterval< T > > imgs,
		final ArrayList< ArrayList< RealRandomAccessible< FloatType > > > weights,
		final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory,
		final AffineTransform3D[] transforms,
		final Img< T > fusedImg,
		final Img< FloatType > weightImg,
		final BoundingBoxGUI bb )
{
	super( portion, imgs, interpolatorFactory, transforms, fusedImg, weightImg, bb );
	
	this.weights = weights;
}
 
Example #22
Source File: FrangiVesselnessTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void regressionTest() throws Exception {

	// load in input image and expected output image.
	Img<FloatType> inputImg = (Img<FloatType>) ops.run(
		net.imagej.ops.image.equation.DefaultEquation.class,
		"Math.tan(0.3*p[0]) + Math.tan(0.1*p[1])");
	Img<FloatType> expectedOutput = ((Img<FloatType>) openFloatImg(
		"Result.tif"));

	// create ouput image
	long[] dims = new long[inputImg.numDimensions()];
	inputImg.dimensions(dims);
	Img<FloatType> actualOutput = ArrayImgs.floats(dims);

	// scale over which the filter operates (sensitivity)
	int scale = 1;

	// physical spacing between data points (1,1 since I got it from the
	// computer)
	double[] spacing = { 1, 1 };

	// run the op
	ops.run(net.imagej.ops.filter.vesselness.DefaultFrangi.class, actualOutput,
		inputImg, spacing, scale);

	// compare the output image data to that stored in the file.
	Cursor<FloatType> cursor = Views.iterable(actualOutput).localizingCursor();
	RandomAccess<FloatType> actualRA = actualOutput.randomAccess();
	RandomAccess<FloatType> expectedRA = expectedOutput.randomAccess();

	while (cursor.hasNext()) {
		cursor.fwd();
		actualRA.setPosition(cursor);
		expectedRA.setPosition(cursor);
		assertEquals(expectedRA.get().get(), actualRA.get().get(), 0);
	}
}
 
Example #23
Source File: ConvertNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.convert.ConvertImages.Float32.class)
public <C extends ComplexType<C>> Img<FloatType> float32(
	final Img<FloatType> out, final IterableInterval<C> in)
{
	@SuppressWarnings("unchecked")
	final Img<FloatType> result = (Img<FloatType>) ops().run(
		Ops.Convert.Float32.class, out, in);
	return result;
}
 
Example #24
Source File: WatershedSeededTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void test() {
	long[] dims = { 15, 30 };
	// create input image
	Img<FloatType> input = ArrayImgs.floats(dims);
	MersenneTwisterFast random = new MersenneTwisterFast(SEED);
	for (FloatType b : input) {
		b.setReal(random.nextDouble());
	}

	// create 3 seeds
	Img<BitType> bits = ArrayImgs.bits(dims);
	RandomAccess<BitType> ra = bits.randomAccess();
	ra.setPosition(new int[] { 0, 0 });
	ra.get().set(true);
	ra.setPosition(new int[] { 4, 6 });
	ra.get().set(true);
	ra.setPosition(new int[] { 10, 20 });
	ra.get().set(true);

	// compute labeled seeds
	final ImgLabeling<Integer, IntType> labeledSeeds = ops.labeling().cca(bits, StructuringElement.EIGHT_CONNECTED);

	testWithoutMask(input, labeledSeeds);

	testWithMask(input, labeledSeeds);
}
 
Example #25
Source File: MVDeconFFTThreads.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
final protected static void convolve2BlockCPU(
		final Block blockStruct, final Img< FloatType > image, final Img< FloatType > result,
		final Img< FloatType > block, final FFTConvolution< FloatType > fftConvolution2 )
{
	// ratio outside of the deconvolved space (psi) is 1
	blockStruct.copyBlock( Views.extendValue( image, new FloatType( 1.0f ) ), block );

	fftConvolution2.setImg( block );
	fftConvolution2.setOutput( block );
	fftConvolution2.convolve();
	
	blockStruct.pasteBlock( result, block );
}
 
Example #26
Source File: Fusion.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
public static void main( String[] args )
{
	new ImageJ();
	
	// test blending
	ImgFactory< FloatType > f = new ArrayImgFactory< FloatType >();
	Img< FloatType > img = f.create( new int[] { 400, 400 }, new FloatType() ); 
	
	Cursor< FloatType > c = img.localizingCursor();
	final int numDimensions = img.numDimensions();
	final double[] tmp = new double[ numDimensions ];
	
	// for blending
	final long[] dimensions = new long[ numDimensions ];
	img.dimensions( dimensions );
	final float percentScaling = 0.2f;
	final double[] border = new double[ numDimensions ];
				
	while ( c.hasNext() )
	{
		c.fwd();
		
		for ( int d = 0; d < numDimensions; ++d )
			tmp[ d ] = c.getFloatPosition( d );
		
		c.get().set( (float)BlendingPixelFusion.computeWeight( tmp, dimensions, border, percentScaling ) );
	}
	
	ImageJFunctions.show( img );
	Log.debug( "done" );
}
 
Example #27
Source File: TransformInputAndWeights.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private static final void loop(
		final Cursor< FloatType > cursor,
		final Cursor< FloatType > cursorW,
		final RealRandomAccess< FloatType > ir,
		final RealRandomAccess< FloatType > wr,
		final AffineTransform3D transform,
		final float[] s, final float[] t,
		final int offsetX, final int offsetY, final int offsetZ,
		final int imgSizeX, final int imgSizeY, final int imgSizeZ )
{
	// move img cursor forward any get the value (saves one access)
	final FloatType v = cursor.next();
	cursor.localize( s );

	// move weight cursor forward and get the value 
	final FloatType w = cursorW.next();

	s[ 0 ] += offsetX;
	s[ 1 ] += offsetY;
	s[ 2 ] += offsetZ;
	
	transform.applyInverse( t, s );
	
	if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizeX, imgSizeY, imgSizeZ ) )
	{
		ir.setPosition( t );

		// do not accept 0 values in the data where image data is present, 0 means no image data is available
		// (used in MVDeconvolution.computeQuotient)
		v.set( Math.max( MVDeconvolution.minValue, ir.get().get() ) );
	}

	// compute weights in any case (the border can be negative!)
	wr.setPosition( t );
	w.set( wr.get() );
}
 
Example #28
Source File: IO.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @deprecated Use {@link #openAllFloat(String)}.
 */
@Deprecated
public static List<SCIFIOImgPlus<FloatType>> openFloatImgs(
	final String source)
{
	return openAllFloat(source);
}
 
Example #29
Source File: ProcessSequentialPortionWeight.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public ProcessSequentialPortionWeight(
		final ImagePortion portion,
		final ArrayList< RandomAccessibleInterval< T > > imgs,
		final ArrayList< RealRandomAccessible< FloatType > > weights,
		final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory,
		final AffineTransform3D[] transforms,
		final Img< T > fusedImg,
		final Img< FloatType > weightImg,
		final BoundingBoxGUI bb )
{
	super( portion, imgs, interpolatorFactory, transforms, fusedImg, weightImg, bb );
	
	this.weights = weights;
}
 
Example #30
Source File: LightSheetZ1.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private final static boolean allZero( final Img< FloatType > slice )
{
	for ( final FloatType t : slice )
		if ( t.get() != 0.0f )
			return false;

	return true;
}