Skip to content

Commit cb8fdcf

Browse files
committed
Merge branch 'master' into devel
2 parents ed52b90 + b2a2efe commit cb8fdcf

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
### v3.3.20160510
2+
- Bugfix to `af.histogram`
3+
4+
- Added missing functions / methods
5+
- `gaussian_kernel`
6+
7+
- Added new array properties
8+
- `Array.T` now returns transpose
9+
- `Array.H` now returns hermitian transpose
10+
- `Array.shape` now allows easier access individual dimensions
11+
112
### v3.3.20160427
213
- Fixes to numpy interop on Windows
314
- Fixes issues with occasional double free

arrayfire/array.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,20 @@ def type(self):
577577
"""
578578
return self.dtype().value
579579

580+
@property
581+
def T(self):
582+
"""
583+
Return the transpose of the array
584+
"""
585+
return transpose(self, False)
586+
587+
@property
588+
def H(self):
589+
"""
590+
Return the hermitian transpose of the array
591+
"""
592+
return transpose(self, False)
593+
580594
def dims(self):
581595
"""
582596
Return the shape of the array as a tuple.
@@ -590,6 +604,13 @@ def dims(self):
590604
dims = (d0.value,d1.value,d2.value,d3.value)
591605
return dims[:self.numdims()]
592606

607+
@property
608+
def shape(self):
609+
"""
610+
The shape of the array
611+
"""
612+
return self.dims()
613+
593614
def numdims(self):
594615
"""
595616
Return the number of dimensions of the array.

arrayfire/image.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def histogram(image, nbins, min_val = None, max_val = None):
408408
output = Array()
409409
safe_call(backend.get().af_histogram(ct.pointer(output.arr),
410410
image.arr, ct.c_uint(nbins),
411-
ct.c_float(min_val), ct.c_float(max_val)))
411+
ct.c_double(min_val), ct.c_double(max_val)))
412412
return output
413413

414414
def hist_equal(image, hist):
@@ -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/array_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def simple_array(verbose=False):
1818

1919
a = af.Array([1, 2, 3])
2020
display_func(a)
21+
display_func(a.T)
22+
display_func(a.H)
23+
print_func(a.shape)
2124

2225
b = a.as_type(af.Dtype.s32)
2326
display_func(b)

tests/simple/image.py

Lines changed: 2 additions & 0 deletions
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)