Java Code Examples for net.imglib2.RandomAccessibleInterval#min()

The following examples show how to use net.imglib2.RandomAccessibleInterval#min() . 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: SlicesII.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @param source
 *            {@link RandomAccessibleInterval} which will be virtually
 *            cropped
 * @param axesOfInterest
 *            axes which define a plane, cube, hypercube, ...! All other
 *            axes will be iterated.
 * @param dropSingletonDimensions
 *            if true, dimensions of size one will be discarded in the
 *            sliced images
 */
public SlicesII(final RandomAccessibleInterval<T> source, final int[] axesOfInterest,
		final boolean dropSingletonDimensions) {
	super(initIntervals(source, axesOfInterest));

	final long[] sliceMin = new long[source.numDimensions()];
	final long[] sliceMax = new long[source.numDimensions()];

	for (int d = 0; d < source.numDimensions(); d++) {
		if (dimension(d) == 1) {
			sliceMin[d] = source.min(d);
			sliceMax[d] = source.max(d);
		}
	}

	this.dropSingltonDimensions = dropSingletonDimensions;
	this.slice = new FinalInterval(sliceMin, sliceMax);
	this.source = source;
}
 
Example 2
Source File: DefaultDoG.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<T> input,
	final RandomAccessibleInterval<T> output)
{
	// input may potentially be translated
	final long[] translation = new long[input.numDimensions()];
	input.min(translation);

	final IntervalView<T> tmpInterval = Views.interval(Views.translate(
		(RandomAccessible<T>) tmpCreator.calculate(input), translation), output);

	gauss1.compute(input, tmpInterval);
	gauss2.compute(input, output);

	// TODO: Match the Subtract Op in initialize() once we have BinaryOp
	ops().run(Ops.Math.Subtract.class, output, output, tmpInterval);
}
 
Example 3
Source File: IntegralImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @see DefaultIntegralImg
 * @see SquareIntegralImg
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testIntegralImageSimilarity() {
	RandomAccessibleInterval<LongType> out1 =
		(RandomAccessibleInterval<LongType>) ops.run(DefaultIntegralImg.class,
			in);
	RandomAccessibleInterval<DoubleType> out2 =
		(RandomAccessibleInterval<DoubleType>) ops.run(WrappedIntegralImg.class,
			in);

	// Remove 0s from integralImg by shifting its interval by +1
	final long[] min = new long[out2.numDimensions()];
	final long[] max = new long[out2.numDimensions()];

	for (int d = 0; d < out2.numDimensions(); ++d) {
		min[d] = out2.min(d) + 1;
		max[d] = out2.max(d);
	}

	// Define the Interval on the infinite random accessibles
	final FinalInterval interval = new FinalInterval(min, max);

	LocalThresholdTest.testIterableIntervalSimilarity(Views.iterable(out1),
		Views.iterable(Views.offsetInterval(out2, interval)));
}
 
Example 4
Source File: VolatileHierarchyProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public VolatileHierarchyProjectorPreMultiply(
		final List<? extends RandomAccessible<A>> sources,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final RandomAccessibleInterval<ByteType> mask,
		final int numThreads,
		final ExecutorService executorService)
{
	super(Math.max(2, sources.get(0).numDimensions()), converter, target);

	this.sources.addAll(sources);
	numInvalidLevels = sources.size();

	this.mask = mask;

	iterableTarget = Views.iterable(target);

	target.min(min);
	target.max(max);
	sourceInterval = new FinalInterval(min, max);

	width = (int) target.dimension(0);
	height = (int) target.dimension(1);
	cr = -width;

	this.numThreads = numThreads;
	this.executorService = executorService;

	lastFrameRenderNanoTime = -1;
	clearMask();
}
 
Example 5
Source File: VolatileHierarchyProjector.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public VolatileHierarchyProjector(
		final List< ? extends RandomAccessible< A > > sources,
		final Converter< ? super A, B > converter,
		final RandomAccessibleInterval< B > target,
		final RandomAccessibleInterval< ByteType > mask,
		final int numThreads,
		final ExecutorService executorService )
{
	super( Math.max( 2, sources.get( 0 ).numDimensions() ), converter, target );

	this.sources.addAll( sources );
	numInvalidLevels = sources.size();

	this.mask = mask;

	iterableTarget = Views.iterable( target );

	target.min(min);
	target.max(max);
	sourceInterval = new FinalInterval( min, max );

	width = ( int )target.dimension( 0 );
	height = ( int )target.dimension( 1 );
	cr = -width;

	this.numThreads = numThreads;
	this.executorService = executorService;

	lastFrameRenderNanoTime = -1;
	clearMask();
}
 
