forked from hunter-packages/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdog.cpp
More file actions
72 lines (61 loc) · 2.49 KB
/
dog.cpp
File metadata and controls
72 lines (61 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*******************************************************
* Copyright (c) 2015, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <af/dim4.hpp>
#include <af/defines.h>
#include <af/vision.h>
#include <af/image.h>
#include <err_common.hpp>
#include <backend.hpp>
#include <handle.hpp>
#include <convolve.hpp>
#include <arith.hpp>
using af::dim4;
using namespace detail;
template<typename T, typename accT>
static af_array dog(const af_array& in, const int radius1, const int radius2)
{
af_array g1, g2;
g1 = g2 = 0;
AF_CHECK(af_gaussian_kernel(&g1, 2*radius1+1, 2*radius1+1, 0.0, 0.0));
AF_CHECK(af_gaussian_kernel(&g2, 2*radius2+1, 2*radius2+1, 0.0, 0.0));
Array<accT> input = castArray<accT>(in);
dim4 iDims = input.dims();
ConvolveBatchKind bkind = iDims[2] > 1 ? CONVOLVE_BATCH_SIGNAL : CONVOLVE_BATCH_NONE;
Array<accT> smth1 = convolve<accT, accT, 2, false>(input, castArray<accT>(g1), bkind);
Array<accT> smth2 = convolve<accT, accT, 2, false>(input, castArray<accT>(g2), bkind);
Array<accT> retVal= arithOp<accT, af_sub_t>(smth1, smth2, iDims);
AF_CHECK(af_release_array(g1));
AF_CHECK(af_release_array(g2));
return getHandle<accT>(retVal);
}
af_err af_dog(af_array *out, const af_array in, const int radius1, const int radius2)
{
try {
ArrayInfo info = getInfo(in);
dim4 inDims = info.dims();
ARG_ASSERT(1, (inDims.ndims()>=2));
ARG_ASSERT(1, (inDims.ndims()<=3));
af_array output;
af_dtype type = info.getType();
switch(type) {
case f32: output = dog<float , float>(in, radius1, radius2); break;
case f64: output = dog<double,double>(in, radius1, radius2); break;
case b8 : output = dog<char , float>(in, radius1, radius2); break;
case s32: output = dog<int , float>(in, radius1, radius2); break;
case u32: output = dog<uint , float>(in, radius1, radius2); break;
case s16: output = dog<short , float>(in, radius1, radius2); break;
case u16: output = dog<ushort, float>(in, radius1, radius2); break;
case u8 : output = dog<uchar , float>(in, radius1, radius2); break;
default : TYPE_ERROR(1, type);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}