forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.py
More file actions
100 lines (75 loc) · 2.83 KB
/
image.py
File metadata and controls
100 lines (75 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
#######################################################
# Copyright (c) 2019, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af
from . import _util
def simple_image(verbose=False):
display_func = _util.display_func(verbose)
a = 10 * af.randu(6, 6)
a3 = 10 * af.randu(5, 5, 3)
dx, dy = af.gradient(a)
display_func(dx)
display_func(dy)
display_func(af.resize(a, scale=0.5))
display_func(af.resize(a, odim0=8, odim1=8))
t = af.randu(3, 2)
display_func(af.transform(a, t))
display_func(af.rotate(a, 3.14))
display_func(af.translate(a, 1, 1))
display_func(af.scale(a, 1.2, 1.2, 7, 7))
display_func(af.skew(a, 0.02, 0.02))
h = af.histogram(a, 3)
display_func(h)
display_func(af.hist_equal(a, h))
display_func(af.dilate(a))
display_func(af.erode(a))
display_func(af.dilate3(a3))
display_func(af.erode3(a3))
display_func(af.bilateral(a, 1, 2))
display_func(af.mean_shift(a, 1, 2, 3))
display_func(af.medfilt(a))
display_func(af.minfilt(a))
display_func(af.maxfilt(a))
display_func(af.regions(af.round(a) > 3))
display_func(af.confidenceCC(af.randu(10, 10),
(af.randu(2) * 9).as_type(af.Dtype.u32), (af.randu(2) * 9).as_type(af.Dtype.u32), 3, 3, 10, 0.1))
dx, dy = af.sobel_derivatives(a)
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)
display_func(af.rgb2gray(ac))
ah = af.rgb2hsv(ac)
display_func(ah)
display_func(af.hsv2rgb(ah))
display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY))
a = af.randu(6, 6)
b = af.unwrap(a, 2, 2, 2, 2)
c = af.wrap(b, 6, 6, 2, 2, 2, 2)
display_func(a)
display_func(b)
display_func(c)
display_func(af.sat(a))
a = af.randu(10, 10, 3)
display_func(af.rgb2ycbcr(a))
display_func(af.ycbcr2rgb(a))
a = af.randu(10, 10)
b = af.canny(a, low_threshold=0.2, high_threshold=0.8)
# FIXME: OpenCL Error (-11): Build Program Failure when calling clBuildProgram
# display_func(af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC, af.DIFFUSION.GRAD))
a = af.randu(10, 10)
psf = af.gaussian_kernel(3, 3)
cimg = af.convolve(a, psf)
display_func(af.iterativeDeconv(cimg, psf, 100, 0.5, af.ITERATIVE_DECONV.LANDWEBER))
display_func(af.iterativeDeconv(cimg, psf, 100, 0.5, af.ITERATIVE_DECONV.RICHARDSONLUCY))
display_func(af.inverseDeconv(cimg, psf, 1.0, af.INVERSE_DECONV.TIKHONOV))
_util.tests["image"] = simple_image