net.imglib2.RealRandomAccess Java Examples

The following examples show how to use net.imglib2.RealRandomAccess. 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: ValueDisplayListener.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private <D> void getInfo()
{
	final Optional<Source<?>> optionalSource = Optional.ofNullable(currentSource.getValue());
	if (optionalSource.isPresent() && optionalSource.get() instanceof DataSource<?, ?>)
	{
		@SuppressWarnings("unchecked") final DataSource<D, ?> source = (DataSource<D, ?>) optionalSource.get();
		final ViewerState       state                = viewer.getState();
		final Interpolation     interpolation        = this.interpolation.apply(source);
		final AffineTransform3D screenScaleTransform = new AffineTransform3D();
		viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform);
		final int               level                = state.getBestMipMapLevel(screenScaleTransform, source);
		final AffineTransform3D affine               = new AffineTransform3D();
		source.getSourceTransform(0, level, affine);
		final RealRandomAccess<D> access = RealViews.transformReal(
				source.getInterpolatedDataSource(
						0,
						level,
						interpolation
				                                ),
				affine
		                                                          ).realRandomAccess();
		final D                   val    = getVal(x, y, access, viewer);
		submitValue.accept(stringConverterFromSource(source).apply(val));
	}
}
 
Example #2
Source File: IdSelector.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void accept(final MouseEvent e)
{
		final AffineTransform3D affine      = new AffineTransform3D();
		final ViewerState       viewerState = viewer.getState().copy();
		viewerState.getViewerTransform(affine);
		final AffineTransform3D screenScaleTransform = new AffineTransform3D();
		viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform);
		final int level = viewerState.getBestMipMapLevel(screenScaleTransform, source);

		source.getSourceTransform(0, level, affine);
		final RealRandomAccess<? extends IntegerType<?>> access =
				RealViews.transformReal(source.getInterpolatedDataSource(0, level, Interpolation.NEARESTNEIGHBOR), affine).realRandomAccess();
		viewer.getMouseCoordinates(access);
		access.setPosition(0L, 2);
		viewer.displayToGlobalCoordinates(access);
		final IntegerType<?> val = access.get();
		final long id  = val.getIntegerLong();
		actOn(id);
}
 
Example #3
Source File: TransformInput.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String call() throws Exception 
{
	final NLinearInterpolatorFactory< FloatType > f = new NLinearInterpolatorFactory< FloatType >();
	
	// make the interpolators and get the transformations
	final RealRandomAccess< FloatType > ir = Views.interpolate( Views.extendMirrorSingle( img ), f ).realRandomAccess();
	final Cursor< FloatType > cursor = Views.iterable( transformedImg ).localizingCursor();

	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
		loop( cursor, ir, transform, s, t, offsetX, offsetY, offsetZ, imgSizeX, imgSizeY, imgSizeZ );
	
	return portion + " finished successfully (transform input & no weights).";
}
 
Example #4
Source File: TransformInputAndWeights.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String call() throws Exception 
{
	final NLinearInterpolatorFactory< FloatType > f = new NLinearInterpolatorFactory< FloatType >();
	
	// make the interpolators and get the transformations
	final RealRandomAccess< FloatType > ir = Views.interpolate( Views.extendMirrorSingle( img ), f ).realRandomAccess();
	final RealRandomAccess< FloatType > wr = blending.realRandomAccess();

	final Cursor< FloatType > cursor = Views.iterable( transformedImg ).localizingCursor();
	final Cursor< FloatType > cursorW = Views.iterable( weightImg ).cursor();

	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];

	cursor.jumpFwd( portion.getStartPosition() );
	cursorW.jumpFwd( portion.getStartPosition() );

	for ( int j = 0; j < portion.getLoopSize(); ++j )
		loop( cursor, cursorW, ir, wr, transform, s, t, offsetX, offsetY, offsetZ, imgSizeX, imgSizeY, imgSizeZ );

	return portion + " finished successfully (transform input & precompute weights).";
}
 
