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 RandomAccessibleInterval<FloatType> computeIntoFloat(IFunction operation)
public static final <O extends RealType<O>> RandomAccessibleInterval<O> computeInto(IFunction operation, RandomAccessibleInterval<O> target)
public static final <O extends RealType<O>> RandomAccessibleInterval<O> computeInto(IFunction operation, RandomAccessibleInterval<O> target, Converter<RealType<?>,O> converter)
public static final GreaterThan GT(Object o1, Object o2)
public static final <T extends RealType<T>> ImgSource<T> img(RandomAccessibleInterval<T> rai)
public static final NumberSource number(Number number)
Copyright © 2009–2019 ImgLib2. All rights reserved.