本文整理汇总了Java中org.joml.Math.exp方法的典型用法代码示例。如果您正苦于以下问题:Java Math.exp方法的具体用法?Java Math.exp怎么用?Java Math.exp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joml.Math
的用法示例。
在下文中一共展示了Math.exp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gaussianKernel
import org.joml.Math; //导入方法依赖的package包/类
/**
* Generate a Gaussian convolution kernel with the given number of rows and columns, and store
* the factors in row-major order in <code>dest</code>.
*
* @param rows
* the number of rows (must be an odd number)
* @param cols
* the number of columns (must be an odd number)
* @param sigma
* determines how big the factors are at the center of distribution
* @param dest
* will hold the kernel factors in row-major order
*/
public static void gaussianKernel(int rows, int cols, float sigma, float[] dest) {
if ((rows & 1) == 0) {
throw new IllegalArgumentException("rows must be an odd number");
}
if ((cols & 1) == 0) {
throw new IllegalArgumentException("cols must be an odd number");
}
if (dest == null) {
throw new IllegalArgumentException("dest must not be null");
}
if (dest.length < rows * cols) {
throw new IllegalArgumentException("dest must have at least " + (rows * cols) + " remaining values");
}
float sum = 0.0f;
for (int i = 0, y = -(rows - 1) / 2; y <= (rows - 1) / 2; y++) {
for (int x = -(cols - 1) / 2; x <= (cols - 1) / 2; x++, i++) {
float k = (float) Math.exp(-(y * y + x * x) / (2.0 * sigma * sigma));
dest[i] = k;
sum += k;
}
}
for (int i = 0; i < rows * cols; i++) {
dest[i] = dest[i] / sum;
}
}