Skip to content

Commit c0423b7

Browse files
committed
FEAT: Adding native image loading and saving from arrayfire 3.2
1 parent 03cb327 commit c0423b7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

arrayfire/image.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,44 @@ def save_image(image, file_name):
7878
safe_call(backend.get().af_save_image(ct.c_char_p(file_name.encode('ascii')), image.arr))
7979
return image
8080

81+
82+
def load_image_native(file_name):
83+
"""
84+
Load an image on the disk as an array in native format.
85+
86+
Parameters
87+
----------
88+
file_name: str
89+
- Full path of the file name on disk.
90+
91+
Returns
92+
-------
93+
image - af.Array
94+
A 2 dimensional (1 channel) or 3 dimensional (3 or 4 channel) array containing the image.
95+
96+
"""
97+
assert(os.path.isfile(file_name))
98+
image = Array()
99+
safe_call(backend.get().af_load_image_native(ct.pointer(image.arr),
100+
ct.c_char_p(file_name.encode('ascii'))))
101+
return image
102+
103+
def save_image_native(image, file_name):
104+
"""
105+
Save an array as an image on the disk in native format.
106+
107+
Parameters
108+
----------
109+
image : af.Array
110+
- A 2 or 3 dimensional arrayfire array representing an image.
111+
112+
file_name: str
113+
- Full path of the file name on the disk.
114+
"""
115+
assert(isinstance(file_name, str))
116+
safe_call(backend.get().af_save_image_native(ct.c_char_p(file_name.encode('ascii')), image.arr))
117+
return image
118+
81119
def resize(image, scale=None, odim0=None, odim1=None, method=INTERP.NEAREST):
82120
"""
83121
Resize an image.

0 commit comments

Comments
 (0)