Example 6
Source File: N5IO.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public graphics.scenery.Node open( final N5Reader n5Reader, final String dataset ) throws IOException {
    Node node;
    String nodeType = getNodeType( n5Reader, dataset );

    // Fail if SciView is not open. We use the active sciview
    SciViewService sciViewService = context().service(SciViewService.class);
    if( sciViewService.numSciView() == 0 ) {
        throw new IOException("SciView is not open, needed for file opening.");
    }

    SciView sv = sciViewService.getActiveSciView();

    if( nodeType.startsWith("sciview") ) {
        node = openSciview( n5Reader, dataset, nodeType );
    } else {
        // TODO check for multiresolution and such here

        // Note: UnsignedByteType is currently hard coded due to BVV constraints
        RandomAccessibleInterval<UnsignedByteType> image = N5Utils.open(n5Reader, dataset);

        long[] dimensions = new long[image.numDimensions()];
        image.dimensions( dimensions );

        long[] minPt = new long[image.numDimensions()];

        // Get type at min point
        RandomAccess<UnsignedByteType> imageRA = image.randomAccess();
        image.min(minPt);
        imageRA.setPosition(minPt);

        node = Volume.fromRAI(image, new UnsignedByteType(), AxisOrder.DEFAULT, dataset, sv.getHub(), new VolumeViewerOptions());
    }

    return node;
}
 
Example 7
Source File: FastFusionTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
/**
 * apply blending to an image, save weights to separate image
 * @param image image to apply blending to
 * @param weightImage image to save weights to
 * @param renderOffset (subpixel) offset of the original image to the provided version
 * @param border blank pixels on each border
 * @param blending extent of blending on each border
 * @param multiplyWeights false: just set weightImage to new weights, true: multiply existing weightImage
 * @param pool thread pool
 * @param <T> image pixel data type
 * @param <R> weight image pixel data type
 */
public static <T extends RealType<T>, R extends RealType<R> > void applyWeights(
		final RandomAccessibleInterval< T > image,
		final RandomAccessibleInterval< R > weightImage,
		final float[] renderOffset,
		final float[] border, 
		final float[] blending,
		final boolean multiplyWeights,
		final ExecutorService pool)
{
	final int n = image.numDimensions();
	final int[] min = new int[n];
	final int[] dimMinus1 = new int[n];
	for (int d=0; d<n; d++)
	{
		min[d] = (int) image.min( d );
		dimMinus1[d] = (int) image.dimension( d ) - 1;
	}

	final Vector< ImagePortion > portions = FusionTools.divideIntoPortions(  Views.iterable( image ).size() );
	final ArrayList< Callable< Void > > calls = new ArrayList<>();
	for (final ImagePortion portion : portions)
	{
		calls.add( new Callable< Void >()
		{
			@Override
			public Void call() throws Exception
			{
				// NB: assuming equal iteration order here
				final Cursor< R > weightC = Views.iterable( weightImage ).localizingCursor();
				final Cursor<T> inC = Views.iterable( image ).localizingCursor();
				inC.jumpFwd( portion.getStartPosition() );
				weightC.jumpFwd( portion.getStartPosition() );
				final float[] position = new float[n];
				for (long i=0; i<portion.getLoopSize(); i++)
				{
					inC.fwd();
					weightC.fwd();
					inC.localize( position );
					for (int d=0; d<n; d++)
						position[d] -= renderOffset[d];
					final float w = BlendingTools.computeWeight( position, min, dimMinus1, border, blending, n );
					inC.get().setReal( inC.get().getRealFloat() * w);
					
					if (multiplyWeights)
					{
						weightC.get().setReal(weightC.get().getRealDouble() * w );
					}
					else
					{
						weightC.get().setReal( w );
					}
				}
				return null;
			}
		} );
	}

	try
	{
		final List< Future< Void > > futures = pool.invokeAll( calls );
		for (final Future< Void > f : futures)
			f.get();
	}
	catch ( InterruptedException | ExecutionException e ) { e.printStackTrace(); }
}