|
45 | 45 | import net.imglib2.RealLocalizable; |
46 | 46 | import net.imglib2.RealRandomAccess; |
47 | 47 | import net.imglib2.RealRandomAccessible; |
| 48 | +import net.imglib2.img.Img; |
48 | 49 | import net.imglib2.img.ImgFactory; |
49 | 50 | import net.imglib2.img.array.ArrayImg; |
50 | 51 | import net.imglib2.img.array.ArrayImgFactory; |
51 | 52 | import net.imglib2.img.cell.CellImgFactory; |
52 | 53 | import net.imglib2.img.list.ListImgFactory; |
53 | 54 | import net.imglib2.type.NativeType; |
54 | 55 | import net.imglib2.type.Type; |
| 56 | +import net.imglib2.type.numeric.RealType; |
55 | 57 | import net.imglib2.type.operators.ValueEquals; |
56 | 58 | import net.imglib2.view.Views; |
57 | 59 |
|
58 | 60 | import java.util.List; |
59 | 61 | import java.util.function.BiPredicate; |
| 62 | +import java.util.stream.StreamSupport; |
60 | 63 |
|
61 | 64 | /** |
62 | 65 | * A collection of general-purpose utility methods for working with ImgLib2 data |
@@ -1003,4 +1006,30 @@ final static public void max( final double[] a, final double[] b ) |
1003 | 1006 | if ( b[ i ] > a[ i ] ) |
1004 | 1007 | a[ i ] = b[ i ]; |
1005 | 1008 | } |
| 1009 | + |
| 1010 | + /** |
| 1011 | + * Returns the content of {@code Iterable<RealType>} as array of doubles. |
| 1012 | + */ |
| 1013 | + public static double[] asDoubleArray( Iterable< ? extends RealType< ? > > iterable ) |
| 1014 | + { |
| 1015 | + return StreamSupport.stream( iterable.spliterator(), false ).mapToDouble( RealType::getRealDouble ).toArray(); |
| 1016 | + } |
| 1017 | + |
| 1018 | + /** |
| 1019 | + * Returns the pixels of an RandomAccessibleInterval of RealType as array of doubles. |
| 1020 | + * The pixels are sorted in flat iteration order. |
| 1021 | + */ |
| 1022 | + public static double[] asDoubleArray( RandomAccessibleInterval< ? extends RealType< ? > > rai ) |
| 1023 | + { |
| 1024 | + return asDoubleArray( Views.flatIterable( rai ) ); |
| 1025 | + } |
| 1026 | + |
| 1027 | + /** |
| 1028 | + * Returns the pixels of an image of RealType as array of doubles. |
| 1029 | + * The pixels are sorted in flat iteration order. |
| 1030 | + */ |
| 1031 | + public static double[] asDoubleArray( Img< ? extends RealType< ? > > image ) |
| 1032 | + { |
| 1033 | + return asDoubleArray( ( RandomAccessibleInterval< ? extends RealType< ? > > ) image ); |
| 1034 | + } |
1006 | 1035 | } |
0 commit comments