net.imglib2.Localizable Java Examples

The following examples show how to use net.imglib2.Localizable. 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: 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 #2
Source File: FloodFill.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static void fillMultisetType(
		final RandomAccessibleInterval<LabelMultisetType> input,
		final RandomAccessible<UnsignedLongType> output,
		final Localizable seed,
		final long seedLabel,
		final FragmentSegmentAssignment assignment)
{
	net.imglib2.algorithm.fill.FloodFill.fill(
			Views.extendValue(input, new LabelMultisetType()),
			output,
			seed,
			new UnsignedLongType(1),
			new DiamondShape(1),
			makePredicate(seedLabel, assignment)
		);
}
 
Example #3
Source File: FloodFill.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static <T extends IntegerType<T>> void fillPrimitiveType(
		final RandomAccessibleInterval<T> input,
		final RandomAccessible<UnsignedLongType> output,
		final Localizable seed,
		final long seedLabel,
		final FragmentSegmentAssignment assignment)
{
	final T extension = Util.getTypeFromInterval(input).createVariable();
	extension.setInteger(Label.OUTSIDE);

	net.imglib2.algorithm.fill.FloodFill.fill(
			Views.extendValue(input, extension),
			output,
			seed,
			new UnsignedLongType(1),
			new DiamondShape(1),
			makePredicate(seedLabel, assignment)
		);
}
 
Example #4
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 #5
Source File: AbstractOutOfBoundsValue.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setPosition(final Localizable localizable)
{
	for (int d = 0; d < n; ++d)
	{
		setPosition(localizable.getLongPosition(d), d);
	}
}
 
Example #6
Source File: ShuffledView.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static <T> RandomAccessibleInterval<T> cropAt(
	final RandomAccessibleInterval<T> image, final int[] blockSize,
	final Localizable offset)
{
	final int numDims = image.numDimensions();
	final long[] minsize = new long[numDims * 2];
	for (int d = 0; d < numDims; d++) {
		minsize[d] = offset.getLongPosition(d);
		final long shaveSize = image.dimension(d) % blockSize[d];
		minsize[numDims + d] = image.dimension(d) - shaveSize;
	}
	return Views.interval(image, FinalInterval.createMinSize(minsize));
}
 
Example #7
Source File: DefaultFillHoles.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
	createFunc = RAIs.function(ops(), CreateImgFromDimsAndType.class, in(), new BitType());
	floodFillComp = (BinaryComputerOp) Computers.binary(ops(),
		Ops.Morphology.FloodFill.class, RandomAccessibleInterval.class, in(),
		Localizable.class, structElement);
}
 
Example #8
Source File: DefaultFloodFill.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(RandomAccessibleInterval<T> op0, Localizable loc,
	RandomAccessibleInterval<T> r)
{
	final RandomAccess<T> op0c = op0.randomAccess();
	op0c.setPosition(loc);
	final T fillValue = op0c.get().copy();
	FloodFill.fill(Views.extendValue(op0, fillValue), Views.extendValue(r, fillValue), loc, fillValue, structElement, new Filter<Pair<T,T >, Pair<T,T>>() {

		@Override
		public boolean accept(Pair<T, T> t, Pair<T, T> u) {
			return !t.getB().valueEquals(u.getB()) && t.getA().valueEquals(u.getA());
		}
	});
}
 
Example #9
Source File: MorphologyNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.morphology.floodFill.DefaultFloodFill.class)
public <T extends Type<T> & Comparable<T>> RandomAccessibleInterval<T>
	floodFill(final RandomAccessibleInterval<T> in1, final Localizable in2,
		final Shape structElement)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(
			net.imagej.ops.morphology.floodFill.DefaultFloodFill.class, in1, in2,
			structElement);
	return result;
}
 
Example #10
Source File: MorphologyNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.morphology.floodFill.DefaultFloodFill.class)
public <T extends Type<T> & Comparable<T>> RandomAccessibleInterval<T>
	floodFill(final RandomAccessibleInterval<T> out,
		final RandomAccessibleInterval<T> in, final Localizable startPos,
		final Shape structElement)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(
			net.imagej.ops.morphology.floodFill.DefaultFloodFill.class, out, in, startPos,
			structElement);
	return result;
}
 
