[python-arrayfire] 43/58: Adding medfilt1 and medfilt2 and necessary tests

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Sep 28 13:57:08 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository python-arrayfire.

commit 208465d1cd72542922876e6ed897765137871661
Author: Pavan Yalamanchili <contact at pavanky.com>
Date:   Fri Sep 23 14:46:22 2016 -0700

    Adding medfilt1 and medfilt2 and necessary tests
---
 arrayfire/image.py               | 33 +--------------
 arrayfire/signal.py              | 91 ++++++++++++++++++++++++++++++++++++++++
 arrayfire/tests/simple/signal.py |  4 ++
 3 files changed, 96 insertions(+), 32 deletions(-)

diff --git a/arrayfire/image.py b/arrayfire/image.py
index 842ce22..7ddb6de 100644
--- a/arrayfire/image.py
+++ b/arrayfire/image.py
@@ -14,6 +14,7 @@ Image processing functions.
 from .library import *
 from .array import *
 from .data import constant
+from .signal import medfilt
 import os
 
 def gradient(image):
@@ -619,38 +620,6 @@ def mean_shift(image, s_sigma, c_sigma, n_iter, is_color = False):
                                           ct.c_uint(n_iter), is_color))
     return output
 
-def medfilt(image, w0 = 3, w1 = 3, edge_pad = PAD.ZERO):
-    """
-    Apply median filter for the image.
-
-    Parameters
-    ----------
-    image : af.Array
-          - A 2 D arrayfire array representing an image, or
-          - A multi dimensional array representing batch of images.
-
-    w0 : optional: int. default: 3.
-          - The length of the filter along the first dimension.
-
-    w1 : optional: int. default: 3.
-          - The length of the filter along the second dimension.
-
-    edge_pad : optional: af.PAD. default: af.PAD.ZERO
-          - Flag specifying how the median at the edge should be treated.
-
-    Returns
-    ---------
-
-    output : af.Array
-           - The image after median filter is applied.
-
-    """
-    output = Array()
-    safe_call(backend.get().af_medfilt(ct.pointer(output.arr),
-                                       image.arr, c_dim_t(w0),
-                                       c_dim_t(w1), edge_pad.value))
-    return output
-
 def minfilt(image, w_len = 3, w_wid = 3, edge_pad = PAD.ZERO):
     """
     Apply min filter for the image.
diff --git a/arrayfire/signal.py b/arrayfire/signal.py
index 78f2c6f..363ed24 100644
--- a/arrayfire/signal.py
+++ b/arrayfire/signal.py
@@ -1265,6 +1265,97 @@ def iir(B, A, X):
     safe_call(backend.get().af_iir(ct.pointer(Y.arr), B.arr, A.arr, X.arr))
     return Y
 
+def medfilt(signal, w0 = 3, w1 = 3, edge_pad = PAD.ZERO):
+    """
+    Apply median filter for the signal.
+
+    Parameters
+    ----------
+    signal : af.Array
+          - A 2 D arrayfire array representing a signal, or
+          - A multi dimensional array representing batch of signals.
+
+    w0 : optional: int. default: 3.
+          - The length of the filter along the first dimension.
+
+    w1 : optional: int. default: 3.
+          - The length of the filter along the second dimension.
+
+    edge_pad : optional: af.PAD. default: af.PAD.ZERO
+          - Flag specifying how the median at the edge should be treated.
+
+    Returns
+    ---------
+
+    output : af.Array
+           - The signal after median filter is applied.
+
+    """
+    output = Array()
+    safe_call(backend.get().af_medfilt(ct.pointer(output.arr),
+                                       signal.arr, c_dim_t(w0),
+                                       c_dim_t(w1), edge_pad.value))
+    return output
+
+def medfilt1(signal, length = 3, edge_pad = PAD.ZERO):
+    """
+    Apply median filter for the signal.
+
+    Parameters
+    ----------
+    signal : af.Array
+          - A 1 D arrayfire array representing a signal, or
+          - A multi dimensional array representing batch of signals.
+
+    length : optional: int. default: 3.
+          - The length of the filter.
+
+    edge_pad : optional: af.PAD. default: af.PAD.ZERO
+          - Flag specifying how the median at the edge should be treated.
+
+    Returns
+    ---------
+
+    output : af.Array
+           - The signal after median filter is applied.
+
+    """
+    output = Array()
+    safe_call(backend.get().af_medfilt1(ct.pointer(output.arr), signal.arr, c_dim_t(length), edge_pad.value))
+    return output
+
+def medfilt2(signal, w0 = 3, w1 = 3, edge_pad = PAD.ZERO):
+    """
+    Apply median filter for the signal.
+
+    Parameters
+    ----------
+    signal : af.Array
+          - A 2 D arrayfire array representing a signal, or
+          - A multi dimensional array representing batch of signals.
+
+    w0 : optional: int. default: 3.
+          - The length of the filter along the first dimension.
+
+    w1 : optional: int. default: 3.
+          - The length of the filter along the second dimension.
+
+    edge_pad : optional: af.PAD. default: af.PAD.ZERO
+          - Flag specifying how the median at the edge should be treated.
+
+    Returns
+    ---------
+
+    output : af.Array
+           - The signal after median filter is applied.
+
+    """
+    output = Array()
+    safe_call(backend.get().af_medfilt2(ct.pointer(output.arr),
+                                        signal.arr, c_dim_t(w0),
+                                        c_dim_t(w1), edge_pad.value))
+    return output
+
 def set_fft_plan_cache_size(cache_size):
     """
     Sets plan cache size.
diff --git a/arrayfire/tests/simple/signal.py b/arrayfire/tests/simple/signal.py
index 03d89b4..817685c 100644
--- a/arrayfire/tests/simple/signal.py
+++ b/arrayfire/tests/simple/signal.py
@@ -110,4 +110,8 @@ def simple_signal(verbose=False):
     display_func(af.fir(b, x))
     display_func(af.iir(b, a, x))
 
+    display_func(af.medfilt1(a))
+    display_func(af.medfilt2(a))
+    display_func(af.medfilt(a))
+
 _util.tests['signal'] = simple_signal

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list