net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory Java Examples

The following examples show how to use net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory. 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: N5Data.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @param reader container
 * @param dataset dataset
 * @param transform transforms voxel data into real world coordinates
 * @param priority in fetching queue
 * @param name initialize with this name
 * @param <T> data type
 * @param <V> viewer type
 * @return {@link DataSource}
 * @throws IOException if any N5 operation throws {@link IOException}
 */
public static <T extends NativeType<T> & RealType<T>, V extends Volatile<T> & NativeType<V> & RealType<V>>
DataSource<T, V> openRawAsSource(
		final N5Reader reader,
		final String dataset,
		final AffineTransform3D transform,
		final SharedQueue queue,
		final int priority,
		final String name) throws IOException, ReflectionException {
	return openScalarAsSource(
			reader,
			dataset,
			transform,
			queue,
			priority,
			i -> i == Interpolation.NLINEAR
			     ? new NLinearInterpolatorFactory<>()
			     : new NearestNeighborInterpolatorFactory<>(),
			i -> i == Interpolation.NLINEAR
			     ? new NLinearInterpolatorFactory<>()
			     : new NearestNeighborInterpolatorFactory<>(),
			name
	                         );
}
 
Example #2
Source File: N5Data.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @param reader container
 * @param dataset dataset
 * @param transform transforms voxel data into real world coordinates
 * @param priority in fetching queue
 * @param name initialize with this name
 * @param <T> data type
 * @param <V> viewer type
 * @return {@link DataSource}
 * @throws IOException if any N5 operation throws {@link IOException}
 */
public static <T extends NativeType<T>, V extends Volatile<T> & NativeType<V>>
DataSource<T, V> openScalarAsSource(
		final N5Reader reader,
		final String dataset,
		final AffineTransform3D transform,
		final SharedQueue queue,
		final int priority,
		final String name) throws IOException, ReflectionException {
	return openScalarAsSource(
			reader,
			dataset,
			transform,
			queue,
			priority,
			i -> new NearestNeighborInterpolatorFactory<>(),
			i -> new NearestNeighborInterpolatorFactory<>(),
			name
	                         );
}
 
Example #3
Source File: N5Data.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @param reader container
 * @param dataset dataset
 * @param transform transforms voxel data into real world coordinates
 * @param priority in fetching queue
 * @param name initialize with this name
 * @return {@link DataSource}
 * @throws IOException if any N5 operation throws {@link IOException}
 */
public static DataSource<LabelMultisetType, VolatileLabelMultisetType>
openLabelMultisetAsSource(
		final N5Reader reader,
		final String dataset,
		final AffineTransform3D transform,
		final SharedQueue queue,
		final int priority,
		final String name) throws IOException, ReflectionException {
	return new N5DataSource<>(
			Objects.requireNonNull(N5Meta.fromReader(reader, dataset)),
			transform,
			name,
			queue,
			priority,
			i -> new NearestNeighborInterpolatorFactory<>(),
			i -> new NearestNeighborInterpolatorFactory<>()
	);
}
 
Example #4
Source File: ShapeInterpolationMode.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static RealRandomAccessible<UnsignedLongType> getTransformedMask(final Mask<UnsignedLongType> mask, final AffineTransform3D transform)
{
	final RealRandomAccessible<UnsignedLongType> interpolatedMask = Views.interpolate(
			Views.extendValue(mask.mask, new UnsignedLongType(Label.OUTSIDE)),
			new NearestNeighborInterpolatorFactory<>()
		);
	return RealViews.affine(interpolatedMask, transform);
}
 
Example #5
Source File: Interpolations.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public InterpolatorFactory<T, RandomAccessible<T>> apply(final Interpolation t)
{
	return t.equals(Interpolation.NLINEAR)
	       ? new NLinearInterpolatorFactory<>()
	       : new NearestNeighborInterpolatorFactory<>();
}
 
Example #6
Source File: N5DataSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <T extends NativeType<T>> Function<Interpolation, InterpolatorFactory<T, RandomAccessible<T>>>
interpolation(final N5Reader n5, final String dataset)
throws IOException
{
	return N5Types.isLabelMultisetType(n5, dataset)
	       ? i -> new NearestNeighborInterpolatorFactory<>()
	       : (Function) realTypeInterpolation();
}
 
Example #7
Source File: N5DataSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <T extends RealType<T>> Function<Interpolation, InterpolatorFactory<T, RandomAccessible<T>>>
realTypeInterpolation()
{
	return i -> i.equals(Interpolation.NLINEAR)
	            ? new NLinearInterpolatorFactory<>()
	            : new NearestNeighborInterpolatorFactory<>();
}
 
