Class Util
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe possible java array size is JVM dependent an actually slightly below Integer.MAX_VALUE. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]asDoubleArray(Iterable<? extends RealType<?>> iterable) Returns the content ofIterable<RealType>as array of doubles.static double[]asDoubleArray(RandomAccessibleInterval<? extends RealType<?>> rai) Returns the pixels of an RandomAccessibleInterval of RealType as array of doubles.static doubleaverage(double[] values) static floataverage(float[] values) static doubleaverageDouble(List<Double> values) static floataverageFloat(List<Float> values) static intcombineHash(int hash1, int hash2) static double[]createGaussianKernel1DDouble(double sigma, boolean normalize) This method creates a gaussian kernelstatic doubledistance(long[] position1, long[] position2) static doubledistance(RealLocalizable position1, RealLocalizable position2) static booleanequalIterationOrder(IterableInterval<?>... intervals) Checks whether nIterableIntervalhave the same iteration order.static int[]expandArray(int[] values, int newLength) Expand or truncate the provided array ofvaluesto lengthnewLength.static long[]expandArray(long[] values, int newLength) Expand or truncate the provided array ofvaluesto lengthnewLength.static <T> T[]genericArray(int length) Deprecated.static double[]getArrayFromValue(double value, int numDimensions) static float[]getArrayFromValue(float value, int numDimensions) static int[]getArrayFromValue(int value, int numDimensions) static long[]getArrayFromValue(long value, int numDimensions) static <T extends NativeType<T>>
ImgFactory<T> getArrayOrCellImgFactory(Dimensions targetSize, int targetCellSize, T type) static <T extends NativeType<T>>
ImgFactory<T> getArrayOrCellImgFactory(Dimensions targetSize, T type) static intgetSuggestedKernelDiameter(double sigma) static <T> ImgFactory<T> getSuitableImgFactory(Dimensions targetSize, T type) static <T, F extends Interval & RandomAccessible<T>>
TgetTypeFromInterval(F rai) Deprecated.static <T, F extends RealInterval & RealRandomAccessible<T>>
TgetTypeFromRealInterval(F rai) Deprecated.static doublegLog(double z, double c) static floatgLog(float z, float c) static doublegLogInv(double w, double c) static doublegLogInv(float w, float c) static <T extends ValueEquals<U>, U>
booleanimagesEqual(RandomAccessibleInterval<? extends T> a, RandomAccessibleInterval<? extends U> b) Checks if both images have equal intervals and content.static <T,U> boolean imagesEqual(RandomAccessibleInterval<? extends T> a, RandomAccessibleInterval<? extends U> b, BiPredicate<T, U> pixelEquals) Checks if both images have equal intervals and content.static final long[]int2long(int[] i) static booleanisApproxEqual(double a, double b, double threshold) static booleanisApproxEqual(float a, float b, float threshold) static final intldu(int v) (Hopefully) fast floor log2 of an unsigned(!) integer value.static booleanlocationsEqual(Localizable l1, Localizable l2) Determines whether the twoLocalizableobjects have the same position, withlongprecision.static booleanDetermines whether the twoRealLocalizableobjects have the same position, withdoubleprecision.static doublelog2(double value) static final int[]long2int(long[] a) static doublemax(double[] values) static final voidmax(double[] a, double[] b) Writes max(a,b) into astatic floatstatic <T extends Type<T> & Comparable<T>>
Tmax(T value1, T value2) static doublemedian(double[] values) static floatmedian(float[] values) static longmedian(long[] values) static doublemin(double[] values) static final voidmin(double[] a, double[] b) Writes min(a,b) into astatic floatstatic <T extends Type<T> & Comparable<T>>
Tmin(T value1, T value2) static doublepercentile(double[] values, double percentile) Computes the percentile of a collection of doubles (percentile 0.5 roughly corresponds to median)static intpow(int a, int b) static StringprintCoordinates(boolean[] value) static StringprintCoordinates(double[] value) static StringprintCoordinates(float[] value) static StringprintCoordinates(int[] value) static StringprintCoordinates(long[] value) static StringprintCoordinates(RealLocalizable localizable) static StringprintInterval(Interval interval) static voidquicksort(double[] data) static voidquicksort(double[] data, int[] sortAlso, int left, int right) static voidquicksort(double[] data, int left, int right) static voidquicksort(float[] data) static voidquicksort(float[] data, int left, int right) static voidquicksort(long[] data) static voidquicksort(long[] data, int left, int right) static longround(double value) static intround(float value) static introundToInt(double value) static introundToInt(float value) static longroundToLong(double value) static longroundToLong(float value) static intsafeInt(long value) Castvaluetoint, checking for overflow.static <T extends ValueEquals<T>>
booleanvalueEqualsObject(T a, Object b) This method should be used in implementations ofValueEquals, to overrideObject.equals(Object).
-
Field Details
-
MAX_ARRAY_SIZE
private static final int MAX_ARRAY_SIZEThe possible java array size is JVM dependent an actually slightly below Integer.MAX_VALUE. This is the same MAX_ARRAY_SIZE as used for example in ArrayList in OpenJDK8.- See Also:
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
genericArray
Deprecated.This does only work when T is erased to Object at call site.See https://github.com/imglib/imglib2/issues/253
-
log2
public static double log2(double value) -
getArrayFromValue
public static double[] getArrayFromValue(double value, int numDimensions) -
getArrayFromValue
public static float[] getArrayFromValue(float value, int numDimensions) -
getArrayFromValue
public static int[] getArrayFromValue(int value, int numDimensions) -
getArrayFromValue
public static long[] getArrayFromValue(long value, int numDimensions) -
expandArray
public static long[] expandArray(long[] values, int newLength) Expand or truncate the provided array ofvaluesto lengthnewLength.If
values.length < newLengththen the last value is repeated. That is, the remaining elements are filled withvalues[values.length - 1].If
values.length == newLengththenvaluesis returned, otherwise a new array is created.- Parameters:
values- values to copynewLength- length of expanded array- Returns:
- an array where
array.length == newLengthandarray[i] == values[Math.max(i, values.length)]
-
expandArray
public static int[] expandArray(int[] values, int newLength) Expand or truncate the provided array ofvaluesto lengthnewLength.If
values.length < newLengththen the last value is repeated. That is, the remaining elements are filled withvalues[values.length - 1].If
values.length == newLengththenvaluesis returned, otherwise a new array is created.- Parameters:
values- values to copynewLength- length of expanded array- Returns:
- an array where
array.length == newLengthandarray[i] == values[Math.max(i, values.length)]
-
distance
-
distance
public static double distance(long[] position1, long[] position2) -
percentile
public static double percentile(double[] values, double percentile) Computes the percentile of a collection of doubles (percentile 0.5 roughly corresponds to median)- Parameters:
values- - the valuespercentile- - the percentile [0...1]- Returns:
- the corresponding value
-
averageDouble
-
averageFloat
-
min
-
max
-
average
public static float average(float[] values) -
average
public static double average(double[] values) -
min
public static double min(double[] values) -
max
public static double max(double[] values) -
median
public static long median(long[] values) -
median
public static double median(double[] values) -
median
public static float median(float[] values) -
quicksort
public static void quicksort(long[] data) -
quicksort
public static void quicksort(long[] data, int left, int right) -
quicksort
public static void quicksort(double[] data) -
quicksort
public static void quicksort(double[] data, int left, int right) -
quicksort
public static void quicksort(float[] data) -
quicksort
public static void quicksort(float[] data, int left, int right) -
quicksort
public static void quicksort(double[] data, int[] sortAlso, int left, int right) -
gLog
public static double gLog(double z, double c) -
gLog
public static float gLog(float z, float c) -
gLogInv
public static double gLogInv(double w, double c) -
gLogInv
public static double gLogInv(float w, float c) -
isApproxEqual
public static boolean isApproxEqual(float a, float b, float threshold) -
isApproxEqual
public static boolean isApproxEqual(double a, double b, double threshold) -
round
public static int round(float value) -
round
public static long round(double value) -
roundToInt
public static int roundToInt(float value) -
roundToInt
public static int roundToInt(double value) -
roundToLong
public static long roundToLong(float value) -
roundToLong
public static long roundToLong(double value) -
createGaussianKernel1DDouble
public static double[] createGaussianKernel1DDouble(double sigma, boolean normalize) This method creates a gaussian kernel- Parameters:
sigma- Standard Derivation of the gaussian functionnormalize- Normalize integral of gaussian function to 1 or not...- Returns:
- double[] The gaussian kernel
-
getSuggestedKernelDiameter
public static int getSuggestedKernelDiameter(double sigma) -
printCoordinates
-
printCoordinates
-
printCoordinates
-
printInterval
-
printCoordinates
-
printCoordinates
-
printCoordinates
-
pow
public static int pow(int a, int b) -
max
-
min
-
long2int
public static final int[] long2int(long[] a) -
int2long
public static final long[] int2long(int[] i) -
safeInt
public static int safeInt(long value) Castvaluetoint, checking for overflow.- Parameters:
value- value to cast toint- Returns:
valuecast toint- Throws:
IllegalArgumentException- ifvalue > Integer.MAX_VALUE
-
getTypeFromInterval
@Deprecated public static <T, F extends Interval & RandomAccessible<T>> T getTypeFromInterval(F rai) Deprecated.This method has been deprecated. UseTyped.getType()instead. TODO: Cannot deprecate because rai parameter is not actually a RandomAccessibleInterval Gets an instance of T from theRandomAccessibleIntervalby querying the value at the min coordinate- Type Parameters:
T- - the T- Parameters:
rai- - theRandomAccessibleInterval- Returns:
- - an instance of T
-
getTypeFromRealInterval
@Deprecated public static <T, F extends RealInterval & RealRandomAccessible<T>> T getTypeFromRealInterval(F rai) Deprecated.Gets an instance of T from theRandomAccessibleIntervalby querying the value at the min coordinate- Type Parameters:
T- - the T- Parameters:
rai- - theRandomAccessibleInterval- Returns:
- - an instance of T
-
getArrayOrCellImgFactory
public static <T extends NativeType<T>> ImgFactory<T> getArrayOrCellImgFactory(Dimensions targetSize, T type) Create anArrayImgFactoryif an image of the requestedtargetSizecould be held in anArrayImg. Otherwise return aCellImgFactorywith as large as possible cell size.- Parameters:
targetSize- size of image that the factory should be able to create.type- type of the factory.- Returns:
- an
ArrayImgFactoryor aCellImgFactory.
-
getArrayOrCellImgFactory
public static <T extends NativeType<T>> ImgFactory<T> getArrayOrCellImgFactory(Dimensions targetSize, int targetCellSize, T type) Create anArrayImgFactoryif an image of the requestedtargetSizecould be held in anArrayImg. Otherwise return aCellImgFactorywith cell sizetargetCellSize(or as large as possible iftargetCellSizeis too large).- Parameters:
targetSize- size of image that the factory should be able to create.targetCellSize- if aCellImgFactoryis created, what should be the cell size.type- type of the factory.- Returns:
- an
ArrayImgFactoryor aCellImgFactory.
-
getSuitableImgFactory
Create an appropriateImgFactoryfor the requestedtargetSizeandtype. If the target size is aImg, return itsImgFactory. If the type is aNativeType, thengetArrayOrCellImgFactory(Dimensions, NativeType)is used; if not, aListImgFactoryis returned.- Parameters:
targetSize- size of image that the factory should be able to create.type- type of the factory.- Returns:
- an
ArrayImgFactory,CellImgFactoryorListImgFactoryas appropriate.
-
ldu
public static final int ldu(int v) (Hopefully) fast floor log2 of an unsigned(!) integer value.- Parameters:
v- unsigned integer- Returns:
- floor log2
-
equalIterationOrder
Checks whether nIterableIntervalhave the same iteration order. -
locationsEqual
Determines whether the twoLocalizableobjects have the same position, withlongprecision.At first glance, this method may appear to be unnecessary, since there is also
locationsEqual(RealLocalizable, RealLocalizable), which is more general. The difference is that this method compares the positions usingLocalizable.getLongPosition(int), which has higher precision in integer space thanRealLocalizable.getDoublePosition(int)does, which is what thelocationsEqual(RealLocalizable, RealLocalizable)method uses.- Parameters:
l1- The firstLocalizable.l2- The secondLocalizable.- Returns:
- True iff the positions are the same, including dimensionality.
- See Also:
-
locationsEqual
Determines whether the twoRealLocalizableobjects have the same position, withdoubleprecision.- Parameters:
l1- The firstRealLocalizable.l2- The secondRealLocalizable.- Returns:
- True iff the positions are the same, including dimensionality.
- See Also:
-
imagesEqual
public static <T extends ValueEquals<U>, U> boolean imagesEqual(RandomAccessibleInterval<? extends T> a, RandomAccessibleInterval<? extends U> b) Checks if both images have equal intervals and content. -
imagesEqual
public static <T,U> boolean imagesEqual(RandomAccessibleInterval<? extends T> a, RandomAccessibleInterval<? extends U> b, BiPredicate<T, U> pixelEquals) Checks if both images have equal intervals and content. A predicate must be given to check if two pixels are equal. -
min
public static final void min(double[] a, double[] b) Writes min(a,b) into a- Parameters:
a-b-
-
max
public static final void max(double[] a, double[] b) Writes max(a,b) into a- Parameters:
a-b-
-
asDoubleArray
-
asDoubleArray
Returns the pixels of an RandomAccessibleInterval of RealType as array of doubles. The pixels are sorted in flat iteration order. -
valueEqualsObject
This method should be used in implementations ofValueEquals, to overrideObject.equals(Object).- See Also:
-
combineHash
public static int combineHash(int hash1, int hash2)
-