Path: blob/master/modules/features2d/src/opencl/akaze.cl
16339 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html345/**6* @brief This function computes the Perona and Malik conductivity coefficient g27* g2 = 1 / (1 + dL^2 / k^2)8* @param lx First order image derivative in X-direction (horizontal)9* @param ly First order image derivative in Y-direction (vertical)10* @param dst Output image11* @param k Contrast factor parameter12*/13__kernel void14AKAZE_pm_g2(__global const float* lx, __global const float* ly, __global float* dst,15float k, int size)16{17int i = get_global_id(0);18// OpenCV plays with dimensions so we need explicit check for this19if (!(i < size))20{21return;22}2324const float k2inv = 1.0f / (k * k);25dst[i] = 1.0f / (1.0f + ((lx[i] * lx[i] + ly[i] * ly[i]) * k2inv));26}2728__kernel void29AKAZE_nld_step_scalar(__global const float* lt, int lt_step, int lt_offset, int rows, int cols,30__global const float* lf, __global float* dst, float step_size)31{32/* The labeling scheme for this five star stencil:33[ a ]34[ -1 c +1 ]35[ b ]36*/37// column-first indexing38int i = get_global_id(1);39int j = get_global_id(0);4041// OpenCV plays with dimensions so we need explicit check for this42if (!(i < rows && j < cols))43{44return;45}4647// get row indexes48int a = (i - 1) * cols;49int c = (i ) * cols;50int b = (i + 1) * cols;51// compute stencil52float res = 0.0f;53if (i == 0) // first rows54{55if (j == 0 || j == (cols - 1))56{57res = 0.0f;58} else59{60res = (lf[c + j] + lf[c + j + 1])*(lt[c + j + 1] - lt[c + j]) +61(lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +62(lf[c + j] + lf[b + j ])*(lt[b + j ] - lt[c + j]);63}64} else if (i == (rows - 1)) // last row65{66if (j == 0 || j == (cols - 1))67{68res = 0.0f;69} else70{71res = (lf[c + j] + lf[c + j + 1])*(lt[c + j + 1] - lt[c + j]) +72(lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +73(lf[c + j] + lf[a + j ])*(lt[a + j ] - lt[c + j]);74}75} else // inner rows76{77if (j == 0) // first column78{79res = (lf[c + 0] + lf[c + 1])*(lt[c + 1] - lt[c + 0]) +80(lf[c + 0] + lf[b + 0])*(lt[b + 0] - lt[c + 0]) +81(lf[c + 0] + lf[a + 0])*(lt[a + 0] - lt[c + 0]);82} else if (j == (cols - 1)) // last column83{84res = (lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +85(lf[c + j] + lf[b + j ])*(lt[b + j ] - lt[c + j]) +86(lf[c + j] + lf[a + j ])*(lt[a + j ] - lt[c + j]);87} else // inner stencil88{89res = (lf[c + j] + lf[c + j + 1])*(lt[c + j + 1] - lt[c + j]) +90(lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +91(lf[c + j] + lf[b + j ])*(lt[b + j ] - lt[c + j]) +92(lf[c + j] + lf[a + j ])*(lt[a + j ] - lt[c + j]);93}94}9596dst[c + j] = res * step_size;97}9899/**100* @brief Compute determinant from hessians101* @details Compute Ldet by (Lxx.mul(Lyy) - Lxy.mul(Lxy)) * sigma102*103* @param lxx spatial derivates104* @param lxy spatial derivates105* @param lyy spatial derivates106* @param dst output determinant107* @param sigma determinant will be scaled by this sigma108*/109__kernel void110AKAZE_compute_determinant(__global const float* lxx, __global const float* lxy, __global const float* lyy,111__global float* dst, float sigma, int size)112{113int i = get_global_id(0);114// OpenCV plays with dimensions so we need explicit check for this115if (!(i < size))116{117return;118}119120dst[i] = (lxx[i] * lyy[i] - lxy[i] * lxy[i]) * sigma;121}122123124