Example #8
Source File: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param meta
 * @param transform
 * @param dataExtension
 * @param extension
 * @param name
 * @param priority
 * @param channelDimension
 * @param channels
 * @throws IOException
 * @throws DataTypeNotSupported
 */
private N5ChannelDataSource(
		final N5Meta meta,
		final AffineTransform3D transform,
		final D dataExtension,
		final T extension,
		final String name,
		final SharedQueue queue,
		final int priority,
		final int channelDimension,
		final long[] channels) throws
		IOException, DataTypeNotSupported {

	final ImagesWithTransform<D, T>[] data = getData(
			meta.reader(),
			meta.dataset(),
			transform,
			queue,
			priority);
	final RandomAccessibleIntervalDataSource.DataWithInvalidate<D, T> dataWithInvalidate = RandomAccessibleIntervalDataSource.asDataWithInvalidate(data);
	this.meta = meta;
	this.channelDimension = channelDimension;
	this.name = name;
	this.transforms = dataWithInvalidate.transforms;
	this.invalidate = dataWithInvalidate.invalidate;

	this.channels = channels == null ? range((int) dataWithInvalidate.data[0].dimension(channelDimension)) : channels;
	this.numChannels = this.channels.length;

	this.intervals = dataWithInvalidate.data;
	extension.setValid(true);
	this.data = collapseDimension(dataWithInvalidate.data, this.channelDimension, this.channels, dataExtension);
	this.viewerData = collapseDimension(dataWithInvalidate.viewData, this.channelDimension, this.channels, extension);

	this.interpolation = ipol -> new NearestNeighborInterpolatorFactory<>();
	this.viewerInterpolation = ipol -> Interpolation.NLINEAR.equals(ipol) ? new NLinearInterpolatorFactory<>() : new NearestNeighborInterpolatorFactory<>();

	LOG.debug("Channel dimension {} has {} channels", channelDimension, numChannels);
}
 
Example #9
Source File: WeightedAverageFusion.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public < T extends RealType< T > > InterpolatorFactory< T, RandomAccessible< T > > getInterpolatorFactory( final T type )
{
	if ( getInterpolation() == 0 )
		return new NearestNeighborInterpolatorFactory<T>();
	else
		return new NLinearInterpolatorFactory< T >();
}
 
Example #10
Source File: LinearIntensityMap.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static private < T extends RealType< T > >InterpolatorFactory< RealComposite< T >, RandomAccessible< RealComposite< T > > > interpolatorFactory( final Interpolation interpolation )
{
	switch ( interpolation )
	{
	case NN:
		return new NearestNeighborInterpolatorFactory< RealComposite< T > >();
	default:
		return new NLinearInterpolatorFactory< RealComposite< T > >();
	}
}
 
Example #11
Source File: Interpolations.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public InterpolatorFactory<T, RandomAccessible<T>> apply(final Interpolation t)
{
	return new NearestNeighborInterpolatorFactory<>();
}
 
Example #12
Source File: MaskedSource.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T> RealRandomAccessible<T> interpolateNearestNeighbor(final RandomAccessible<T> ra)
{
	return Views.interpolate(ra, new NearestNeighborInterpolatorFactory<>());
}
 
