Skip to content

Commit dd296be

Browse files
committed
update api
1 parent 736c62d commit dd296be

18 files changed

Lines changed: 438 additions & 245 deletions

File tree

include/af/image.h

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -339,40 +339,6 @@ AFAPI array histogram(const array &in, const unsigned nbins);
339339
*/
340340
AFAPI array meanShift(const array& in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color=false);
341341

342-
/**
343-
C++ Interface for median filter
344-
345-
\snippet test/medfilt.cpp ex_image_medfilt
346-
347-
\param[in] in array is the input image
348-
\param[in] wind_length is the kernel height
349-
\param[in] wind_width is the kernel width
350-
\param[in] edge_pad value will decide what happens to border when running
351-
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
352-
\return the processed image
353-
354-
\ingroup image_func_medfilt
355-
*/
356-
AFAPI array medfilt(const array& in, const dim_t wind_length = 3, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
357-
358-
#if AF_API_VERSION >= 34
359-
/**
360-
C++ Interface for median filter
361-
362-
\snippet test/medfilt.cpp ex_image_medfilt
363-
364-
\param[in] in array is the input signal
365-
\param[in] wind_width is the kernel width
366-
\param[in] edge_pad value will decide what happens to border when running
367-
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
368-
\return the processed signal
369-
370-
\ingroup image_func_medfilt
371-
*/
372-
AFAPI array medfilt_1d(const array& in, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
373-
374-
#endif
375-
376342
/**
377343
C++ Interface for minimum filter
378344
@@ -1072,39 +1038,6 @@ extern "C" {
10721038
*/
10731039
AFAPI af_err af_mean_shift(af_array *out, const af_array in, const float spatial_sigma, const float chromatic_sigma, const unsigned iter, const bool is_color);
10741040

1075-
/**
1076-
C Interface for median filter
1077-
1078-
\param[out] out array is the processed image
1079-
\param[in] in array is the input image
1080-
\param[in] wind_length is the kernel height
1081-
\param[in] wind_width is the kernel width
1082-
\param[in] edge_pad value will decide what happens to border when running
1083-
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
1084-
\return \ref AF_SUCCESS if the median filter is applied successfully,
1085-
otherwise an appropriate error code is returned.
1086-
1087-
\ingroup image_func_medfilt
1088-
*/
1089-
AFAPI af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad);
1090-
1091-
#if AF_API_VERSION >= 34
1092-
/**
1093-
C Interface for 1D median filter
1094-
1095-
\param[out] out array is the processed signal
1096-
\param[in] in array is the input signal
1097-
\param[in] wind_width is the kernel width
1098-
\param[in] edge_pad value will decide what happens to border when running
1099-
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
1100-
\return \ref AF_SUCCESS if the median filter is applied successfully,
1101-
otherwise an appropriate error code is returned.
1102-
1103-
\ingroup image_func_medfilt
1104-
*/
1105-
AFAPI af_err af_medfilt_1d(af_array *out, const af_array in, const dim_t wind_width, const af_border_type edge_pad);
1106-
1107-
#endif
11081041
/**
11091042
C Interface for minimum filter
11101043

include/af/signal.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,57 @@ AFAPI array fir(const array &b, const array &x);
603603
*/
604604
AFAPI array iir(const array &b, const array &a, const array &x);
605605

606+
/**
607+
C++ Interface for median filter
608+
609+
\snippet test/medfilt.cpp ex_image_medfilt
610+
611+
\param[in] in array is the input image
612+
\param[in] wind_length is the kernel height
613+
\param[in] wind_width is the kernel width
614+
\param[in] edge_pad value will decide what happens to border when running
615+
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
616+
\return the processed image
617+
618+
\ingroup image_func_medfilt
619+
*/
620+
AFAPI array medfilt(const array& in, const dim_t wind_length = 3, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
621+
622+
#if AF_API_VERSION >= 34
623+
/**
624+
C++ Interface for median filter
625+
626+
\snippet test/medfilt.cpp ex_image_medfilt
627+
628+
\param[in] in array is the input signal
629+
\param[in] wind_width is the kernel width
630+
\param[in] edge_pad value will decide what happens to border when running
631+
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
632+
\return the processed signal
633+
634+
\ingroup image_func_medfilt
635+
*/
636+
AFAPI array medfilt1(const array& in, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
637+
#endif
638+
639+
#if AF_API_VERSION >= 34
640+
/**
641+
C++ Interface for median filter
642+
643+
\snippet test/medfilt.cpp ex_image_medfilt
644+
645+
\param[in] in array is the input image
646+
\param[in] wind_length is the kernel height
647+
\param[in] wind_width is the kernel width
648+
\param[in] edge_pad value will decide what happens to border when running
649+
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
650+
\return the processed image
651+
652+
\ingroup image_func_medfilt
653+
*/
654+
AFAPI array medfilt2(const array& in, const dim_t wind_length = 3, const dim_t wind_width = 3, const borderType edge_pad = AF_PAD_ZERO);
655+
#endif
656+
606657
}
607658
#endif
608659

@@ -1079,6 +1130,58 @@ AFAPI af_err af_fir(af_array *y, const af_array b, const af_array x);
10791130
*/
10801131
AFAPI af_err af_iir(af_array *y, const af_array b, const af_array a, const af_array x);
10811132

1133+
/**
1134+
C Interface for median filter
1135+
1136+
\param[out] out array is the processed image
1137+
\param[in] in array is the input image
1138+
\param[in] wind_length is the kernel height
1139+
\param[in] wind_width is the kernel width
1140+
\param[in] edge_pad value will decide what happens to border when running
1141+
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
1142+
\return \ref AF_SUCCESS if the median filter is applied successfully,
1143+
otherwise an appropriate error code is returned.
1144+
1145+
\ingroup image_func_medfilt
1146+
*/
1147+
AFAPI af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad);
1148+
1149+
#if AF_API_VERSION >= 34
1150+
/**
1151+
C Interface for 1D median filter
1152+
1153+
\param[out] out array is the processed signal
1154+
\param[in] in array is the input signal
1155+
\param[in] wind_width is the kernel width
1156+
\param[in] edge_pad value will decide what happens to border when running
1157+
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
1158+
\return \ref AF_SUCCESS if the median filter is applied successfully,
1159+
otherwise an appropriate error code is returned.
1160+
1161+
\ingroup image_func_medfilt
1162+
*/
1163+
AFAPI af_err af_medfilt1(af_array *out, const af_array in, const dim_t wind_width, const af_border_type edge_pad);
1164+
#endif
1165+
1166+
#if AF_API_VERSION >= 34
1167+
/**
1168+
C Interface for median filter
1169+
1170+
\param[out] out array is the processed image
1171+
\param[in] in array is the input image
1172+
\param[in] wind_length is the kernel height
1173+
\param[in] wind_width is the kernel width
1174+
\param[in] edge_pad value will decide what happens to border when running
1175+
filter in their neighborhood. It takes one of the values [\ref AF_PAD_ZERO | \ref AF_PAD_SYM]
1176+
\return \ref AF_SUCCESS if the median filter is applied successfully,
1177+
otherwise an appropriate error code is returned.
1178+
1179+
\ingroup image_func_medfilt
1180+
*/
1181+
AFAPI af_err af_medfilt2(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad);
1182+
#endif
1183+
1184+
10821185
#if AF_API_VERSION >= 34
10831186
/**
10841187
C Interface for setting plan cache size

src/api/c/filters.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <af/dim4.hpp>
1111
#include <af/defines.h>
1212
#include <af/image.h>
13+
#include <af/signal.h>
1314
#include <af/data.h>
1415
#include <handle.hpp>
1516
#include <err_common.hpp>
@@ -19,44 +20,47 @@
1920
using af::dim4;
2021
using namespace detail;
2122

23+
af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
24+
{
25+
return af_medfilt2(out, in, wind_length, wind_width, edge_pad);
26+
}
27+
2228
template<typename T>
23-
static af_array medfilt(af_array const &in, dim_t w_len, dim_t w_wid, af_border_type edge_pad)
29+
static af_array medfilt1(af_array const &in, dim_t w_wid, af_border_type edge_pad)
2430
{
2531
switch(edge_pad) {
26-
case AF_PAD_ZERO : return getHandle<T>(medfilt<T, AF_PAD_ZERO>(getArray<T>(in), w_len, w_wid)); break;
27-
case AF_PAD_SYM : return getHandle<T>(medfilt<T, AF_PAD_SYM >(getArray<T>(in), w_len, w_wid)); break;
28-
default : return getHandle<T>(medfilt<T, AF_PAD_ZERO>(getArray<T>(in), w_len, w_wid)); break;
32+
case AF_PAD_ZERO : return getHandle<T>(medfilt1<T, AF_PAD_ZERO>(getArray<T>(in), w_wid)); break;
33+
case AF_PAD_SYM : return getHandle<T>(medfilt1<T, AF_PAD_SYM >(getArray<T>(in), w_wid)); break;
34+
default : return getHandle<T>(medfilt1<T, AF_PAD_ZERO>(getArray<T>(in), w_wid)); break;
2935
}
3036
}
3137

32-
af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
38+
af_err af_medfilt1(af_array *out, const af_array in, const dim_t wind_width, const af_border_type edge_pad)
3339
{
3440
try {
35-
ARG_ASSERT(2, (wind_length==wind_width));
36-
ARG_ASSERT(2, (wind_length>0));
37-
ARG_ASSERT(3, (wind_width>0));
41+
ARG_ASSERT(2, (wind_width>0));
3842
ARG_ASSERT(4, (edge_pad>=AF_PAD_ZERO && edge_pad<=AF_PAD_SYM));
3943

4044
ArrayInfo info = getInfo(in);
4145
af::dim4 dims = info.dims();
4246

4347
dim_t input_ndims = dims.ndims();
44-
DIM_ASSERT(1, (input_ndims >= 2));
48+
DIM_ASSERT(1, (input_ndims >= 1));
4549

46-
if (wind_length==1) {
50+
if (wind_width==1) {
4751
*out = retain(in);
4852
} else {
4953
af_array output;
5054
af_dtype type = info.getType();
5155
switch(type) {
52-
case f32: output = medfilt<float >(in, wind_length, wind_width, edge_pad); break;
53-
case f64: output = medfilt<double>(in, wind_length, wind_width, edge_pad); break;
54-
case b8 : output = medfilt<char >(in, wind_length, wind_width, edge_pad); break;
55-
case s32: output = medfilt<int >(in, wind_length, wind_width, edge_pad); break;
56-
case u32: output = medfilt<uint >(in, wind_length, wind_width, edge_pad); break;
57-
case s16: output = medfilt<short >(in, wind_length, wind_width, edge_pad); break;
58-
case u16: output = medfilt<ushort>(in, wind_length, wind_width, edge_pad); break;
59-
case u8 : output = medfilt<uchar >(in, wind_length, wind_width, edge_pad); break;
56+
case f32: output = medfilt1<float >(in, wind_width, edge_pad); break;
57+
case f64: output = medfilt1<double>(in, wind_width, edge_pad); break;
58+
case b8 : output = medfilt1<char >(in, wind_width, edge_pad); break;
59+
case s32: output = medfilt1<int >(in, wind_width, edge_pad); break;
60+
case u32: output = medfilt1<uint >(in, wind_width, edge_pad); break;
61+
case s16: output = medfilt1<short >(in, wind_width, edge_pad); break;
62+
case u16: output = medfilt1<ushort>(in, wind_width, edge_pad); break;
63+
case u8 : output = medfilt1<uchar >(in, wind_width, edge_pad); break;
6064
default : TYPE_ERROR(1, type);
6165
}
6266
std::swap(*out, output);
@@ -68,41 +72,43 @@ af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, con
6872
}
6973

7074
template<typename T>
71-
static af_array medfilt_1d(af_array const &in, dim_t w_wid, af_border_type edge_pad)
75+
static af_array medfilt2(af_array const &in, dim_t w_len, dim_t w_wid, af_border_type edge_pad)
7276
{
7377
switch(edge_pad) {
74-
case AF_PAD_ZERO : return getHandle<T>(medfilt_1d<T, AF_PAD_ZERO>(getArray<T>(in), w_wid)); break;
75-
case AF_PAD_SYM : return getHandle<T>(medfilt_1d<T, AF_PAD_SYM >(getArray<T>(in), w_wid)); break;
76-
default : return getHandle<T>(medfilt_1d<T, AF_PAD_ZERO>(getArray<T>(in), w_wid)); break;
78+
case AF_PAD_ZERO : return getHandle<T>(medfilt2<T, AF_PAD_ZERO>(getArray<T>(in), w_len, w_wid)); break;
79+
case AF_PAD_SYM : return getHandle<T>(medfilt2<T, AF_PAD_SYM >(getArray<T>(in), w_len, w_wid)); break;
80+
default : return getHandle<T>(medfilt2<T, AF_PAD_ZERO>(getArray<T>(in), w_len, w_wid)); break;
7781
}
7882
}
7983

80-
af_err af_medfilt_1d(af_array *out, const af_array in, const dim_t wind_width, const af_border_type edge_pad)
84+
af_err af_medfilt2(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
8185
{
8286
try {
83-
ARG_ASSERT(2, (wind_width>0));
87+
ARG_ASSERT(2, (wind_length==wind_width));
88+
ARG_ASSERT(2, (wind_length>0));
89+
ARG_ASSERT(3, (wind_width>0));
8490
ARG_ASSERT(4, (edge_pad>=AF_PAD_ZERO && edge_pad<=AF_PAD_SYM));
8591

8692
ArrayInfo info = getInfo(in);
8793
af::dim4 dims = info.dims();
8894

8995
dim_t input_ndims = dims.ndims();
90-
DIM_ASSERT(1, (input_ndims >= 1));
96+
DIM_ASSERT(1, (input_ndims >= 2));
9197

92-
if (wind_width==1) {
98+
if (wind_length==1) {
9399
*out = retain(in);
94100
} else {
95101
af_array output;
96102
af_dtype type = info.getType();
97103
switch(type) {
98-
case f32: output = medfilt_1d<float >(in, wind_width, edge_pad); break;
99-
case f64: output = medfilt_1d<double>(in, wind_width, edge_pad); break;
100-
case b8 : output = medfilt_1d<char >(in, wind_width, edge_pad); break;
101-
case s32: output = medfilt_1d<int >(in, wind_width, edge_pad); break;
102-
case u32: output = medfilt_1d<uint >(in, wind_width, edge_pad); break;
103-
case s16: output = medfilt_1d<short >(in, wind_width, edge_pad); break;
104-
case u16: output = medfilt_1d<ushort>(in, wind_width, edge_pad); break;
105-
case u8 : output = medfilt_1d<uchar >(in, wind_width, edge_pad); break;
104+
case f32: output = medfilt2<float >(in, wind_length, wind_width, edge_pad); break;
105+
case f64: output = medfilt2<double>(in, wind_length, wind_width, edge_pad); break;
106+
case b8 : output = medfilt2<char >(in, wind_length, wind_width, edge_pad); break;
107+
case s32: output = medfilt2<int >(in, wind_length, wind_width, edge_pad); break;
108+
case u32: output = medfilt2<uint >(in, wind_length, wind_width, edge_pad); break;
109+
case s16: output = medfilt2<short >(in, wind_length, wind_width, edge_pad); break;
110+
case u16: output = medfilt2<ushort>(in, wind_length, wind_width, edge_pad); break;
111+
case u8 : output = medfilt2<uchar >(in, wind_length, wind_width, edge_pad); break;
106112
default : TYPE_ERROR(1, type);
107113
}
108114
std::swap(*out, output);

src/api/cpp/filters.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@
88
********************************************************/
99

1010
#include <af/image.h>
11+
#include <af/signal.h>
1112
#include <af/array.h>
1213
#include "error.hpp"
1314

1415
namespace af
1516
{
1617

1718
array medfilt(const array& in, const dim_t wind_length, const dim_t wind_width, const borderType edge_pad)
19+
{
20+
return medfilt2(in, wind_length, wind_width, edge_pad);
21+
}
22+
23+
array medfilt1(const array& in, const dim_t wind_width, const borderType edge_pad)
1824
{
1925
af_array out = 0;
20-
AF_THROW(af_medfilt(&out, in.get(), wind_length, wind_width, edge_pad));
26+
AF_THROW(af_medfilt1(&out, in.get(), wind_width, edge_pad));
2127
return array(out);
2228
}
2329

24-
array medfilt_1d(const array& in, const dim_t wind_width, const borderType edge_pad)
30+
array medfilt2(const array& in, const dim_t wind_length, const dim_t wind_width, const borderType edge_pad)
2531
{
2632
af_array out = 0;
27-
AF_THROW(af_medfilt_1d(&out, in.get(), wind_width, edge_pad));
33+
AF_THROW(af_medfilt2(&out, in.get(), wind_length, wind_width, edge_pad));
2834
return array(out);
2935
}
3036

src/api/unified/image.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,6 @@ af_err af_mean_shift(af_array *out, const af_array in, const float spatial_sigma
152152
return CALL(out, in, spatial_sigma, chromatic_sigma, iter, is_color);
153153
}
154154

155-
af_err af_medfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
156-
{
157-
CHECK_ARRAYS(in);
158-
return CALL(out, in, wind_length, wind_width, edge_pad);
159-
}
160-
161-
af_err af_medfilt_1d(af_array *out, const af_array in, const dim_t wind_width, const af_border_type edge_pad)
162-
{
163-
CHECK_ARRAYS(in);
164-
return CALL(out, in, wind_width, edge_pad);
165-
}
166-
167155
af_err af_minfilt(af_array *out, const af_array in, const dim_t wind_length, const dim_t wind_width, const af_border_type edge_pad)
168156
{
169157
CHECK_ARRAYS(in);

0 commit comments

Comments
 (0)