Example #5
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 #6
Source File: AffineWarpField.java    From render with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Logic stolen from
 * <a href='https://github.com/trakem2/TrakEM2/blob/master/TrakEM2_/src/main/java/org/janelia/intensity/LinearIntensityMap.java'>
 *   TrakEM2 LinearIntensityMap
 * </a>.
 *
 * @return an accessor for deriving warped pixel intensities.
 */
public RealRandomAccess<RealComposite<DoubleType>> getAccessor() {

    final ArrayImg<DoubleType, DoubleArray> warpField =
            ArrayImgs.doubles(values, columnCount, rowCount, VALUES_PER_AFFINE);

    final CompositeIntervalView<DoubleType, RealComposite<DoubleType>>
            collapsedSource = Views.collapseReal(warpField);

    final RandomAccessible<RealComposite<DoubleType>> extendedCollapsedSource = Views.extendBorder(collapsedSource);
    final RealRandomAccessible<RealComposite<DoubleType>> coefficients =
            Views.interpolate(extendedCollapsedSource, interpolatorFactory);

    final double xScale = getXScale();
    final double yScale = getYScale();
    final double[] scale = { xScale, yScale };
    final double[] shift = { 0.5 * xScale , 0.5 * yScale };

    final ScaleAndTranslation scaleAndTranslation = new ScaleAndTranslation(scale, shift);

    final RealRandomAccessible<RealComposite<DoubleType>> stretchedCoefficients =
            RealViews.transform(coefficients, scaleAndTranslation);

    return stretchedCoefficients.realRandomAccess();
}
 
Example #7
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 #8
Source File: Fusion.java    From Stitching with GNU General Public License v2.0 6 votes vote down vote up
/**
* Helper method to lazily initialize the input image interpolators,
* creating one list per thread.
*/
private
	ArrayList<RealRandomAccess<? extends RealType<?>>>
	getThreadInterpolators(
		List<ArrayList<RealRandomAccess<? extends RealType<?>>>> interpolators,
		int threadNumber,
		ArrayList<? extends ImageInterpolation<? extends RealType<?>>> input,
		int numImages)
{
	ArrayList<RealRandomAccess<? extends RealType<?>>> in = null;
	if (threadNumber >= interpolators.size()) {
		in = new ArrayList<RealRandomAccess<? extends RealType<?>>>();
		for (int i = 0; i < numImages; ++i) {
			in.add(input.get(i).createInterpolator());
		}
		interpolators.add(in);
	}
	else {
		in = interpolators.get(threadNumber);
	}
	return in;
}
 
Example #9
Source File: ContentBased.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RealRandomAccess<FloatType> realRandomAccess( final RealInterval interval )
{
	return Views.interpolate(
			Views.extendZero( this.contentBasedImg ),
			new NLinearInterpolatorFactory< FloatType >()
			).realRandomAccess( interval );
}
 
Example #10
Source File: ContentBased.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RealRandomAccess<FloatType> realRandomAccess()
{ 
	return Views.interpolate(
		Views.extendZero( this.contentBasedImg ),
		new NLinearInterpolatorFactory< FloatType >()
		).realRandomAccess();
}
 
Example #11
Source File: BlendingRealRandomAccess.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RealRandomAccess<FloatType> copyRealRandomAccess()
{
	final BlendingRealRandomAccess r = new BlendingRealRandomAccess( interval, border, blending );
	r.setPosition( this );
	return r;
}
 
Example #12
Source File: TransformInput.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 RealRandomAccess< FloatType > ir,
		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 );

	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() ) );
	}
}
 
Example #13
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 #14
Source File: TransformWeights.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String call() throws Exception 
{
	// make the blending and get the transformations
	final RealRandomAccess< FloatType > wr = blending.realRandomAccess();

	final Cursor< FloatType > cursorO = Views.iterable( overlapImg ).localizingCursor();
	final Cursor< FloatType > cursorB = Views.iterable( blendingImg ).cursor();

	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];

	cursorO.jumpFwd( portion.getStartPosition() );
	cursorB.jumpFwd( portion.getStartPosition() );

	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final FloatType o = cursorO.next();
		cursorO.localize( s );
		
		// move weight cursor forward and get the value 
		final FloatType b = cursorB.next();

		s[ 0 ] += offsetX;
		s[ 1 ] += offsetY;
		s[ 2 ] += offsetZ;

		transform.applyInverse( t, s );

		// compute weights in any part of the image (the border can be negative!)
		wr.setPosition( t );

		o.set( o.get() + 1 );
		b.set( wr.get() );
	}

	return portion + " finished successfully (visualize weights).";
}
 