Example #13
Source File: LabelSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public static <D extends IntegerType<D> & NativeType<D>, T extends Volatile<D> & IntegerType<T>>
LabelSourceState<D, T> simpleSourceFromSingleRAI(
		final RandomAccessibleInterval<D> data,
		final double[] resolution,
		final double[] offset,
		final Invalidate<Long> invalidate,
		final long maxId,
		final String name,
		final LabelBlockLookup labelBlockLookup,
		final Group meshesGroup,
		final ObjectProperty<ViewFrustum> viewFrustumProperty,
		final ObjectProperty<AffineTransform3D> eyeToWorldTransformProperty,
		final ExecutorService meshManagerExecutors,
		final HashPriorityQueueBasedTaskExecutor<MeshWorkerPriority> meshWorkersExecutors) {

	if (!Views.isZeroMin(data))
	{
		return simpleSourceFromSingleRAI(
				Views.zeroMin(data),
				resolution,
				offset,
				invalidate,
				maxId,
				name,
				labelBlockLookup,
				meshesGroup,
				viewFrustumProperty,
				eyeToWorldTransformProperty,
				meshManagerExecutors,
				meshWorkersExecutors
			);
	}

	final AffineTransform3D mipmapTransform = new AffineTransform3D();
	mipmapTransform.set(
			resolution[0], 0, 0, offset[0],
			0, resolution[1], 0, offset[1],
			0, 0, resolution[2], offset[2]
	                   );

	final T vt = (T) VolatileTypeMatcher.getVolatileTypeForType(Util.getTypeFromInterval(data)).createVariable();
	vt.setValid(true);
	final RandomAccessibleInterval<T> vdata = Converters.convert(data, (s, t) -> t.get().set(s), vt);

	final RandomAccessibleIntervalDataSource<D, T> dataSource = new RandomAccessibleIntervalDataSource<>(
			data,
			vdata,
			mipmapTransform,
			invalidate,
			i -> new NearestNeighborInterpolatorFactory<>(),
			i -> new NearestNeighborInterpolatorFactory<>(),
			name);

	final SelectedIds                        selectedIds    = new SelectedIds();
	final FragmentSegmentAssignmentOnlyLocal assignment     = new FragmentSegmentAssignmentOnlyLocal(new FragmentSegmentAssignmentOnlyLocal.DoesNotPersist());
	final SelectedSegments selectedSegments = new SelectedSegments(selectedIds, assignment);
	final LockedSegmentsOnlyLocal            lockedSegments = new LockedSegmentsOnlyLocal(seg -> {});
	final ModalGoldenAngleSaturatedHighlightingARGBStream stream = new
			ModalGoldenAngleSaturatedHighlightingARGBStream(
			selectedSegments,
			lockedSegments);

	final MeshManagerWithAssignmentForSegments meshManager = MeshManagerWithAssignmentForSegments.fromBlockLookup(
			dataSource,
			selectedSegments,
			stream,
			viewFrustumProperty,
			eyeToWorldTransformProperty,
			labelBlockLookup,
			meshManagerExecutors,
			meshWorkersExecutors);

	return new LabelSourceState<>(
			dataSource,
			new HighlightingStreamConverterIntegerType<>(stream),
			new ARGBCompositeAlphaYCbCr(),
			name,
			assignment,
			lockedSegments,
			new LocalIdService(maxId),
			selectedIds,
			meshManager,
			labelBlockLookup
	);
}
 
Example #14
Source File: RawSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public static <D extends RealType<D> & NativeType<D>, T extends AbstractVolatileNativeRealType<D, T>>
RawSourceState<D, T> simpleSourceFromSingleRAI(
		final RandomAccessibleInterval<D> data,
		final double[] resolution,
		final double[] offset,
		final Invalidate<Long> invalidate,
		final double min,
		final double max,
		final String name) {

	if (!Views.isZeroMin(data))
	{
		return simpleSourceFromSingleRAI(Views.zeroMin(data), resolution, offset, invalidate, min, max, name);
	}

	final AffineTransform3D mipmapTransform = new AffineTransform3D();
	mipmapTransform.set(
			resolution[0], 0, 0, offset[0],
			0, resolution[1], 0, offset[1],
			0, 0, resolution[2], offset[2]
	                   );

	@SuppressWarnings("unchecked") final T vt = (T) VolatileTypeMatcher.getVolatileTypeForType(Util
			.getTypeFromInterval(
			data)).createVariable();
	vt.setValid(true);
	final RandomAccessibleInterval<T> vdata = Converters.convert(data, (s, t) -> t.get().set(s), vt);

	final RandomAccessibleIntervalDataSource<D, T> dataSource = new RandomAccessibleIntervalDataSource<>(
			data,
			vdata,
			mipmapTransform,
			invalidate,
			i -> new NearestNeighborInterpolatorFactory<>(),
			i -> new NearestNeighborInterpolatorFactory<>(),
			name
	);

	return new RawSourceState<>(
			dataSource,
			new ARGBColorConverter.InvertingImp0<>(min, max),
			new CompositeCopy<>(),
			name
	);

}
 
