Skip to content

Commit 24ec3fb

Browse files
mlloreda9prady9
authored andcommitted
Add anisotropic_diffusion() API
Added anisotropic_diffusion() support from v3.6.0
1 parent 0ec6da3 commit 24ec3fb

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

arrayfire/image.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,47 @@ def canny(image,
12401240
c_uint_t(sobel_window), c_bool_t(is_fast)))
12411241
return output
12421242

1243+
def anisotropic_diffusion(image, time_step, conductance, iterations, flux_function_type = FLUX.QUADRATIC, diffusion_kind = DIFFUSION.GRAD):
1244+
"""
1245+
Anisotropic smoothing filter.
1246+
1247+
Parameters
1248+
----------
1249+
image: af.Array
1250+
The input image.
1251+
1252+
time_step: scalar.
1253+
The time step used in solving the diffusion equation.
1254+
1255+
conductance:
1256+
Controls conductance sensitivity in diffusion equation.
1257+
1258+
iterations:
1259+
Number of times the diffusion step is performed.
1260+
1261+
flux_function_type:
1262+
Type of flux function to be used. Available flux functions:
1263+
- Quadratic (af.FLUX.QUADRATIC)
1264+
- Exponential (af.FLUX.EXPONENTIAL)
1265+
1266+
diffusion_kind:
1267+
Type of diffusion equatoin to be used. Available diffusion equations:
1268+
- Gradient diffusion equation (af.DIFFUSION.GRAD)
1269+
- Modified curvature diffusion equation (af.DIFFUSION.MCDE)
1270+
1271+
Returns
1272+
-------
1273+
out: af.Array
1274+
Anisotropically-smoothed output image.
1275+
1276+
"""
1277+
out = Array()
1278+
safe_call(backend.get().
1279+
af_anisotropic_diffusion(c_pointer(out.arr), image.arr,
1280+
c_float_t(time_step), c_float_t(conductance), c_uint_t(iterations),
1281+
flux_function_type.value, diffusion_kind.value))
1282+
return out
1283+
12431284
def is_image_io_available():
12441285
"""
12451286
Function to check if the arrayfire library was built with Image IO support.

arrayfire/library.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ class CANNY_THRESHOLD(_Enum):
422422
MANUAL = _Enum_Type(0)
423423
AUTO_OTSU = _Enum_Type(1)
424424

425+
class FLUX(_Enum):
426+
"""
427+
Flux functions
428+
"""
429+
DEFAULT = _Enum_Type(0)
430+
QUADRATIC = _Enum_Type(1)
431+
EXPONENTIAL = _Enum_Type(2)
432+
433+
class DIFFUSION(_Enum):
434+
"""
435+
Diffusion equations
436+
"""
437+
DEFAULT = _Enum_Type(0)
438+
GRAD = _Enum_Type(1)
439+
MCDE = _Enum_Type(2)
440+
425441
_VER_MAJOR_PLACEHOLDER = "__VER_MAJOR__"
426442

427443
def _setup():

arrayfire/tests/simple/image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@ def simple_image(verbose = False):
8181
a = af.randu(10, 10)
8282
b = af.canny(a, low_threshold = 0.2, high_threshold = 0.8)
8383

84+
display_func(af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC, af.DIFFUSION.GRAD))
85+
8486
_util.tests['image'] = simple_image

0 commit comments

Comments
 (0)