[python-arrayfire] 02/11: FEAT: Add gaussian_kernel and necessary tests

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu May 26 17:37:12 UTC 2016


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

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

commit 7f3f8442dc5ae2758ec0ed5b335b23fe1149aa5a
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue May 10 14:35:34 2016 -0400

    FEAT: Add gaussian_kernel and necessary tests
---
 arrayfire/image.py    | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/simple/image.py |  2 ++
 2 files changed, 44 insertions(+)

diff --git a/arrayfire/image.py b/arrayfire/image.py
index 2487abe..ec68f8a 100644
--- a/arrayfire/image.py
+++ b/arrayfire/image.py
@@ -769,6 +769,48 @@ def sobel_derivatives(image, w_len=3):
                                               image.arr, ct.c_uint(w_len)))
     return dx,dy
 
+def gaussian_kernel(rows, cols, sigma_r = None, sigma_c = None):
+    """
+    Create a gaussian kernel with the given parameters.
+
+    Parameters
+    ----------
+    image : af.Array
+          - A 2 D arrayfire array representing an image, or
+          - A multi dimensional array representing batch of images.
+
+    rows : int
+         - The number of rows in the gaussian kernel.
+
+    cols : int
+         - The number of columns in the gaussian kernel.
+
+    sigma_r : optional: number. default: None.
+         - The sigma value along rows
+         - If None, calculated as (0.25 * rows + 0.75)
+
+    sigma_c : optional: number. default: None.
+         - The sigma value along columns
+         - If None, calculated as (0.25 * cols + 0.75)
+
+    Returns
+    -------
+    out   : af.Array
+          - A gaussian kernel of size (rows, cols)
+    """
+    out = Array()
+
+    if (sigma_r is None):
+        sigma_r = 0.25 * rows + 0.75
+
+    if (sigma_c is None):
+        sigma_c = 0.25 * cols + 0.75
+
+    safe_call(backend.get().af_gaussian_kernel(ct.pointer(out.arr),
+                                               ct.c_int(rows), ct.c_int(cols),
+                                               ct.c_double(sigma_r), ct.c_double(sigma_c)))
+    return out
+
 def sobel_filter(image, w_len = 3, is_fast = False):
     """
     Apply sobel filter to the image.
diff --git a/tests/simple/image.py b/tests/simple/image.py
index 7fdfa90..209013a 100644
--- a/tests/simple/image.py
+++ b/tests/simple/image.py
@@ -54,6 +54,8 @@ def simple_image(verbose = False):
     display_func(dx)
     display_func(dy)
     display_func(af.sobel_filter(a))
+    display_func(af.gaussian_kernel(3, 3))
+    display_func(af.gaussian_kernel(3, 3, 1, 1))
 
     ac = af.gray2rgb(a)
     display_func(ac)

-- 
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