Java Code Examples for net.imglib2.Interval#numDimensions()
The following examples show how to use
net.imglib2.Interval#numDimensions() .
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: FractalSpimDataGenerator.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static List<TranslationGet> getTileTranslations(List<Interval> intervals) { final List< TranslationGet > tr = new ArrayList<>(); for(Interval iv : intervals) { double[] min = new double[iv.numDimensions()]; iv.realMin( min ); if (iv.numDimensions() == 2) tr.add( new Translation2D( min ) ); else tr.add( new Translation3D( min ) ); } return tr; }
Example 2
Source File: PlaneSeparator.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Returns true if we have a cached plane matching the given image and plane * indices, with extents to cover the desired offsets and lengths */ private boolean haveCached(final long source, final int imageIndex, final Interval bounds) { if (source != lastPlaneIndex || imageIndex != lastImageIndex || lastPlane == null || lastPlaneMin == null || lastPlaneMax == null) { return false; } // TODO It would be nice to fix up this logic so that we can use // cached planes when requesting a sub-region of the cached plane. // See https://github.com/scifio/scifio/issues/155 for (int d = 0; d < bounds.numDimensions(); d++) { if (bounds.min(d) != lastPlaneMin[d]) return false; if (bounds.max(d) != lastPlaneMax[d]) return false; } return true; }
Example 3
Source File: TestImgFormat.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public ByteArrayPlane openPlane(final int imageIndex, final long planeIndex, final ByteArrayPlane plane, final Interval bounds, final SCIFIOConfig config) throws FormatException, IOException { final Metadata meta = getMetadata(); FormatTools.checkPlaneForReading(meta, imageIndex, planeIndex, plane .getData().length, bounds); plane.setImageMetadata(meta.get(imageIndex)); final long[] pos = FormatTools.rasterToPosition(meta.get(imageIndex) .getAxesLengthsNonPlanar(), planeIndex); final long[] planarIndices = new long[bounds.numDimensions()]; openPlaneHelper(imageIndex, planeIndex, meta, plane, bounds, pos, planarIndices, 0, -1, -1); return plane; }
Example 4
Source File: BlendingRealRandomAccess.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
/** * RealRandomAccess that computes a blending function for a certain {@link Interval} * * @param interval - the interval it is defined on (return zero outside of it) * @param border - how many pixels to skip before starting blending (on each side of each dimension) * @param blending - how many pixels to compute the blending function on (on each side of each dimension) */ public BlendingRealRandomAccess( final Interval interval, final float[] border, final float[] blending ) { this.interval = interval; this.n = interval.numDimensions(); this.l = new float[ n ]; this.border = border; this.blending = blending; this.v = new FloatType(); this.min = new int[ n ]; this.dimMinus1 = new int[ n ]; for ( int d = 0; d < n; ++d ) { this.min[ d ] = (int)interval.min( d ); this.dimMinus1[ d ] = (int)interval.max( d ) - min[ d ]; } }
Example 5
Source File: Imgs.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Adjusts the given {@link Img} to match the bounds of the specified * {@link Interval}. * * @param img An image whose min/max bounds might need adjustment. * @param minMax An {@link Interval} whose min/max bounds to use when * adjusting the image. If the provided {@code minMax} object is not * an {@link Interval}, no adjustment is performed. * @return A wrapped version of the input {@link Img} with bounds adjusted to * match the provided {@link Interval}, if any; or the input image * itself if no adjustment was needed/possible. */ public static <T extends Type<T>> Img<T> adjustMinMax(final Img<T> img, final Object minMax) { if (!(minMax instanceof Interval)) return img; final Interval interval = (Interval) minMax; final long[] min = new long[interval.numDimensions()]; interval.min(min); for (int d = 0; d < min.length; d++) { if (min[d] != 0) { return ImgView.wrap(Views.translate(img, min), img.factory()); } } return img; }
Example 6
Source File: SlicesII.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private static Interval initIntervals(final Interval src, final int[] axesOfInterest) { final long[] dimensionsToIterate = new long[src.numDimensions()]; src.dimensions(dimensionsToIterate); // determine axis to iterate for (int i = 0; i < src.numDimensions(); i++) { for (int j = 0; j < axesOfInterest.length; j++) { if (axesOfInterest[j] == i) { dimensionsToIterate[i] = 1; break; } } } return new FinalInterval(dimensionsToIterate); }
Example 7
Source File: Morphologies.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Computes the min coordinate and the size of an {@link Interval} after * padding with a list of {@link Shape}s in a series morphology operations. * * @param source the interval to be applied with some morphology operation * @param shapes the list of Shapes for padding * @return a size-2 array storing the min coordinate and the size of the * padded interval */ public static final long[][] computeMinSize(final Interval source, final List<Shape> shapes) { final int numDims = source.numDimensions(); final long[] min = new long[numDims]; final long[] size = new long[numDims]; for (int i = 0; i < numDims; i++) { min[i] = source.min(i); size[i] = source.dimension(i); } for (final Shape shape : shapes) { final Neighborhood<BitType> nh = MorphologyUtils.getNeighborhood(shape, source); for (int i = 0; i < numDims; i++) { min[i] += nh.min(i); size[i] += nh.dimension(i) - 1; } } return new long[][] { min, size }; }
Example 8
Source File: CropRAI.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RandomAccessibleInterval<T> calculate(final RandomAccessibleInterval<T> input, final Interval interval) { boolean oneSizedDims = false; if (dropSingleDimensions) { for (int d = 0; d < interval.numDimensions(); d++) { if (interval.dimension(d) == 1) { oneSizedDims = true; break; } } } if (Intervals.equals(input, interval) && !oneSizedDims) return input; if (!Intervals.contains(input, interval)) throw new RuntimeException("Intervals don't match!"); IntervalView<T> res = Views.offsetInterval(input, interval); return oneSizedDims ? Views.dropSingletonDimensions(res) : res; }
Example 9
Source File: BlendingRealRandomAccess.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
/** * RealRandomAccess that computes a blending function for a certain {@link Interval} * * @param interval - the interval it is defined on (return zero outside of it) * @param border - how many pixels to skip before starting blending (on each side of each dimension) * @param blending - how many pixels to compute the blending function on (on each side of each dimension) */ public BlendingRealRandomAccess( final Interval interval, final float[] border, final float[] blending ) { this.interval = interval; this.n = interval.numDimensions(); this.l = new float[ n ]; this.border = border; this.blending = blending; this.v = new FloatType(); this.min = new int[ n ]; this.dimMinus1 = new int[ n ]; for ( int d = 0; d < n; ++d ) { this.min[ d ] = (int)interval.min( d ); this.dimMinus1[ d ] = (int)interval.max( d ) - min[ d ]; } }
Example 10
Source File: SlicesII.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public SlicesIICursor(final RandomAccessibleInterval<T> src, final Interval fixedAxes, final Interval slice) { super(fixedAxes); this.src = src; this.tmpPosition = new long[fixedAxes.numDimensions()]; this.sliceDims = new long[slice.numDimensions()]; this.sliceOffset = new long[slice.numDimensions()]; slice.dimensions(sliceDims); slice.min(sliceOffset); }
Example 11
Source File: FourNeighborhoodExtrema.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
/** * split the given Interval into nSplits intervals along the largest dimension * @param interval input interval * @param nSplits how may splits * @return list of intervals input was split into */ public static List<Interval> splitAlongLargestDimension(Interval interval, long nSplits){ List<Interval> res = new ArrayList<Interval>(); long[] min = new long[interval.numDimensions()]; long[] max = new long[interval.numDimensions()]; interval.min(min); interval.max(max); int splitDim = 0; for (int i = 0; i< interval.numDimensions(); i++){ if (interval.dimension(i) > interval.dimension(splitDim)) splitDim = i; } // there could be more splits than actual dimension entries nSplits = Math.min( nSplits, interval.dimension(splitDim) ); long chunkSize = interval.dimension(splitDim) / nSplits; long maxSplitDim = max[splitDim]; for (int i = 0; i<nSplits; i++){ if (i != 0){ min[splitDim] += chunkSize; } max[splitDim] = min[splitDim] + chunkSize - 1; if (i == nSplits -1){ max[splitDim] = maxSplitDim; } res.add(new FinalInterval(min, max)); } return res; }
Example 12
Source File: DifferenceOfGaussianCUDA.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public static long[] getImgSize( final Interval img ) { final long[] dim = new long[ img.numDimensions() ]; for ( int d = 0; d < img.numDimensions(); ++d ) dim[ d ] = img.dimension( d ); return dim; }
Example 13
Source File: DifferenceOfGaussianCUDA.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public static int[] getImgSizeInt( final Interval img ) { final int[] dim = new int[ img.numDimensions() ]; for ( int d = 0; d < img.numDimensions(); ++d ) dim[ d ] = (int)img.dimension( d ); return dim; }
Example 14
Source File: FractalSpimDataGenerator.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
/** * create SpimData containing Views at each Interval * @param intervals list of intervals * @return generated SpimData */ public SpimData generateSpimData(final List<Interval> intervals) { final List<RealLocalizable> mins = new ArrayList<>(); for(Interval iv : intervals) { RealPoint min = new RealPoint( iv.numDimensions() ); iv.min( min ); mins.add( min ); } return generateSpimData( intervals, mins ); }
Example 15
Source File: AbstractArrayLoader.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
private void validateBounds(final long[] lengths, final Interval bounds) { if (lengths.length != bounds.numDimensions()) { throw new IllegalArgumentException("Expected bounds of dimensionality " + lengths.length + " but was " + bounds.numDimensions()); } for (int d = 0; d < bounds.numDimensions(); d++) { if (bounds.min(d) < 0 || bounds.max(d) >= lengths[d]) { throw new IllegalArgumentException("Bound #" + d + " of " + // "[" + bounds.min(d) + ", " + bounds.max(d) + "] " + // "is not contained in [0, " + lengths[d] + "]"); } } }
Example 16
Source File: SCIFIOMetadataTools.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Returns true if the provided axes correspond to a complete image row */ public static boolean wholeRow(final int imageIndex, final Metadata meta, final Interval bounds) { final int yIndex = meta.get(imageIndex).getAxisIndex(Axes.Y); for (int d = 0; d < bounds.numDimensions(); d++) { if (d == yIndex) continue; final long length = meta.get(imageIndex).getAxisLength(d); if (bounds.min(d) != 0 || bounds.dimension(d) != length) return false; } return true; }
Example 17
Source File: PlaneSeparator.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Converts the given plane information using the current metadata to a format * usable by the wrapped reader, stored in the "lastPlane"... variables. */ private void updateLastPlaneInfo(final long source, final int imageIndex, final int splitOffset, final Interval bounds) { final Metadata meta = getMetadata(); final Metadata parentMeta = getParentMeta(); lastPlaneIndex = source; lastImageIndex = imageIndex; // create the plane offsets and lengths to match the underlying image lastPlaneMin = new long[bounds.numDimensions() + splitOffset]; lastPlaneMax = new long[bounds.numDimensions() + splitOffset]; // Create the offset and length arrays to match the underlying, // unsplit dimensions. This is required to pass to the wrapped reader. // The unsplit plane will then have the appropriate region extracted. for (final CalibratedAxis axis : parentMeta.get(imageIndex) .getAxesPlanar()) { final int parentIndex = parentMeta.get(imageIndex).getAxisIndex(axis .type()); final int currentIndex = meta.get(imageIndex).getAxisIndex(axis.type()); // This axis is still a planar axis, so we can read it from the // current plane offsets/lengths if (currentIndex >= 0 && currentIndex < meta.get(imageIndex) .getPlanarAxisCount()) { lastPlaneMin[parentIndex] = bounds.min(currentIndex); lastPlaneMax[parentIndex] = bounds.max(currentIndex); } // This axis is a planar axis in the underlying metadata that was // split out, so we will insert a [0,length] range else if (parentMeta.get(imageIndex).getAxisIndex(axis.type()) < parentMeta .get(imageIndex).getPlanarAxisCount()) { lastPlaneMin[parentIndex] = 0; lastPlaneMax[parentIndex] = parentMeta.get(imageIndex).getAxisLength( axis.type()) - 1; } } }
Example 18
Source File: FractalSpimDataGenerator.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public static List< RealLocalizable > getTileMins(List<Interval> intervals) { final List<RealLocalizable> mins = new ArrayList<>(); for(Interval iv : intervals) { RealPoint min = new RealPoint( iv.numDimensions() ); iv.min( min ); mins.add( min ); } return mins; }
Example 19
Source File: ByteArrayPlane.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected byte[] blankPlane(final Interval bounds) { byte[] buf = null; final long[] sizes = new long[bounds.numDimensions() + 1]; for (int i = 0; i < sizes.length - 1; i++) { sizes[i] = bounds.dimension(i); } sizes[sizes.length - 1] = FormatTools.getBytesPerPixel(getImageMetadata() .getPixelType()); buf = ArrayUtils.allocate(sizes); return buf; }
Example 20
Source File: DisplayOverlapTestPopup.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static <S extends AbstractSequenceDescription< ?,? extends BasicViewDescription<? extends BasicViewSetup>, ? >> List<RandomAccessibleInterval< FloatType >> openVirtuallyFused( S sd, ViewRegistrations vrs, Collection<? extends Collection<ViewId>> views, Interval boundingBox, double[] downsamplingFactors) { final BasicImgLoader imgLoader = sd.getImgLoader(); final List<RandomAccessibleInterval< FloatType >> openImgs = new ArrayList<>(); final Interval bbSc = TransformVirtual.scaleBoundingBox( new FinalInterval( boundingBox ), inverse( downsamplingFactors )); final long[] dim = new long[ bbSc.numDimensions() ]; bbSc.dimensions( dim ); for (Collection<ViewId> viewGroup : views) { final ArrayList< RandomAccessibleInterval< FloatType > > images = new ArrayList<>(); final ArrayList< RandomAccessibleInterval< FloatType > > weights = new ArrayList<>(); for ( final ViewId viewId : viewGroup ) { final ViewRegistration vr = vrs.getViewRegistration( viewId ); vr.updateModel(); AffineTransform3D model = vr.getModel(); final float[] blending = Util.getArrayFromValue( FusionTools.defaultBlendingRange, 3 ); final float[] border = Util.getArrayFromValue( FusionTools.defaultBlendingBorder, 3 ); model = model.copy(); TransformVirtual.scaleTransform( model, inverse(downsamplingFactors) ); final RandomAccessibleInterval inputImg = DownsampleTools.openDownsampled( imgLoader, viewId, model ); System.out.println( model.inverse() ); FusionTools.adjustBlending( sd.getViewDescriptions().get( viewId ), blending, border, model ); images.add( TransformView.transformView( inputImg, model, bbSc, 0, 1 ) ); weights.add( TransformWeight.transformBlending( inputImg, border, blending, model, bbSc ) ); } openImgs.add( new FusedRandomAccessibleInterval( new FinalInterval( dim ), images, weights ) ); } return openImgs; }