Skip to content

Commit 7f3f844

Browse files
committed
FEAT: Add gaussian_kernel and necessary tests
1 parent 4a49c38 commit 7f3f844

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

arrayfire/image.py

+42
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,48 @@ def sobel_derivatives(image, w_len=3):
769769
image.arr, ct.c_uint(w_len)))
770770
return dx,dy
771771

772+
def gaussian_kernel(rows, cols, sigma_r = None, sigma_c = None):
773+
"""
774+
Create a gaussian kernel with the given parameters.
775+
776+
Parameters
777+
----------
778+
image : af.Array
779+
- A 2 D arrayfire array representing an image, or
780+
- A multi dimensional array representing batch of images.
781+
782+
rows : int
783+
- The number of rows in the gaussian kernel.
784+
785+
cols : int
786+
- The number of columns in the gaussian kernel.
787+
788+
sigma_r : optional: number. default: None.
789+
- The sigma value along rows
790+
- If None, calculated as (0.25 * rows + 0.75)
791+
792+
sigma_c : optional: number. default: None.
793+
- The sigma value along columns
794+
- If None, calculated as (0.25 * cols + 0.75)
795+
796+
Returns
797+
-------
798+
out : af.Array
799+
- A gaussian kernel of size (rows, cols)
800+
"""
801+
out = Array()
802+
803+
if (sigma_r is None):
804+
sigma_r = 0.25 * rows + 0.75
805+
806+
if (sigma_c is None):
807+
sigma_c = 0.25 * cols + 0.75
808+
809+
safe_call(backend.get().af_gaussian_kernel(ct.pointer(out.arr),
810+
ct.c_int(rows), ct.c_int(cols),
811+
ct.c_double(sigma_r), ct.c_double(sigma_c)))
812+
return out
813+
772814
def sobel_filter(image, w_len = 3, is_fast = False):
773815
"""
774816
Apply sobel filter to the image.

tests/simple/image.py

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def simple_image(verbose = False):
5454
display_func(dx)
5555
display_func(dy)
5656
display_func(af.sobel_filter(a))
57+
display_func(af.gaussian_kernel(3, 3))
58+
display_func(af.gaussian_kernel(3, 3, 1, 1))
5759

5860
ac = af.gray2rgb(a)
5961
display_func(ac)

0 commit comments

Comments
 (0)