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

The following examples show how to use net.imglib2.view.Views#zeroMin() . 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: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static <I extends IntegerType<I> & NativeType<I>> BlockDiff downsampleIntegerTypeAndSerialize(
		final N5Writer n5,
		final String dataset,
		final DatasetAttributes attributes,
		final RandomAccessibleInterval<I> data,
		final int[] relativeFactors,
		final int[] size,
		final Interval blockInterval,
		final long[] blockPosition
) throws IOException {
	final I i = Util.getTypeFromInterval(data).createVariable();
	i.setInteger(Label.OUTSIDE);
	final RandomAccessibleInterval<I> input = Views.isZeroMin(data) ? data : Views.zeroMin(data);
	final RandomAccessibleInterval<I> output = new ArrayImgFactory<>(i).create(size);
	WinnerTakesAll.downsample(input, output, relativeFactors);

	final RandomAccessibleInterval<I> previousContents = Views.offsetInterval(N5Utils.<I>open(n5, dataset), blockInterval);
	final BlockDiff blockDiff = createBlockDiffInteger(previousContents, output);

	N5Utils.saveBlock(output, n5, dataset, attributes, blockPosition);
	return blockDiff;
}
 
Example 2
Source File: LocalThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Add 0s before axis minimum.
 * 
 * @param input Input RAI
 * @return An extended and cropped version of input
 */
private <T extends RealType<T>> RandomAccessibleInterval<T> addLeadingZeros(
	RandomAccessibleInterval<T> input)
{
	final long[] min = Intervals.minAsLongArray(input);
	final long[] max = Intervals.maxAsLongArray(input);

	for (int i = 0; i < max.length; i++) {
		min[i]--;
	}

	final T realZero = Util.getTypeFromInterval(input).copy();
	realZero.setZero();

	final ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extendedImg = Views.extendValue(input,
		realZero);
	final IntervalView<T> offsetInterval = Views.interval(extendedImg,
		min, max);
	
	return Views.zeroMin(offsetInterval);
}
 
Example 3
Source File: FractalImgLoader.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public RandomAccessibleInterval< LongType > getImageAtInterval(Interval interval){
	return  Views.zeroMin( Views.interval( fractalsRA, interval) );
	/*
	// we want a Img here, so that we can downsaple later
	Img<LongType> resImg = new ArrayImgFactory<LongType>().create( raiT, new LongType() );
	
	ops.copy().rai( resImg, raiT );
	//ImgLib2Util.copyRealImage(raiT, resImg) ;
	return resImg;*/
}
 
Example 4
Source File: ZeroMinViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void defaultZeroMinTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	IntervalView<DoubleType> imgTranslated = Views.interval(
			Views.translate((RandomAccessible<DoubleType>) img, 2, 5), new long[] { 2, 5 }, new long[] { 12, 15 });

	IntervalView<DoubleType> il2 = Views.zeroMin(imgTranslated);
	IntervalView<DoubleType> opr = ops.transform().zeroMinView(imgTranslated);

	assertTrue(Views.isZeroMin(il2) == Views.isZeroMin(opr));
}
 