Example #15
Source File: ConsensusWarpFieldBuilder.java    From render with GNU General Public License v2.0 5 votes vote down vote up
public static double[] getAffineMatrixElements(final RealRandomAccess<RealComposite<DoubleType>> warpFieldAccessor,
                                               final double[] location) {
    warpFieldAccessor.setPosition(location);
    final RealComposite<DoubleType> coefficients = warpFieldAccessor.get();
    return new double[] {
            coefficients.get(0).getRealDouble(),
            coefficients.get(1).getRealDouble(),
            coefficients.get(2).getRealDouble(),
            coefficients.get(3).getRealDouble(),
            coefficients.get(4).getRealDouble(),
            coefficients.get(5).getRealDouble()
    };
}
 
Example #16
Source File: Fusion.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * Intermediate helper method to delegate to
	 * {@link #processTile(ClassifiedRegion, int[], int, PixelFusion, ArrayList, ArrayList, LocalizableByDimCursor, float[], int[], int, int[], long[], ImagePlus)}
	 */
private void processTile(ClassifiedRegion r, int depth,
	PixelFusion myFusion, ArrayList<InvertibleBoundable> transform,
	ArrayList<RealRandomAccess<? extends RealType<?>>> in,
	RandomAccess<T> out, double[][] inPos,
	int threadNumber, int[] count, long[] lastDraw, ImagePlus fusionImp)
	throws NoninvertibleModelException
{
	processTile(r, r.classArray(), depth, myFusion, transform, in, out,
		inPos, threadNumber, count, lastDraw, fusionImp);
}
 
Example #17
Source File: BlendingRealRandomAccess.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RealRandomAccess<FloatType> copyRealRandomAccess()
{
	final BlendingRealRandomAccess r = new BlendingRealRandomAccess( interval, border, blending );
	r.setPosition( this );
	return r;
}
 
Example #18
Source File: LabelSourceStateMergeDetachHandler.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void accept(final MouseEvent e)
{
	final long lastSelection = selectedIds.getLastSelection();

	if (lastSelection == Label.INVALID) { return; }

	final AffineTransform3D screenScaleTransform = new AffineTransform3D();
	viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform);
	final int level = viewer.getState().getBestMipMapLevel(screenScaleTransform, source);

	final AffineTransform3D affine = new AffineTransform3D();
	source.getSourceTransform(0, level, affine);
	final RealRandomAccessible<? extends IntegerType<?>> transformedSource = RealViews
			.transformReal(
					source.getInterpolatedDataSource(0, level, Interpolation.NEARESTNEIGHBOR),
					affine);
	final RealRandomAccess<? extends IntegerType<?>> access = transformedSource.realRandomAccess();
	viewer.getMouseCoordinates(access);
	access.setPosition(0L, 2);
	viewer.displayToGlobalCoordinates(access);
	final IntegerType<?> val = access.get();
	final long id  = val.getIntegerLong();

	if (FOREGROUND_CHECK.test(id))
	{
		final Optional<Detach> detach = assignment.getDetachAction(id, lastSelection);
		detach.ifPresent(assignment::apply);
	}
}
 
