Java Code Examples for net.imglib2.util.Intervals#numElements()
The following examples show how to use
net.imglib2.util.Intervals#numElements() .
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: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
public ArrayImg<UnsignedVariableBitLengthType, LongArray> generateUnsignedVariableBitLengthTypeArrayTestImg(final boolean fill, final int nbits, final long... dims) { final long[] array = new long[(int) Intervals.numElements(new FinalInterval( dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (long) (((pseudoRandom() / Integer.MAX_VALUE)) % (Math.pow(2, nbits))) ; } } final LongArray l = new LongArray(array); return ArrayImgs.unsignedVariableBitLengths(l, nbits, dims); }
Example 2
Source File: VolatileHelpers.java From paintera with GNU General Public License v2.0 | 6 votes |
@Override public Cell<VolatileLabelMultisetArray> createInvalid(final Long key) throws Exception { final long[] cellPosition = new long[grid.numDimensions()]; grid.getCellGridPositionFlat(key, cellPosition); final long[] cellMin = new long[cellPosition.length]; final int[] cellDims = new int[cellPosition.length]; grid.getCellDimensions(cellPosition, cellMin, cellDims); final LabelMultisetEntry e = new LabelMultisetEntry(Label.INVALID, 1); final int numEntities = (int) Intervals.numElements(cellDims); final LongMappedAccessData listData = LongMappedAccessData.factory.createStorage(32); final LabelMultisetEntryList list = new LabelMultisetEntryList(listData, 0); list.createListAt(listData, 0); list.add(e); final int[] data = new int[numEntities]; final VolatileLabelMultisetArray array = new VolatileLabelMultisetArray( data, listData, false, new long[] {Label.INVALID} ); return new Cell<>(cellDims, cellMin, array); }
Example 3
Source File: DefaultCoarsenessFeature.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Apply mean filter with given size of reactangle shape * * @param input * Input image * @param i * Size of rectangle shape * @return Filered mean image */ @SuppressWarnings("unchecked") private Img<I> mean(final RandomAccessibleInterval<I> input, final int i) { long[] dims = new long[input.numDimensions()]; input.dimensions(dims); final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(dims))]; Img<I> meanImg = (Img<I>) ArrayImgs.unsignedBytes(array, dims); OutOfBoundsMirrorFactory<ByteType, Img<ByteType>> oobFactory = new OutOfBoundsMirrorFactory<>( Boundary.SINGLE); ops().run(MeanFilterOp.class, meanImg, input, new RectangleShape(i, true), oobFactory); return meanImg; }
Example 4
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<ShortType, ShortArray> generateShortArrayTestImg( final boolean fill, final long... dims) { final short[] array = new short[(int) Intervals.numElements( new FinalInterval(dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (short) (pseudoRandom() / Integer.MAX_VALUE); } } return ArrayImgs.shorts(array, dims); }
Example 5
Source File: ConvertMapTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private static Img<FloatType> generateFloatImg(final float[] values) { final float[] array = new float[(int) Intervals.numElements(new FinalInterval(dims))]; if (array.length != values.length) { throw new RuntimeException("Number of values doesn't match dimmensions"); } for (int i = 0; i < array.length; i++) { array[i] = values[i]; } return ArrayImgs.floats(array, dims); }
Example 6
Source File: MinMaxFilter.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Plane openPlane(final int imageIndex, final long planeIndex, final Plane plane, final Interval bounds, final SCIFIOConfig config) throws FormatException, IOException { // FormatTools.assertId(getCurrentFile(), true, 2); super.openPlane(imageIndex, planeIndex, plane, bounds, config); final int bytesPerPixel = FormatTools.getBytesPerPixel(// getMetadata().get(imageIndex).getPixelType()); final int len = (int) (bytesPerPixel * Intervals.numElements(bounds)); updateMinMax(imageIndex, planeIndex, plane.getBytes(), len); return plane; }
Example 7
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<FloatType, FloatArray> generateFloatArrayTestImg( final boolean fill, final long... dims) { final float[] array = new float[(int) Intervals.numElements( new FinalInterval(dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (float) pseudoRandom() / (float) Integer.MAX_VALUE; } } return ArrayImgs.floats(array, dims); }
Example 8
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<IntType, IntArray> generateIntArrayTestImg(final boolean fill, final long... dims) { final int[] array = new int[(int) Intervals.numElements(new FinalInterval( dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (int) pseudoRandom() / (int) Integer.MAX_VALUE; } } return ArrayImgs.ints(array, dims); }
Example 9
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<UnsignedShortType, ShortArray> generateUnsignedShortArrayTestImg(final boolean fill, final long... dims) { final short[] array = new short[(int) Intervals.numElements( new FinalInterval(dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (short) (pseudoRandom() / Integer.MAX_VALUE); } } return ArrayImgs.unsignedShorts(array, dims); }
Example 10
Source File: PainteraAlerts.java From paintera with GNU General Public License v2.0 | 5 votes |
private static void findMaxId( final DataSource<? extends IntegerType<?>, ?> source, final int level, final LongConsumer maxIdTracker, final AtomicBoolean cancel, final DoubleConsumer progressTracker) { final RandomAccessibleInterval<? extends IntegerType<?>> rai = source.getDataSource(0, level); final ReadOnlyLongWrapper totalNumVoxels = new ReadOnlyLongWrapper(Intervals.numElements(rai)); maxIdTracker.accept(org.janelia.saalfeldlab.labels.Label.getINVALID()); final LongProperty numProcessedVoxels = new SimpleLongProperty(0); numProcessedVoxels.addListener((obs, oldv, newv) -> progressTracker.accept(numProcessedVoxels.doubleValue() / totalNumVoxels.doubleValue())); final int[] blockSize = blockSizeFromRai(rai); final List<Interval> intervals = Grids.collectAllContainedIntervals(Intervals.minAsLongArray(rai), Intervals.maxAsLongArray(rai), blockSize); final ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); final List<Future<?>> futures = new ArrayList<>(); for (final Interval interval : intervals) { futures.add(es.submit(() -> { synchronized (cancel) { if (cancel.get()) return; } final RandomAccessibleInterval<? extends IntegerType<?>> slice = Views.interval(rai, interval); final long maxId = findMaxId(slice); synchronized (cancel) { if (!cancel.get()) { numProcessedVoxels.set(numProcessedVoxels.get() + Intervals.numElements(slice)); maxIdTracker.accept(maxId); } } })); } futures.forEach(ThrowingConsumer.unchecked(Future::get)); es.shutdown(); }
Example 11
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<UnsignedByteType, ByteArray> generateUnsignedByteArrayTestImg( final boolean fill, final long... dims) { final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval( dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (byte) pseudoRandom(); } } return ArrayImgs.unsignedBytes(array, dims); }
Example 12
Source File: DefaultCreateImgFactory.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public ImgFactory<T> calculate() { return (dims == null || Intervals.numElements(dims) <= Integer.MAX_VALUE) ? new ArrayImgFactory<>() : new CellImgFactory<>(); }
Example 13
Source File: SlicesII.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public long size() { return Intervals.numElements(this); }
Example 14
Source File: IntegralMean.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void compute(final RectangleNeighborhood<Composite<I>> input, final DoubleType output) { // computation according to // https://en.wikipedia.org/wiki/Summed_area_table final IntegralCursor<Composite<I>> cursor = new IntegralCursor<>(input); final int dimensions = input.numDimensions(); // Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector}) final DoubleType sum = new DoubleType(); sum.setZero(); // Convert from input to return type final Converter<I, DoubleType> conv = new RealDoubleConverter<>(); final DoubleType valueAsDoubleType = new DoubleType(); while (cursor.hasNext()) { final I value = cursor.next().get(0).copy(); conv.convert(value, valueAsDoubleType); // Obtain the cursor position encoded as corner vector final int cornerInteger = cursor.getCornerRepresentation(); // Determine if the value has to be added (factor==1) or subtracted // (factor==-1) final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions - IntegralMean.norm(cornerInteger))); valueAsDoubleType.mul(factor); sum.add(valueAsDoubleType); } final int area = (int) Intervals.numElements(Intervals.expand(input, -1l)); // Compute mean by dividing the sum divided by the number of elements valueAsDoubleType.set(area); // NB: Reuse DoubleType sum.div(valueAsDoubleType); output.set(sum); }
Example 15
Source File: ConvolveNaiveF.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean conforms() { // conforms only if the kernel is sufficiently small return Intervals.numElements(in2()) <= 9; }
Example 16
Source File: ConvolveNaiveC.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean conforms() { // conforms only if the kernel is sufficiently small return Intervals.numElements(kernel) <= 9; }
Example 17
Source File: PadAndConvolveFFTF.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean conforms() { // conforms only if the kernel is sufficiently large return Intervals.numElements(in2()) > 9; }
Example 18
Source File: PadAndConvolveFFT.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean conforms() { // conforms only if the kernel is sufficiently large return Intervals.numElements(in2()) > 9; }
Example 19
Source File: PadAndCorrelateFFT.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean conforms() { // TODO: only conforms if the kernel is sufficiently large (else the // naive approach should be used) -> what is a good heuristic?? return Intervals.numElements(in2()) > 9; }
Example 20
Source File: AbstractArrayLoader.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Recurses over all the provided {@link Range}s, reading the corresponding * bytes and storing them in the provided data object. */ private void read(final A data, Plane tmpPlane, final Interval bounds, final Range[] npRanges, final long[] npIndices, final int depth, int planeCount) throws FormatException, IOException { if (depth < npRanges.length) { // We need to invert the depth index to get the current non-planar // axis index, to ensure axes are iteratead in fastest to slowest // order final int npPosition = npRanges.length - 1 - depth; for (int i = 0; i < npRanges[npPosition].size(); i++) { npIndices[npPosition] = npRanges[npPosition].get(i); read(data, tmpPlane, bounds, npRanges, npIndices, depth + 1, planeCount); planeCount++; } } else if (inSubregion(npIndices)) { final int planeIndex = (int) FormatTools.positionToRaster(0, reader, npIndices); validateBounds(reader.getMetadata().get(0).getAxesLengthsPlanar(), bounds); if (tmpPlane == null) { tmpPlane = reader.openPlane(index, planeIndex, bounds); } else { // Sanity check! final long expectedLength = Intervals.numElements(bounds); if (tmpPlane.getBytes().length != expectedLength) { throw new IllegalArgumentException("Expected tmpPlane length " + expectedLength + " but was " + tmpPlane.getBytes().length); } tmpPlane = reader.openPlane(index, planeIndex, tmpPlane, bounds); } convertBytes(data, tmpPlane.getBytes(), planeCount); // update color table if (!loadedTable()[index][planeIndex]) { addTable(index, planeIndex, tmpPlane.getColorTable()); } } }