Example 5
Source File: RigidWarp.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args)
{
	RandomAccessibleInterval< FloatType > a = ImgLib2Util.openAs32Bit( new File( "73.tif.zip" ) );
	RandomAccessibleInterval< FloatType > b = ImgLib2Util.openAs32Bit( new File( "74.tif.zip" ) );
	
	long slice = 40;
	ImageJFunctions.show( a );
	
	a = Views.zeroMin( Views.hyperSlice( a, 2, slice ));
	b = Views.zeroMin( Views.hyperSlice( b, 2, slice ));

	TranslationGet t1 = new Translation2D();
	TranslationGet t2 = new Translation2D(460, 0);
	ArrayList< Pair< RealInterval, AffineGet > > views = new ArrayList<Pair<RealInterval, AffineGet>>();
	views.add( new ValuePair< RealInterval, AffineGet >( a, t1 ) );
	views.add( new ValuePair< RealInterval, AffineGet >( b, t2 ) );

	RealInterval overlap = BoundingBoxMaximalGroupOverlap.getMinBoundingIntervalSingle( views );

	final RealInterval transformed1 = TransformTools.applyTranslation( a, t1, new boolean[] {false, false} );
	final RealInterval transformed2 = TransformTools.applyTranslation( b, t2, new boolean[] {false, false} );

	// get overlap in images' coordinates
	final RealInterval localOverlap1 = TransformTools.getLocalOverlap( transformed1, overlap );
	final RealInterval localOverlap2 = TransformTools.getLocalOverlap( transformed2, overlap );

	// round to integer interval
	final Interval interval1 = TransformTools.getLocalRasterOverlap( localOverlap1 );
	final Interval interval2 = TransformTools.getLocalRasterOverlap( localOverlap2 );

	//final WarpFunction warp = new TranslationWarp(3);
	final WarpFunction warp = new RigidWarp(2);
	//final WarpFunction warp = new AffineWarp( 3 );

	// rotate second image
	AffineTransform2D rot = new AffineTransform2D();
	rot.rotate( 1.4 * Math.PI / 180 );
	RandomAccessibleInterval< FloatType > rotated = Views.interval(
			RealViews.affine( 
					Views.interpolate( Views.extendMirrorSingle( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ),
					rot.copy() ),
			interval2);

	// show input
	new ImageJ();
	ImageJFunctions.show( Views.interval( a,  interval1 ) );
	ImageJFunctions.show( rotated );

	// downsample input
	RandomAccessibleInterval< FloatType > simple2x1 = Downsample.simple2x( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), new boolean[] {false, false} );
	RandomAccessibleInterval< FloatType > simple2x2 = Downsample.simple2x( Views.zeroMin( Views.interval( rotated, interval2 ) ), new ArrayImgFactory<>(), new boolean[] {false, false} );

	// align

	//Align< FloatType > lk = new Align<>( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), warp );
	Align< FloatType > lk = new Align<>( simple2x1, new ArrayImgFactory<>(), warp );
	//System.out.println( Util.printCoordinates( lk.align( Views.zeroMin( Views.interval( b, interval2 ) ), 100, 0.01 ).getRowPackedCopy() ) );
	//final AffineTransform transform = lk.align( Views.zeroMin( rotated ), 100, 0.01 );
	final AffineTransform transform = lk.align( simple2x2, 100, 0.1 );

	// transformation matrix
	System.out.println( Util.printCoordinates( transform.getRowPackedCopy() ) );

	// correct input and show
	RandomAccessibleInterval< FloatType > backRotated = Views.interval(
			RealViews.affine( 
					Views.interpolate( Views.extendMirrorSingle( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ),
					rot.copy().preConcatenate( transform ).copy() ),
			interval2);

	ImageJFunctions.show( backRotated );

	// constructor needs column packed matrix, therefore the transpose
	Matrix mt = new Matrix( transform.getRowPackedCopy(), 3).transpose();
	Matrix rigid = mt.getMatrix( 0, 1, 0, 1 );

	// check whether result is rotation matrix (det == +-1, orthogonal)
	System.out.println( rigid.det() );
	System.out.println( Util.printCoordinates( rigid.times( rigid.transpose() ).getRowPackedCopy() ) );
}
 
Example 6
Source File: DefaultZeroMinView.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public IntervalView<T> calculate(RandomAccessibleInterval<T> input) {
	return Views.zeroMin(input);
}
 
Example 7
Source File: DeconvolveTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testDeconvolve() {
	int[] size = new int[] { 225, 167 };

	// create an input with a small sphere at the center
	Img<FloatType> in = new ArrayImgFactory<FloatType>().create(size,
		new FloatType());
	placeSphereInCenter(in);

	// crop the image so the sphere is truncated at the corner
	// (this is useful for testing non-circulant mode)
	IntervalView<FloatType> incropped = Views.interval(in, new long[] {
		size[0] / 2, size[1] / 2 }, new long[] { size[0] - 1, size[1] - 1 });

	incropped = Views.zeroMin(incropped);

	RandomAccessibleInterval<FloatType> kernel = ops.create().kernelGauss(
		new double[] { 4.0, 4.0 }, new FloatType());

	RandomAccessibleInterval<FloatType> convolved = ops.create().img(incropped,
		new FloatType());
	RandomAccessibleInterval<FloatType> deconvolved = ops.create().img(
		incropped, new FloatType());
	RandomAccessibleInterval<FloatType> deconvolved2 = ops.create().img(
		incropped, new FloatType());

	// convolve
	convolved = (Img<FloatType>) ops.run(PadAndConvolveFFT.class, convolved,
		incropped, kernel);

	// deconvolve with standard Richardson Lucy
	deconvolved = (RandomAccessibleInterval<FloatType>) ops.run(
		PadAndRichardsonLucy.class, deconvolved, convolved, kernel, null,
		new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(in)
			.createVariable()), 10);

	// deconvolve with accelerated non-circulant Richardson Lucy
	deconvolved2 = (RandomAccessibleInterval<FloatType>) ops.run(
		PadAndRichardsonLucy.class, deconvolved2, convolved, kernel, null,
		new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(in)
			.createVariable()), null, null, null, 10, true, true);

	assertEquals(incropped.dimension(0), deconvolved.dimension(0));
	assertEquals(incropped.dimension(1), deconvolved.dimension(1));

	assertEquals(incropped.dimension(0), deconvolved2.dimension(0));
	assertEquals(incropped.dimension(1), deconvolved2.dimension(1));

	final Cursor<FloatType> deconvolvedCursor = Views.iterable(deconvolved)
		.cursor();

	final Cursor<FloatType> deconvolvedCursor2 = Views.iterable(deconvolved2)
		.cursor();

	float[] deconvolvedValues = { 3.6045982E-4f, 0.0016963598f, 0.0053468645f,
		0.011868152f, 0.019616995f, 0.025637051f, 0.028158935f, 0.027555753f,
		0.025289025f, 0.02266813f, 0.020409783f, 0.018752098f, 0.017683199f,
		0.016951872f, 0.016685976f };

	float[] deconvolvedValues2 = { 0.2630342f, 0.3163991f, 0.37503138f,
		0.43603566f, 0.49504462f, 0.54681045f, 0.5863713f, 0.6105026f, 0.6186579f,
		0.6129602f, 0.5972553f, 0.57583135f, 0.55244136f, 0.53075385f, 0.5109135f };

	for (int i = 0; i < deconvolvedValues.length; i++) {
		assertEquals(deconvolvedValues[i], deconvolvedCursor.next().get(), 0.0f);
		assertEquals(deconvolvedValues2[i], deconvolvedCursor2.next().get(),
			0.0f);
	}
}