Example #11
Source File: PhaseCorrelationPeak2.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public PhaseCorrelationPeak2(Localizable pcmPosition, double phaseCorr)
{
	this.pcmLocation = new Point( pcmPosition );
	this.shift = null;
	this.subpixelPcmLocation = null;
	this.subpixelShift = null;
	this.phaseCorr = phaseCorr;
	this.crossCorr = 0.0;
	this.nPixel = 0;
}
 
Example #12
Source File: Vector4.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
default void setPosition(Localizable localizable) {
    setX( localizable.getDoublePosition( 0 ) );
    setY( localizable.getDoublePosition( 1 ) );
    setZ( localizable.getDoublePosition( 2 ) );
    setW( localizable.getDoublePosition( 3 ) );
}
 
Example #13
Source File: Vector4.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
default void move(Localizable distance) {
    moveX( distance.getDoublePosition( 0 ) );
    moveY( distance.getDoublePosition( 1 ) );
    moveZ( distance.getDoublePosition( 2 ) );
    moveW( distance.getDoublePosition( 3 ) );
}
 
Example #14
Source File: AbstractOutOfBoundsValue.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void move(final Localizable localizable)
{
	for (int d = 0; d < n; ++d)
	{
		move(localizable.getLongPosition(d), d);
	}
}
 
Example #15
Source File: RealRandomAccessibleTriple.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setPosition(final Localizable localizable)
{
	a.setPosition(localizable);
	b.setPosition(localizable);
	c.setPosition(localizable);
}
 
Example #16
Source File: RandomAccessibleTriple.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setPosition(final Localizable localizable)
{
	a.setPosition(localizable);
	b.setPosition(localizable);
	c.setPosition(localizable);
}
 
Example #17
Source File: RandomAccessibleTriple.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void move(final Localizable localizable)
{
	a.move(localizable);
	b.move(localizable);
	c.move(localizable);
}
 
Example #18
Source File: RealRandomAccessibleTriple.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void move(final Localizable localizable)
{
	a.move(localizable);
	b.move(localizable);
	c.move(localizable);
}
 
Example #19
Source File: PhaseCorrelationPeak2.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public Localizable getShift() {
	return shift;
}
 
Example #20
Source File: PhaseCorrelationPeak2.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public Localizable getPcmLocation() {
	return pcmLocation;
}
 
Example #21
Source File: PhaseCorrelationPeak2.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public void setShift(Localizable shift) {
	this.shift = shift;
}
 
