Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7fdf7e

Browse files
syurkeviumar456
authored andcommittedApr 29, 2020
adds missing deconv functions to python wrapper
1 parent a1d5a1f commit e7fdf7e

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
 

‎arrayfire/image.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,78 @@ def anisotropic_diffusion(image, time_step, conductance, iterations, flux_functi
13241324
flux_function_type.value, diffusion_kind.value))
13251325
return out
13261326

1327+
def iterativeDeconv(image, psf, iterations, relax_factor, algo = ITERATIVE_DECONV.DEFAULT):
1328+
"""
1329+
Iterative deconvolution algorithm.
1330+
1331+
Parameters
1332+
----------
1333+
image: af.Array
1334+
The blurred input image.
1335+
1336+
psf: af.Array
1337+
The kernel(point spread function) known to have caused
1338+
the blur in the system.
1339+
1340+
iterations:
1341+
Number of times the algorithm will run.
1342+
1343+
relax_factor: scalar.
1344+
is the relaxation factor multiplied with distance
1345+
of estimate from observed image.
1346+
1347+
algo:
1348+
takes enum value of type af.ITERATIVE_DECONV
1349+
indicating the iterative deconvolution algorithm to be used
1350+
1351+
Returns
1352+
-------
1353+
out: af.Array
1354+
sharp image estimate generated from the blurred input
1355+
1356+
Note
1357+
-------
1358+
relax_factor argument is ignored when the RICHARDSONLUCY algorithm is used.
1359+
1360+
"""
1361+
out = Array()
1362+
safe_call(backend.get().
1363+
af_iterative_deconv(c_pointer(out.arr), image.arr, psf.arr,
1364+
c_uint_t(iterations), c_float_t(relax_factor), algo.value))
1365+
return out
1366+
1367+
def inverseDeconv(image, psf, gamma, algo = ITERATIVE_DECONV.DEFAULT):
1368+
"""
1369+
Inverse deconvolution algorithm.
1370+
1371+
Parameters
1372+
----------
1373+
image: af.Array
1374+
The blurred input image.
1375+
1376+
psf: af.Array
1377+
The kernel(point spread function) known to have caused
1378+
the blur in the system.
1379+
1380+
gamma: scalar.
1381+
is a user defined regularization constant
1382+
1383+
algo:
1384+
takes enum value of type af.INVERSE_DECONV
1385+
indicating the inverse deconvolution algorithm to be used
1386+
1387+
Returns
1388+
-------
1389+
out: af.Array
1390+
sharp image estimate generated from the blurred input
1391+
1392+
"""
1393+
out = Array()
1394+
safe_call(backend.get().
1395+
af_inverse_deconv(c_pointer(out.arr), image.arr, psf.arr,
1396+
c_float_t(gamma), algo.value))
1397+
return out
1398+
13271399
def is_image_io_available():
13281400
"""
13291401
Function to check if the arrayfire library was built with Image IO support.

‎arrayfire/library.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,21 @@ class TOPK(_Enum):
459459
MIN = _Enum_Type(1)
460460
MAX = _Enum_Type(2)
461461

462+
class ITERATIVE_DECONV(_Enum):
463+
"""
464+
Iterative deconvolution algorithm
465+
"""
466+
DEFAULT = _Enum_Type(0)
467+
LANDWEBER = _Enum_Type(1)
468+
RICHARDSONLUCY = _Enum_Type(2)
469+
470+
class INVERSE_DECONV(_Enum):
471+
"""
472+
Inverse deconvolution algorithm
473+
"""
474+
DEFAULT = _Enum_Type(0)
475+
TIKHONOV = _Enum_Type(1)
476+
462477
class VARIANCE(_Enum):
463478
"""
464479
Variance bias type

‎tests/simple/image.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,12 @@ def simple_image(verbose=False):
8888

8989
display_func(af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC, af.DIFFUSION.GRAD))
9090

91+
a = af.randu(10, 10)
92+
psf = af.gaussian_kernel(3, 3)
93+
cimg = af.convolve(a, psf)
94+
display_func(af.iterativeDeconv(cimg, psf, 100, 0.5, af.ITERATIVE_DECONV.LANDWEBER))
95+
display_func(af.iterativeDeconv(cimg, psf, 100, 0.5, af.ITERATIVE_DECONV.RICHARDSONLUCY))
96+
display_func(af.inverseDeconv(cimg, psf, 1.0, af.INVERSE_DECONV.TIKHONOV))
97+
9198

9299
_util.tests["image"] = simple_image

0 commit comments

Comments
 (0)
Please sign in to comment.