net.imglib2.type.Type Java Examples
The following examples show how to use
net.imglib2.type.Type.
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: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the min of an image. * * @param img The image to calculate the min of * @return The min of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMin( final RandomAccessibleInterval<T> img ) { final Cursor<T> cursor = Views.iterable(img).cursor(); cursor.fwd(); // copy first element as current maximum final T min = cursor.get().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.get(); if ( currValue.compareTo( min ) < 0 ) min.set( currValue ); } return min; }
Example #2
Source File: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the min of an image with respect to a mask. * * @param img The image to calculate the min of * @param mask The mask to respect * @return The min of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMin( final RandomAccessibleInterval<T> img, final RandomAccessibleInterval<BitType> mask ) { // create cursor to walk an image with respect to a mask final TwinCursor<T> cursor = new TwinCursor<T>( img.randomAccess(), img.randomAccess(), Views.iterable(mask).localizingCursor()); // forward one step to get the first value cursor.fwd(); // copy first element as current minimum final T min = cursor.getFirst().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.getFirst(); if ( currValue.compareTo( min ) < 0 ) min.set( currValue ); } return min; }
Example #3
Source File: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the max of an image with respect to a mask. * * @param img The image to calculate the min of * @param mask The mask to respect * @return The min of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMax( final RandomAccessibleInterval<T> img, final RandomAccessibleInterval<BitType> mask ) { // create cursor to walk an image with respect to a mask final TwinCursor<T> cursor = new TwinCursor<T>( img.randomAccess(), img.randomAccess(), Views.iterable(mask).localizingCursor()); // forward one step to get the first value cursor.fwd(); final T max = cursor.getFirst().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.getFirst(); if ( currValue.compareTo( max ) > 0 ) max.set( currValue ); } return max; }
Example #4
Source File: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the max of an image. * * @param img The image to calculate the max of * @return The max of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMax( final RandomAccessibleInterval<T> img ) { final Cursor<T> cursor = Views.iterable(img).localizingCursor(); cursor.fwd(); // copy first element as current maximum final T max = cursor.get().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.get(); if ( currValue.compareTo( max ) > 0 ) max.set( currValue ); } return max; }
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: LogicNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.logic.If.class) public <I extends BooleanType<I>, O extends Type<O>> O conditional( final O out, final I in, final O ifTrueVal, final O ifFalseVal) { @SuppressWarnings("unchecked") final O result = (O) ops().run(Ops.Logic.Conditional.class, out, in, ifTrueVal, ifFalseVal); return result; }
Example #7
Source File: CopyNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.copy.CopyType.class) public <T extends Type<T>> T type(final T out, final T in) { @SuppressWarnings("unchecked") final T result = (T) ops().run(net.imagej.ops.copy.CopyType.class, out, in); return result; }
Example #8
Source File: RichardsonLucyTVUpdate.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * performs update step of the Richardson Lucy with Total Variation Algorithm */ @Override public void compute(I correction, I estimate) { if (variation == null) { Type<T> type = Util.getTypeFromInterval(correction); variation = ops().create().img(correction, type.createVariable()); } divUnitGradFastThread(estimate); final Cursor<T> cursorCorrection = Views.iterable(correction).cursor(); final Cursor<T> cursorVariation = Views.iterable(variation).cursor(); final Cursor<T> cursorEstimate = Views.iterable(estimate).cursor(); while (cursorEstimate.hasNext()) { cursorCorrection.fwd(); cursorVariation.fwd(); cursorEstimate.fwd(); cursorEstimate.get().mul(cursorCorrection.get()); cursorEstimate.get().mul(1f / (1f - regularizationFactor * cursorVariation .get().getRealFloat())); } }
Example #9
Source File: MorphologyNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.morphology.floodFill.DefaultFloodFill.class) public <T extends Type<T> & Comparable<T>> RandomAccessibleInterval<T> floodFill(final RandomAccessibleInterval<T> out, final RandomAccessibleInterval<T> in, final Localizable startPos, final Shape structElement) { @SuppressWarnings("unchecked") final RandomAccessibleInterval<T> result = (RandomAccessibleInterval<T>) ops().run( net.imagej.ops.morphology.floodFill.DefaultFloodFill.class, out, in, startPos, structElement); return result; }
Example #10
Source File: MorphologyNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.morphology.floodFill.DefaultFloodFill.class) public <T extends Type<T> & Comparable<T>> RandomAccessibleInterval<T> floodFill(final RandomAccessibleInterval<T> in1, final Localizable in2, final Shape structElement) { @SuppressWarnings("unchecked") final RandomAccessibleInterval<T> result = (RandomAccessibleInterval<T>) ops().run( net.imagej.ops.morphology.floodFill.DefaultFloodFill.class, in1, in2, structElement); return result; }
Example #11
Source File: AbstractArrayLoader.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
public AbstractArrayLoader(final Reader reader, final ImageRegion subRegion) { this.reader = reader; this.subRegion = subRegion; reader.getContext().inject(this); final Type<?> inputType = // imgUtilityService.makeType(reader.getMetadata().get(0).getPixelType()); compatible = outputClass().isAssignableFrom(inputType.getClass()); }
Example #12
Source File: LogicNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.logic.If.class) public <I extends BooleanType<I>, O extends Type<O>> O conditional(final I in, final O ifTrueVal, final O ifFalseVal) { @SuppressWarnings("unchecked") final O result = (O) ops().run(Ops.Logic.Conditional.class, in, ifTrueVal, ifFalseVal); return result; }
Example #13
Source File: LogicNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.logic.Default.class) public <I extends BooleanType<I>, O extends Type<O>> O conditional( final O out, final I in, final O defaultVal) { @SuppressWarnings("unchecked") final O result = (O) ops().run(Ops.Logic.Conditional.class, out, in, defaultVal); return result; }
Example #14
Source File: GeomNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.geom.geom2d.DefaultContour.class) public <T extends Type<T>> Polygon2D contour( final RandomAccessibleInterval<T> in, final boolean useJacobs) { final Polygon2D result = (Polygon2D) ops().run( net.imagej.ops.Ops.Geometric.Contour.class, in, useJacobs); return result; }
Example #15
Source File: GeomNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.geom.geom3d.DefaultMarchingCubes.class) public <T extends Type<T>> Mesh marchingCubes( final RandomAccessibleInterval<T> in) { final Mesh result = (Mesh) ops().run( net.imagej.ops.Ops.Geometric.MarchingCubes.class, in); return result; }
Example #16
Source File: GeomNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.geom.geom3d.DefaultMarchingCubes.class) public <T extends Type<T>> Mesh marchingCubes( final RandomAccessibleInterval<T> in, final double isolevel) { final Mesh result = (Mesh) ops().run( net.imagej.ops.Ops.Geometric.MarchingCubes.class, in, isolevel); return result; }
Example #17
Source File: GeomNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.geom.geom3d.DefaultMarchingCubes.class) public <T extends Type<T>> Mesh marchingCubes( final RandomAccessibleInterval<T> in, final double isolevel, final VertexInterpolator interpolatorClass) { final Mesh result = (Mesh) ops().run( net.imagej.ops.Ops.Geometric.MarchingCubes.class, in, isolevel, interpolatorClass); return result; }
Example #18
Source File: CopyRAI.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void initialize() { final Object outType = out() == null ? Type.class : Util .getTypeFromInterval(out()); final Object inType = in() == null ? NativeType.class : Util .getTypeFromInterval(in()); final UnaryComputerOp<?, ?> typeComputer = Computers.unary(ops(), Ops.Copy.Type.class, outType, inType); mapComputer = RAIs.computer(ops(), Ops.Map.class, in(), typeComputer); createFunc = RAIs.function(ops(), Ops.Create.Img.class, in(), inType); }
Example #19
Source File: ImageNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** Executes the "fill" operation on the given arguments. */ @OpMethod(op = net.imagej.ops.image.fill.DefaultFill.class) public <T extends Type<T>> Iterable<T> fill(final Iterable<T> out, final T in) { @SuppressWarnings("unchecked") final Iterable<T> result = (Iterable<T>) ops().run( net.imagej.ops.Ops.Image.Fill.class, out, in); return result; }
Example #20
Source File: TransformNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Extend a RandomAccessibleInterval with a constant-value out-of-bounds * strategy. * * @param input the interval to extend. * @return (unbounded) RandomAccessible which extends the input interval to * infinity. * @see net.imglib2.outofbounds.OutOfBoundsConstantValue */ @OpMethod( op = net.imagej.ops.transform.extendValueView.DefaultExtendValueView.class) public <T extends Type<T>, F extends RandomAccessibleInterval<T>> ExtendedRandomAccessibleInterval<T, F> extendValueView(final F input, final T value) { return (ExtendedRandomAccessibleInterval<T, F>) ops().run( Ops.Transform.ExtendValueView.class, input, value); }
Example #21
Source File: TransformNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Executes the "crop" operation on the given arguments. * * @param in * @param interval * @param dropSingleDimensions * @return */ @OpMethod(op = net.imagej.ops.transform.crop.CropImgPlus.class) public <T extends Type<T>> ImgPlus<T> crop(final ImgPlus<T> in, final Interval interval, final boolean dropSingleDimensions) { @SuppressWarnings("unchecked") final ImgPlus<T> result = (ImgPlus<T>) ops().run(Ops.Transform.Crop.class, in, interval, dropSingleDimensions); return result; }
Example #22
Source File: TransformNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Executes the "crop" operation on the given arguments. * * @param in * @param interval * @return */ @OpMethod(op = net.imagej.ops.transform.crop.CropImgPlus.class) public <T extends Type<T>> ImgPlus<T> crop(final ImgPlus<T> in, final Interval interval) { @SuppressWarnings("unchecked") final ImgPlus<T> result = (ImgPlus<T>) ops().run(Ops.Transform.Crop.class, in, interval); return result; }
Example #23
Source File: MathNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.math.NullaryNumericTypeMath.Assign.class) public <T extends Type<T>> T assign(final T out, final T constant) { @SuppressWarnings("unchecked") final T result = (T) ops().run( net.imagej.ops.math.NullaryNumericTypeMath.Assign.class, out, constant); return result; }
Example #24
Source File: SourceInfo.java From paintera with GNU General Public License v2.0 | 5 votes |
@Deprecated public <D extends Type<D>, T extends RealType<T>> RawSourceState<D, T> addRawSource( final DataSource<D, T> source, final double min, final double max, final ARGBType color, final Composite<ARGBType, ARGBType> composite) { final RawSourceState<D, T> state = makeRawSourceState(source, min, max, color, composite); addState(source, state); return state; }
Example #25
Source File: SourceInfo.java From paintera with GNU General Public License v2.0 | 5 votes |
@Deprecated public <D extends Type<D>, T extends RealType<T>> RawSourceState<D, T> makeRawSourceState( final DataSource<D, T> source, final double min, final double max, final ARGBType color, final Composite<ARGBType, ARGBType> composite) { final ARGBColorConverter<T> converter = new ARGBColorConverter.InvertingImp1<>(min, max); converter.colorProperty().set(color); final RawSourceState<D, T> state = new RawSourceState<>(source, converter, composite, source.getName()); return state; }
Example #26
Source File: Mirror.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * @param image - The {@link Img} to mirror * @param dimension - The axis to mirror (e.g. 0->x-Axis->horizontally, 1->y-axis->vertically) * @param numThreads - number of threads */ public static < T extends Type< T > > boolean mirror( final Img< T > image, final int dimension, final int numThreads ) { final int n = image.numDimensions(); // divide the image into chunks final long imageSize = image.size(); final Vector< ImagePortion > portions = FusionHelper.divideIntoPortions( imageSize, numThreads * 4 ); final long maxMirror = image.dimension( dimension ) - 1; final long sizeMirrorH = image.dimension( dimension ) / 2; // set up executor service final ExecutorService taskExecutor = Executors.newFixedThreadPool( Threads.numThreads() ); final ArrayList< Callable< Void > > tasks = new ArrayList< Callable< Void > >(); for ( final ImagePortion portion : portions ) { tasks.add( new Callable< Void >() { @Override public Void call() throws Exception { final Cursor< T > cursorIn = image.localizingCursor(); final RandomAccess< T > cursorOut = image.randomAccess(); final T temp = image.firstElement().createVariable(); final long[] position = new long[ n ]; // set the cursorIn to right offset final long startPosition = portion.getStartPosition(); final long loopSize = portion.getLoopSize(); if ( startPosition > 0 ) cursorIn.jumpFwd( startPosition ); // iterate over all pixels, if they are above the middle switch them with their counterpart // from the other half in the respective dimension for ( long i = 0; i < loopSize; ++i ) { cursorIn.fwd(); cursorIn.localize( position ); if ( position[ dimension ] <= sizeMirrorH ) { // set the localizable to the correct mirroring position position[ dimension ] = maxMirror - position[ dimension ]; cursorOut.setPosition( position ); // do a triangle switching final T in = cursorIn.get(); final T out = cursorOut.get(); temp.set( in ); in.set( out ); out.set( temp ); } } return null; } }); } try { // invokeAll() returns when all tasks are complete taskExecutor.invokeAll( tasks ); } catch ( final InterruptedException e ) { IOFunctions.println( "Failed to compute downsampling: " + e ); e.printStackTrace(); return false; } taskExecutor.shutdown(); return true; }
Example #27
Source File: CopyNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@OpMethod(op = net.imagej.ops.copy.CopyType.class) public <T extends Type<T>> T type(final T in) { @SuppressWarnings("unchecked") final T result = (T) ops().run(net.imagej.ops.copy.CopyType.class, in); return result; }
Example #28
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
private Type<?> getType(final Reader r) { return utils().makeType(r.getMetadata().get(0).getPixelType()); }
Example #29
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Reads planes from the given initialized {@link Reader} into the specified * {@link Img}. */ private <T> void readPlanes(final Reader r, final int imageIndex, final ImgPlus<T> imgPlus, final SCIFIOConfig config) throws FormatException, IOException { // TODO - create better container types; either: // 1) an array container type using one byte array per plane // 2) as #1, but with an Reader reference reading planes on demand // 3) as PlanarRandomAccess, but with an Reader reference // reading planes on demand // PlanarRandomAccess is useful for efficient access to pixels in ImageJ // (e.g., getPixels) // #1 is useful for efficient SCIFIO import, and useful for tools // needing byte arrays (e.g., BufferedImage Java3D texturing by // reference) // #2 is useful for efficient memory use for tools wanting matching // primitive arrays (e.g., virtual stacks in ImageJ) // #3 is useful for efficient memory use // get container final PlanarAccess<?> planarAccess = utils().getPlanarAccess(imgPlus); final Type<?> inputType = // utils().makeType(r.getMetadata().get(0).getPixelType()); final T outputType = imgPlus.firstElement(); final boolean compatibleTypes = outputType.getClass().isAssignableFrom( inputType.getClass()); // populate planes final boolean isPlanar = planarAccess != null && compatibleTypes; final boolean isArray = utils().getArrayAccess(imgPlus) != null && compatibleTypes; final ImageRegion region = config.imgOpenerGetRegion(); final Metadata m = r.getMetadata(); final List<CalibratedAxis> planarAxes = m.get(imageIndex).getAxesPlanar(); final int planarAxisCount = planarAxes.size(); // [min, max] of the planar dimensions final long[] planarMin = new long[planarAxisCount]; final long[] planarMax = new long[planarAxisCount]; // Non-planar indices to open final Range[] npRanges = new Range[m.get(imageIndex).getAxesNonPlanar() .size()]; final long[] npIndices = new long[npRanges.length]; // populate plane dimensions int index = 0; for (final CalibratedAxis planarAxis : planarAxes) { if (region != null && region.hasRange(planarAxis.type())) { planarMin[index] = region.getRange(planarAxis.type()).head(); planarMax[index] = region.getRange(planarAxis.type()).tail(); } else { planarMin[index] = 0; planarMax[index] = m.get(imageIndex).getAxisLength(planarAxis) - 1; } index++; } final Interval bounds = new FinalInterval(planarMin, planarMax); // determine non-planar indices to open index = 0; for (final CalibratedAxis npAxis : m.get(imageIndex).getAxesNonPlanar()) { if (region != null && region.hasRange(npAxis.type())) { npRanges[index++] = region.getRange(npAxis.type()); } else { npRanges[index++] = new Range(0l, m.get(imageIndex).getAxisLength(npAxis .type()) - 1); } } PlaneConverter converter = config.imgOpenerGetPlaneConverter(); if (converter == null) { // if we have a PlanarAccess we can use a PlanarAccess converter, // otherwise we can use a more general RandomAccess approach if (isArray) { converter = pcService.getArrayConverter(); } else if (isPlanar) { converter = pcService.getPlanarConverter(); } else converter = pcService.getDefaultConverter(); } read(imageIndex, imgPlus, r, config, converter, bounds, npRanges, npIndices); if (config.imgOpenerIsComputeMinMax()) populateMinMax(r, imgPlus, imageIndex); }
Example #30
Source File: ImgUtilityService.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
/** Converts SCIFIO pixel type to ImgLib2 Type object. */ Type<?> makeType(final int pixelType);