/** * Represent an arbitrary RandomAccessibleInterval as an Img * * @param accessible * RandomAccessibleInterval which will be wrapped with an ImgView * @param factory * ImgFactory returned by {@link ImgView#factory()} * @return * RandomAccessibleInterval represented as an Img */ public static < T extends Type< T >> Img< T > wrap(final RandomAccessibleInterval< T > accessible, final ImgFactory< T > factory){ if(accessible instanceof Img){ return (Img<T>) accessible; }else{ return new ImgView< T >(accessible, factory); } } }
private <T extends RealType<T>> Img<T> wrapToImg( final RandomAccessibleInterval<T> rai) { if (rai instanceof Img) return (Img<T>) rai; return ImgView.wrap(rai, imgFactory(rai)); }
@Override public Img< T > copy() { final Img< T > copy = factory.create( this ); final Cursor< T > srcCursor = localizingCursor(); final RandomAccess< T > resAccess = copy.randomAccess(); while ( srcCursor.hasNext() ) { srcCursor.fwd(); resAccess.setPosition( srcCursor ); resAccess.get().set( srcCursor.get() ); } return copy; }
@Override public Img< T > copy() { final Img< T > copy = factory.create( this ); final Cursor< T > srcCursor = localizingCursor(); final RandomAccess< T > resAccess = copy.randomAccess(); while ( srcCursor.hasNext() ) { srcCursor.fwd(); resAccess.setPosition( srcCursor ); resAccess.get().set( srcCursor.get() ); } return copy; }
/** * Represent an arbitrary RandomAccessibleInterval as an Img * * @param accessible * RandomAccessibleInterval which will be wrapped with an ImgView * @param factory * ImgFactory returned by {@link ImgView#factory()} * @return * RandomAccessibleInterval represented as an Img */ public static < T extends Type< T >> Img< T > wrap(final RandomAccessibleInterval< T > accessible, final ImgFactory< T > factory){ if(accessible instanceof Img){ return (Img<T>) accessible; }else{ return new ImgView< T >(accessible, factory); } } }
@Override public ImgPlus<T> calculate(final ImgPlus<T> input, final Interval interval) { final ImgPlus<T> out = new ImgPlus<>(ImgView.wrap(cropper.calculate(input, interval), input.factory())); // TODO remove metadata-util MetadataUtil.copyAndCleanImgPlusMetadata(interval, input, out); return out; } }
private static <T extends Type<T>> Img<T> setUpSlice( ImgPlus<T> sourceImgPlus, int d, long pos) { return new ImgView<T>(Views.hyperSlice(sourceImgPlus, d, pos), sourceImgPlus.factory()); }
/** * 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; }
private static <T extends Type<T>> Img<T> setUpSlice( ImgPlus<T> sourceImgPlus, int d, long pos) { return new ImgView<T>(Views.hyperSlice(sourceImgPlus, d, pos), sourceImgPlus.factory()); }
private ImgPlus<UnsignedByteType> splitColorChannels(ImgPlus<ARGBType> input) { Img<ARGBType> colored = input.getImg(); RandomAccessibleInterval<UnsignedByteType> colorStack = Views.stack( Converters.argbChannel( colored, 1 ), Converters.argbChannel( colored, 2 ), Converters.argbChannel( colored, 3 ) ); ImgPlus<UnsignedByteType> result = new ImgPlus<>(ImgView.wrap(colorStack, new PlanarImgFactory<>()), input.getName()); int lastAxis = colored.numDimensions(); for (int i = 0; i < lastAxis; i++) result.setAxis(input.axis(i).copy(), i); result.setAxis(new DefaultLinearAxis(Axes.CHANNEL), lastAxis); return ImgPlusViews.moveAxis(result, lastAxis, 2); }
new ImgView<>( Converters.convert( ( RandomAccessibleInterval<UnsignedByteType> ) ImageJFunctions.wrapByte( imp ),
@SuppressWarnings("unused") private Overlay createDefaultOverlay(final Roi roi) { final Rectangle bounds = roi.getBounds(); final ArrayImg<BitType, LongArray> arrayImg = ArrayImgs.bits(bounds.width, bounds.height); arrayImg.setLinkedType(new BitType(arrayImg)); final int xOff = bounds.x; final int yOff = bounds.y; final Img<BitType> img = new ImgView<BitType>(Views.translate(arrayImg, xOff, yOff), arrayImg .factory()); final RandomAccess<BitType> ra = img.randomAccess(); final ImageProcessor ip = roi.getMask(); for (int i = xOff; i < xOff + bounds.width; i++) { ra.setPosition(i, 0); for (int j = yOff; j < yOff + bounds.height; j++) { ra.setPosition(j, 1); ra.get().set(ip.get(i - xOff, j - yOff) > 0); } } final BinaryMaskRegionOfInterest<BitType, Img<BitType>> broi = new BinaryMaskRegionOfInterest<BitType, Img<BitType>>(img); final Overlay overlay = new BinaryMaskOverlay<BitType, Img<BitType>>(getContext(), broi); assignPropertiesToOverlay(overlay, roi); return overlay; }