Example #15
Source File: Stitching_Pairwise.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
protected static < T extends RealType< T > & NativeType< T > > ImagePlus fuse( final T targetType, final ImagePlus imp1, final ImagePlus imp2, final ArrayList<InvertibleBoundable> models, final StitchingParameters params )
{
	final ArrayList<ImagePlus> images = new ArrayList< ImagePlus >();
	images.add( imp1 );
	images.add( imp2 );
	
	if ( params.fusionMethod < 6 )
	{
		ImagePlus imp = Fusion.fuse( targetType, images, models, params.dimensionality, params.subpixelAccuracy, params.fusionMethod, null, false, params.ignoreZeroValuesFusion, params.displayFusion );
		return imp;
	}
	else if ( params.fusionMethod == 6 ) // overlay
	{
		// images are always the same, we just trigger different timepoints
		final InterpolatorFactory< FloatType, RandomAccessible< FloatType > > factory;
		
		if ( params.subpixelAccuracy )
			factory  = new NLinearInterpolatorFactory<FloatType>();
		else
			factory  = new NearestNeighborInterpolatorFactory< FloatType >();
	
		// fuses the first timepoint but estimates the boundaries for all timepoints as it gets all models
		final CompositeImage timepoint0 = OverlayFusion.createOverlay( targetType, images, models, params.dimensionality, 1, factory );
		
		if ( imp1.getNFrames() > 1 )
		{
			final ImageStack stack = new ImageStack( timepoint0.getWidth(), timepoint0.getHeight() );
			
			// add all slices of the first timepoint
			for ( int c = 1; c <= timepoint0.getStackSize(); ++c )
				stack.addSlice( "", timepoint0.getStack().getProcessor( c ) );
			
			//"Overlay into composite image"
			for ( int f = 2; f <= imp1.getNFrames(); ++f )
			{
				final CompositeImage tmp = OverlayFusion.createOverlay( targetType, images, models, params.dimensionality, f, factory );
				
				// add all slices of the first timepoint
				for ( int c = 1; c <= tmp.getStackSize(); ++c )
					stack.addSlice( "", tmp.getStack().getProcessor( c ) );					
			}
			
			//convertXYZCT ...
			ImagePlus result = new ImagePlus( params.fusedName, stack );
			
			// numchannels, z-slices, timepoints (but right now the order is still XYZCT)
			result.setDimensions( timepoint0.getNChannels(), timepoint0.getNSlices(), imp1.getNFrames() );
			return CompositeImageFixer.makeComposite( result, CompositeImage.COMPOSITE );
		}
		else
		{
			timepoint0.setTitle( params.fusedName );
			return timepoint0;
		}
	}
	else
	{
		//"Do not fuse images"
		return null;
	}
}
 
Example #16
Source File: MinFilterThreshold.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public boolean run()
{
	// fuse the dataset
	final ProcessFusion process;

	if ( loadSequentially )
		process = new ProcessSequential( spimData, viewIdsToProcess, bb, false, false, 1 );
	else
		process = new ProcessParalell( spimData, viewIdsToProcess, bb, false, false );

	Img< FloatType > img = process.fuseStack( new FloatType(), new NearestNeighborInterpolatorFactory<FloatType>(), timepoint, channel );

	final float[] minmax = FusionHelper.minMax( img );
	final int effR = Math.max( radiusMin / bb.getDownSampling(), 1 );
	final double threshold = (minmax[ 1 ] - minmax[ 0 ]) * ( background / 100.0 ) + minmax[ 0 ];

	IOFunctions.println( "Fused image minimum: " + minmax[ 0 ] );
	IOFunctions.println( "Fused image maximum: " + minmax[ 1 ] );
	IOFunctions.println( "Threshold: " + threshold );

	IOFunctions.println( "Computing minimum filter with effective radius of " + effR + " (downsampling=" + bb.getDownSampling() + ")" );

	img = computeLazyMinFilter( img, effR );

	if ( displaySegmentationImage )
		ImageJFunctions.show( img );

	this.min = new int[ img.numDimensions() ];
	this.max = new int[ img.numDimensions() ];

	if ( !computeBoundingBox( img, threshold, min, max ) )
		return false;

	IOFunctions.println( "Bounding box dim scaled: [" + Util.printCoordinates( min ) + "] >> [" + Util.printCoordinates( max ) + "]" );

	// adjust bounding box for downsampling and global coordinates
	for ( int d = 0; d < img.numDimensions(); ++d )
	{
		// downsampling
		min[ d ] *= bb.getDownSampling();
		max[ d ] *= bb.getDownSampling();
		
		// global coordinates
		min[ d ] += bb.min( d );
		max[ d ] += bb.min( d );
		
		// effect of the min filter + extra space
		min[ d ] -= radiusMin * 3;
		max[ d ] += radiusMin * 3;
	}
	
	IOFunctions.println( "Bounding box dim global: [" + Util.printCoordinates( min ) + "] >> [" + Util.printCoordinates( max ) + "]" );
	
	return true;
}