Example #19
Source File: LabelSourceStateMergeDetachHandler.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void accept(final MouseEvent e)
{
	synchronized (viewer)
	{

		final long lastSelection = selectedIds.getLastSelection();

		if (lastSelection == Label.INVALID) { return; }

		final AffineTransform3D screenScaleTransform = new AffineTransform3D();
		viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform);
		final int level = viewer.getState().getBestMipMapLevel(screenScaleTransform, source);

		final AffineTransform3D affine = new AffineTransform3D();
		source.getSourceTransform(0, level, affine);
		final RealRandomAccess<? extends IntegerType<?>> access = RealViews.transformReal(
				source.getInterpolatedDataSource(
						0,
						level,
						Interpolation.NEARESTNEIGHBOR),
				affine).realRandomAccess();
		viewer.getMouseCoordinates(access);
		access.setPosition(0L, 2);
		viewer.displayToGlobalCoordinates(access);
		final IntegerType<?> val = access.get();
		final long id = val.getIntegerLong();

		if (FOREGROUND_CHECK.test(id))
		{
			LOG.debug("Merging fragments: {} -- last selection: {}", id, lastSelection);
			final Optional<Merge> action = assignment.getMergeAction(
					id,
					lastSelection,
					idService::next);
			action.ifPresent(assignment::apply);
		}
	}
}
 
Example #20
Source File: ValueDisplayListener.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <D> D getVal(final double x, final double y, final RealRandomAccess<D> access, final ViewerPanelFX
		viewer)
{
	access.setPosition(x, 0);
	access.setPosition(y, 1);
	access.setPosition(0l, 2);
	return getVal(access, viewer);
}
 
Example #21
Source File: Blending.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public RealRandomAccess<FloatType> realRandomAccess( final RealInterval interval )
{
	return realRandomAccess();
}
 
Example #22
Source File: ProcessIndependentPortion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	// make the interpolators and get the transformations
	final RealRandomAccess< T > r = Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess();
	final int[] imgSize = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		transform.applyInverse( t, s );
		
		if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSize[ 0 ], imgSize[ 1 ], imgSize[ 2 ] ) )
		{
			r.setPosition( t );
			v.setReal( r.get().getRealFloat() );
		}
	}
	
	return portion + " finished successfully (individual fusion, no weights).";
}
 
Example #23
Source File: ProcessSequentialPortionWeights.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators, weights and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final ArrayList< ArrayList< RealRandomAccess< FloatType > > > weightAccess = new ArrayList< ArrayList< RealRandomAccess< FloatType > > >();
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
		
		final ArrayList< RealRandomAccess< FloatType > > list = new ArrayList< RealRandomAccess< FloatType > >();

		for ( final RealRandomAccessible< FloatType > rra : weights.get( i ) )
			list.add( rra.realRandomAccess() );
		
		weightAccess.add( list );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final Cursor< FloatType > cursorW = weightImg.cursor();
	
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	cursorW.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );

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

		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		double sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				
				double w1 = 1;
				
				for ( final RealRandomAccess< FloatType > weight : weightAccess.get( i ) )
				{
					weight.setPosition( t );
					w1 *= weight.get().get();
				}
				
				sum += r.get().getRealDouble() * w1;
				sumW += w1;
			}
		}
		
		if ( sumW > 0 )
		{
			v.setReal( v.getRealFloat() + sum );
			w.set( w.get() + (float)sumW );
		}
	}
	
	return portion + " finished successfully (many weights).";
}
 
Example #24
Source File: ProcessSequentialPortion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final Cursor< FloatType > cursorW = weightImg.cursor();
	
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	cursorW.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		// move weight cursor forward and get the value 
		final FloatType w = cursorW.next();
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		int sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				sum += r.get().getRealDouble();
				++sumW;
			}
		}
		
		if ( sumW > 0 )
		{
			v.setReal( v.getRealFloat() + sum );
			w.set( w.get() + sumW );
		}
	}
	
	return portion + " finished successfully (no weights).";
}
 
Example #25
Source File: ProcessParalellPortionWeight.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators, weights and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final ArrayList< RealRandomAccess< FloatType > > weightAccess = new ArrayList< RealRandomAccess< FloatType > >();
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
					
		weightAccess.add( weights.get( i ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		double sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				
				final RealRandomAccess< FloatType > weight = weightAccess.get( i );
				weight.setPosition( t );
				
				final double w = weight.get().get();
				
				sum += r.get().getRealDouble() * w;
				sumW += w;
			}
		}
		
		if ( sumW > 0 )
			v.setReal( sum / sumW );
	}
	
	return portion + " finished successfully (one weight).";
}
 
