- 操作系統:ubuntu22.04
- OpenCV版本:OpenCV4.9
- IDE:Visual Studio Code
- 編程語言:C++11
算法描述
對輸入的 uchar1 像素值(范圍 [0, 255]),先歸一化到 [0.0, 1.0] 浮點區間,然后計算其 反雙曲正切函數 atanh(x),最終返回一個 float1 類型的結果。
函數原型
__device__ __forceinline__ float1 cv::cudev::atanh ( const uchar1 & a )
參數
- uchar1 CUDA 向量類型,表示一個單通道 8 位無符號整型(等價于 unsigned char 或 uint8_t)。
代碼示例
#include <opencv2/cudev/common.hpp>
#include <cstdio>
#include <cmath> // for atanhf// 手動實現 atan2f 并做邊界保護
__device__ __forceinline__ float safe_atanh(float x) {if (x <= -1.0f) return -1.0e+37f; // -infif (x >= 1.0f) return +1.0e+37f; // +infreturn atanhf(x);
}__global__ void test_atanh() {uchar1 a = make_uchar1(128); // 輸入一個像素值float normalized = a.x / 255.0f;// 安全處理if (normalized >= 1.0f) normalized = 0.999999f;if (normalized <= 0.0f) normalized = 0.000001f;float result = safe_atanh(normalized);printf("atanh(%f) = %f\n", normalized, result);
}int main() {test_atanh<<<1, 1>>>();cudaDeviceReset();return 0;
}
運行結果
atanh(0.501961) = 0.551924