def samplerConvert(rai, converter): """ rai: an instance of RandomAccessibleInterval converter: an instance of a SamplerConverter. """ # Grab method through reflection. Otherwise we get one that returns an IterableInterval # which is not compatible with ImageJFunctions.wrap methods. m = Converters.getDeclaredMethod( "convert", [RandomAccessibleInterval, SamplerConverter]) return m.invoke(None, rai, converter)
def convert2(rai, converter, toType, randomAccessible=True): """ rai: an instance of RandomAccessibleInterval converter: as created with e.g. createConverter toType: class of the target Type randomAccessible: when True (default) use RandomAccessibleInterval, otherwise use IterableInterval """ # Grab method through reflection. Otherwise we get one that returns an IterableInterval # which is not compatible with ImageJFunctions.wrap methods. m = Converters.getDeclaredMethod("convert", [ RandomAccessibleInterval if randomAccessible else IterableInterval, Converter, ImgLib2Type ]) return m.invoke(None, rai, converter, toType.newInstance())