Example #22
Source File: FourNeighborhoodExtremaTest.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testRandomPeaksMT()
{
	Img< FloatType > img = ArrayImgs.floats( 50, 50 );
	Random rnd = new Random( seed );
	
	for( FloatType t : img )
		t.set( rnd.nextFloat() );
	
	ArrayList< Pair< Localizable, Double > > correct = new ArrayList< Pair<Localizable,Double> >(); 
	
	RandomAccess<FloatType> ra = img.randomAccess();
	
	for ( int i = 0; i < 10; ++i ){
		for (int d = 0; d< img.numDimensions(); d++){
			ra.setPosition((int) (rnd.nextDouble() * 50), d);
		}
		ra.get().set((float) (rnd.nextDouble() + 1.0));
		
		correct.add(new ValuePair<Localizable, Double>(new Point(ra), new Double(ra.get().get())));
	}
	
	// sort the peaks in descending order
	Collections.sort(correct, new Comparator<Pair< Localizable, Double >>() {
		@Override
		public int compare(Pair<Localizable, Double> o1, Pair<Localizable, Double> o2) {
			return Double.compare(o2.getB(), o1.getB());
		}
	});
	
	int nMax = 5;
	ArrayList< Pair< Localizable, Double > > found = FourNeighborhoodExtrema.findMaxMT(Views.extendPeriodic(img), img, nMax, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
	assertEquals(nMax, found.size());
	
	
	long[] posCorrect = new long[img.numDimensions()];
	long[] posFound = new long[img.numDimensions()];
	
	for (int i = 0; i<found.size(); i++){			
		assertEquals(correct.get(i).getB(), found.get(i).getB());
		
		correct.get(i).getA().localize(posCorrect);
		found.get(i).getA().localize(posFound);			
		assertArrayEquals(posCorrect, posFound);
	}
}
 
Example #23
Source File: PermuteCoordinateAxesTransform.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void applyInverse(Positionable source, Localizable target) {
	for (int i = 0; i < lookup.length; ++i)
		source.setPosition(target.getLongPosition(inverseLookup[i]), i);
}
 
Example #24
Source File: PermuteCoordinateAxesTransform.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void apply(Localizable source, Positionable target) {
	for (int i = 0; i < lookup.length; ++i)
		target.setPosition(source.getLongPosition(lookup[i]), i);
}
 
Example #25
Source File: DefaultFloodFill.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public RandomAccessibleInterval<T> createOutput(
	RandomAccessibleInterval<T> input1, Localizable input2)
{
	return createFunc.calculate(input1);
}
 
Example #26
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T, U> void restrictTo(
		final RandomAccessible<Pair<T, U>> source,
		final RandomAccessible<UnsignedLongType> mask,
		final Localizable seed,
		final Shape shape,
		final Predicate<T> backgroundFilter,
		final Predicate<U> canvasFilter)
{
	final int n = source.numDimensions();

	final RandomAccessible<Pair<Pair<T, U>, UnsignedLongType>> paired = Views.pair(source, mask);

	final TLongList[] coordinates = new TLongList[n];
	for (int d = 0; d < n; ++d)
	{
		coordinates[d] = new TLongArrayList();
		coordinates[d].add(seed.getLongPosition(d));
	}

	final RandomAccessible<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>> neighborhood       = shape
			.neighborhoodsRandomAccessible(
			paired);
	final RandomAccess<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>>     neighborhoodAccess = neighborhood
			.randomAccess();

	final RandomAccess<UnsignedLongType> targetAccess = mask.randomAccess();
	targetAccess.setPosition(seed);
	targetAccess.get().set(1);

	final UnsignedLongType zero = new UnsignedLongType(0);
	final UnsignedLongType one  = new UnsignedLongType(1);
	final UnsignedLongType two  = new UnsignedLongType(2);

	for (int i = 0; i < coordinates[0].size(); ++i)
	{
		for (int d = 0; d < n; ++d)
		{
			neighborhoodAccess.setPosition(coordinates[d].get(i), d);
		}

		final Cursor<Pair<Pair<T, U>, UnsignedLongType>> neighborhoodCursor = neighborhoodAccess.get().cursor();

		while (neighborhoodCursor.hasNext())
		{
			final Pair<Pair<T, U>, UnsignedLongType> p                   = neighborhoodCursor.next();
			final UnsignedLongType                   m                   = p.getB();
			final Pair<T, U>                         backgroundAndCanvas = p.getA();
			if (m.valueEquals(zero) && canvasFilter.test(backgroundAndCanvas.getB()))
			{
				// If background is same as at seed, mark mask with two
				// (==not active), else with one (==active).
				m.set(backgroundFilter.test(backgroundAndCanvas.getA()) ? two : one);
				for (int d = 0; d < n; ++d)
				{
					coordinates[d].add(neighborhoodCursor.getLongPosition(d));
				}
			}

		}

		if (i > CLEANUP_THRESHOLD)
		{
			for (int d = 0; d < coordinates.length; ++d)
			{
				final TLongList c = coordinates[d];
				coordinates[d] = c.subList(i, c.size());
			}
			i = 0;
		}

	}
}
 
Example #27
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static void restrictToLabelMultisetType(
		final MaskedSource<LabelMultisetType, ?> source,
		final int time,
		final int level,
		final Localizable seed,
		final Runnable requestRepaint) throws MaskInUse
{
	final RandomAccessibleInterval<UnsignedLongType>  canvas        = source.getReadOnlyDataCanvas(time, level);
	final RandomAccessibleInterval<LabelMultisetType> background    = source.getReadOnlyDataBackground(time,
			level);
	final MaskInfo<UnsignedLongType>                  maskInfo      = new MaskInfo<>(
			time,
			level,
			new UnsignedLongType(Label.TRANSPARENT)
	);
	final Mask<UnsignedLongType> mask = source.generateMask(maskInfo, FOREGROUND_CHECK);
	final AccessBoxRandomAccessible<UnsignedLongType> accessTracker = new AccessBoxRandomAccessible<>(Views
			.extendValue(mask.mask, new UnsignedLongType(1)));

	final RandomAccess<UnsignedLongType> canvasAccess = canvas.randomAccess();
	canvasAccess.setPosition(seed);
	final UnsignedLongType                paintedLabel     = canvasAccess.get();
	final RandomAccess<LabelMultisetType> backgroundAccess = background.randomAccess();
	backgroundAccess.setPosition(seed);
	final LabelMultisetType backgroundSeed      = backgroundAccess.get();
	final long              backgroundSeedLabel = backgroundSeed.entrySet().stream().max((e1, e2) -> Long.compare(
			e1.getCount(),
			e2.getCount()
	                                                                                                             )
	                                                                                    ).map(
			e -> e.getElement().id()).orElse(Label.INVALID);

	final RandomAccessible<Pair<LabelMultisetType, UnsignedLongType>> paired = Views.pair(
			Views.extendValue(
					background,
					new LabelMultisetType()
			                 ),
			Views.extendValue(canvas, new UnsignedLongType(Label.INVALID))
	                                                                                     );

	restrictTo(
			paired,
			accessTracker,
			seed,
			new DiamondShape(1),
			bg -> bg.contains(backgroundSeedLabel),
			cv -> cv.valueEquals(paintedLabel)
	          );

	requestRepaint.run();

	source.applyMask(mask, accessTracker.createAccessInterval(), FOREGROUND_CHECK);

}
 
Example #28
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T extends RealType<T>> void restrictTo(
		final MaskedSource<T, ?> source,
		final int time,
		final int level,
		final Localizable seed,
		final Runnable requestRepaint) throws MaskInUse
{
	final RandomAccessibleInterval<UnsignedLongType>  canvas        = source.getReadOnlyDataCanvas(time, level);
	final RandomAccessibleInterval<T>                 background    = source.getReadOnlyDataBackground(time,
			level);
	final MaskInfo<UnsignedLongType>                  maskInfo      = new MaskInfo<>(
			time,
			level,
			new UnsignedLongType(Label.TRANSPARENT)
	);
	final Mask<UnsignedLongType> mask = source.generateMask(maskInfo, FOREGROUND_CHECK);
	final AccessBoxRandomAccessible<UnsignedLongType> accessTracker = new AccessBoxRandomAccessible<>(Views
			.extendValue(mask.mask, new UnsignedLongType(1)));

	final RandomAccess<UnsignedLongType> canvasAccess = canvas.randomAccess();
	canvasAccess.setPosition(seed);
	final UnsignedLongType paintedLabel     = canvasAccess.get();
	final RandomAccess<T>  backgroundAccess = background.randomAccess();
	backgroundAccess.setPosition(seed);
	final T backgroundSeed = backgroundAccess.get();

	final RandomAccessible<Pair<T, UnsignedLongType>> paired = Views.pair(
			Views.extendBorder(background),
			Views.extendValue(canvas, new UnsignedLongType(Label.INVALID))
	                                                                     );

	restrictTo(
			paired,
			accessTracker,
			seed,
			new DiamondShape(1),
			bg -> bg.valueEquals(backgroundSeed),
			cv -> cv.valueEquals(paintedLabel)
	          );

	requestRepaint.run();

	source.applyMask(mask, accessTracker.createAccessInterval(), FOREGROUND_CHECK);

}
 
Example #29
Source File: BlendingRealRandomAccess.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void move( final Localizable localizable )
{
	for ( int d = 0; d < n; ++d )
		l[ d ] += localizable.getFloatPosition( d );
}
 
Example #30
Source File: BlendingRealRandomAccess.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setPosition( final Localizable localizable )
{
	for ( int d = 0; d < n; ++d )
		l[ d ] = localizable.getFloatPosition( d );
}