forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedfilt.cpp
More file actions
69 lines (57 loc) · 2.04 KB
/
medfilt.cpp
File metadata and controls
69 lines (57 loc) · 2.04 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
/*******************************************************
* Copyright (c) 2014, 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 <medfilt.hpp>
#include <Array.hpp>
#include <kernel/medfilt.hpp>
#include <platform.hpp>
#include <queue.hpp>
#include <af/dim4.hpp>
#include <functional>
using af::dim4;
namespace cpu {
template<typename T>
using medianFilter1 = std::function<void(Param<T>, CParam<T>, dim_t)>;
template<typename T>
using medianFilter2 = std::function<void(Param<T>, CParam<T>, dim_t, dim_t)>;
template<typename T>
Array<T> medfilt1(const Array<T> &in, const int w_wid,
const af::borderType pad) {
static const medianFilter1<T> funcs[2] = {
kernel::medfilt1<T, AF_PAD_ZERO>,
kernel::medfilt1<T, AF_PAD_SYM>,
};
Array<T> out = createEmptyArray<T>(in.dims());
getQueue().enqueue(funcs[static_cast<int>(pad)], out, in, w_wid);
return out;
}
template<typename T>
Array<T> medfilt2(const Array<T> &in, const int w_len, const int w_wid,
const af::borderType pad) {
static const medianFilter2<T> funcs[2] = {
kernel::medfilt2<T, AF_PAD_ZERO>,
kernel::medfilt2<T, AF_PAD_SYM>,
};
Array<T> out = createEmptyArray<T>(in.dims());
getQueue().enqueue(funcs[static_cast<int>(pad)], out, in, w_len, w_wid);
return out;
}
#define INSTANTIATE(T) \
template Array<T> medfilt1<T>(const Array<T> &in, const int w_wid, \
const af::borderType); \
template Array<T> medfilt2<T>(const Array<T> &in, const int w_len, \
const int w_wid, const af::borderType);
INSTANTIATE(float)
INSTANTIATE(double)
INSTANTIATE(char)
INSTANTIATE(int)
INSTANTIATE(uint)
INSTANTIATE(uchar)
INSTANTIATE(ushort)
INSTANTIATE(short)
} // namespace cpu