Example #26
Source File: ProcessSequentialPortionWeight.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators, weights and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final ArrayList< RealRandomAccess< FloatType > > weightAccess = new ArrayList< RealRandomAccess< FloatType > >();
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
					
		weightAccess.add( weights.get( i ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final Cursor< FloatType > cursorW = weightImg.cursor();

	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	cursorW.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );

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

		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		double sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				
				final RealRandomAccess< FloatType > weight = weightAccess.get( i );
				weight.setPosition( t );
				
				final double w1 = weight.get().get();
				
				sum += r.get().getRealDouble() * w1;
				sumW += w1;
			}
		}
		
		if ( sumW > 0 )
		{
			v.setReal( v.getRealFloat() + sum );
			w.set( w.get() + (float)sumW );
		}
	}
	
	return portion + " finished successfully (one weight).";
}
 
Example #27
Source File: Blending.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public RealRandomAccess<FloatType> realRandomAccess()
{
	return new BlendingRealRandomAccess( interval, border, blending );
}
 
Example #28
Source File: ProcessParalellPortionWeights.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators, weights and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final ArrayList< ArrayList< RealRandomAccess< FloatType > > > weightAccess = new ArrayList< ArrayList< RealRandomAccess< FloatType > > >();
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
		
		final ArrayList< RealRandomAccess< FloatType > > list = new ArrayList< RealRandomAccess< FloatType > >();

		for ( final RealRandomAccessible< FloatType > rra : weights.get( i ) )
			list.add( rra.realRandomAccess() );
		
		weightAccess.add( list );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		double sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				
				double w = 1;
				
				for ( final RealRandomAccess< FloatType > weight : weightAccess.get( i ) )
				{
					weight.setPosition( t );
					w *= weight.get().get();
				}
				
				sum += r.get().getRealDouble() * w;
				sumW += w;
			}
		}
		
		if ( sumW > 0 )
			v.setReal( sum / sumW );
	}
	
	return portion + " finished successfully (many weights).";
}
 
Example #29
Source File: ProcessParalellPortion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		int sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				sum += r.get().getRealDouble();
				++sumW;
			}
		}
		
		if ( sumW > 0 )
			v.setReal( sum / sumW );
	}
	
	return portion + " finished successfully (no weights).";
}
 
Example #30
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Extracts the PSF by averaging the local neighborhood RANSAC correspondences
 * @param size - the size in which the psf is extracted (in pixel units, z-scaling is ignored)
 * @return - the psf, NOT z-scaling corrected
 */
protected static < T extends RealType< T > & NativeType< T > > ArrayImg< T, ? > extractPSFLocal(
		final RandomAccessibleInterval< T > img,
		final ArrayList< double[] > locations,
		final long[] size )
{
	final int numDimensions = size.length;
	
	final ArrayImg< T, ? > psf = new ArrayImgFactory< T >().create( size, Views.iterable( img ).firstElement() );
	
	// Mirror produces some artifacts ... so we use periodic
	final RealRandomAccess< T > interpolator =
			Views.interpolate( Views.extendPeriodic( img ), new NLinearInterpolatorFactory< T >() ).realRandomAccess();
	
	final ArrayLocalizingCursor< T > psfCursor = psf.localizingCursor();
	
	final long[] sizeHalf = size.clone();
	for ( int d = 0; d < numDimensions; ++d )
		sizeHalf[ d ] /= 2;
	
	final int[] tmpI = new int[ size.length ];
	final double[] tmpD = new double[ size.length ];

	for ( final double[] position : locations )
	{
		psfCursor.reset();
		
		while ( psfCursor.hasNext() )
		{
			psfCursor.fwd();
			psfCursor.localize( tmpI );

			for ( int d = 0; d < numDimensions; ++d )
				tmpD[ d ] = tmpI[ d ] - sizeHalf[ d ] + position[ d ];
			
			interpolator.setPosition( tmpD );
			
			psfCursor.get().add( interpolator.get() );
		}
	}

	return psf;
}