public class ImgMath extends Object
RandomAccessibleInterval instances.
Peak performance is within 1.2X - 1.8X of manually writing a loop
using ImgLib2's low-level Cursor or RandomAccess with
native math + / - * and flow if else operators
and in-loop variable declarations.
Input images can be of different Type as long as all of them
extend RealType.
An example in java:
import static net.imglib2.algorithm.math.ImgMath.*;
RandomAccessibleInterval<A> img1 = ...
RandomAccessibleInterval<B> img2 = ...
RandomAccessibleInterval<C> img3 = ...
RandomAccessibleInterval<O> result = ...
compute( div( max( img1, img2, img3 ), 3.0 ) ).into( result );
Another example, illustrating variable declaration with Let
and also if/then/else flow control, to compute the saturation of
an RGB image:
import static net.imglib2.algorithm.math.ImgMath.*;
RandomAccessible< ARGBType > rgb = ...
final RandomAccessibleInterval< UnsignedByteType >
red = Converters.argbChannel( rgb, 1 ),
green = Converters.argbChannel( rgb, 2 ),
blue = Converters.argbChannel( rgb, 3 );
RandomAccessibleInterval< FloatType > saturation = new ArrayImgFactory< FloatType >( new FloatType() ).create( rgb );
compute( let( "red", red,
"green", green,
"blue", blue,
"max", max( var( "red" ), var( "green" ), var( "blue" ) ),
"min", min( var( "red" ), var( "green" ), var( "blue" ) ),
IF ( EQ( 0, var( "max" ) ),
THEN( 0 ),
ELSE( div( sub( var( "max" ), var( "min" ) ),
var( "max" ) ) ) ) ) )
.into( saturation );
| Constructor and Description |
|---|
ImgMath() |
public static final <I extends net.imglib2.type.numeric.RealType<I>> Compute compute(net.imglib2.RandomAccessibleInterval<I> src)
public static final net.imglib2.RandomAccessibleInterval<net.imglib2.type.numeric.real.FloatType> computeIntoFloats(IFunction operation)
public static final <O extends net.imglib2.type.numeric.RealType<O>> net.imglib2.RandomAccessibleInterval<O> computeInto(IFunction operation, net.imglib2.RandomAccessibleInterval<O> target)
public static final <O extends net.imglib2.type.numeric.RealType<O>> net.imglib2.RandomAccessibleInterval<O> computeInto(IFunction operation, net.imglib2.RandomAccessibleInterval<O> target, net.imglib2.converter.Converter<net.imglib2.type.numeric.RealType<?>,O> converter)
public static final <O extends net.imglib2.type.NativeType<O> & net.imglib2.type.numeric.RealType<O>> net.imglib2.RandomAccessibleInterval<O> computeIntoImg(IFunction operation)
public static final <O extends net.imglib2.type.NativeType<O> & net.imglib2.type.numeric.RealType<O>> net.imglib2.RandomAccessibleInterval<O> computeIntoArrayImg(IFunction operation)
public static final <O extends net.imglib2.type.numeric.RealType<O>> net.imglib2.RandomAccessibleInterval<O> view(ViewableFunction operation)
IFunction are also ViewableFunction.operation - public static final net.imglib2.RandomAccessibleInterval<net.imglib2.type.numeric.real.FloatType> viewFloats(ViewableFunction operation)
IFunction are also ViewableFunction.operation - public static final GreaterThan GT(Object o1, Object o2)
public static final GreaterThan greaterThan(Object o1, Object o2)
public static final AndLogical AND(Object o1, Object o2)
public static final AndLogical AND(Object... o)
public static final XorLogical XOR(Object o1, Object o2)
public static final XorLogical XOR(Object... o)
public static final NotLogical NOT(Object o)
public static final <T extends net.imglib2.type.numeric.RealType<T>> ImgSource<T> img(net.imglib2.RandomAccessibleInterval<T> rai)
public static final <T extends net.imglib2.type.numeric.RealType<T>> ImgSource<T> intervalSource(net.imglib2.RandomAccessibleInterval<T> rai)
img(RandomAccessibleInterval), given that img is a widely used variable name.public static final NumberSource number(Number number)
public static final <T extends net.imglib2.type.numeric.RealType<T>> BlockReadSource<T> block(net.imglib2.RandomAccessible<T> src, long[] radius)
public static final <T extends net.imglib2.type.numeric.RealType<T>> BlockReadSource<T> block(net.imglib2.RandomAccessible<T> src, long radius)
public static final <T extends net.imglib2.type.numeric.RealType<T>> BlockReadSource<T> block(net.imglib2.RandomAccessible<T> src, long[][] corners)
public static final <T extends net.imglib2.type.numeric.RealType<T>> RandomAccessibleSource<T> offset(net.imglib2.RandomAccessible<T> src, long[] offset)
public static final <T extends net.imglib2.type.numeric.RealType<T>> OffsetSource<T> offset(IFunction f, long[] offset)
public static final <T extends net.imglib2.type.numeric.RealType<T>> IFunction source(net.imglib2.RandomAccessible<T> src)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(List<net.imglib2.Point> positions, T value, double radius)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(List<net.imglib2.Point> positions, T value, double radius, Object outside)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(List<net.imglib2.Point> positions, T value, double radius, Object outside, net.imglib2.Interval interval)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(List<net.imglib2.Point> positions, List<T> values, double radius)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(List<net.imglib2.Point> positions, List<T> values, double radius, Object outside)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(List<net.imglib2.Point> positions, List<T> values, double radius, Object outside, net.imglib2.Interval interval)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(net.imglib2.KDTree<T> kdtree, double radius)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(net.imglib2.KDTree<T> kdtree, double radius, Object outside)
public static final <T extends net.imglib2.type.numeric.RealType<T>> KDTreeSource<T> gen(net.imglib2.KDTree<T> kdtree, double radius, Object outside, net.imglib2.Interval interval)
Copyright © 2009–2025 ImgLib2. All rights reserved.