GeezerVison is showing github.com — FEAT: Adding native image loading and saving from arrayfire 3.2 · arrayfire/arrayfire-python@c0423b7
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: arrayfire/image.py +38Lines changed: 38 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,6 +78,44 @@ def save_image(image, file_name): |
78 | 78 | safe_call(backend.get().af_save_image(ct.c_char_p(file_name.encode('ascii')), image.arr)) |
79 | 79 | return image |
80 | 80 |
|
| 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 | + |
81 | 119 | def resize(image, scale=None, odim0=None, odim1=None, method=INTERP.NEAREST): |
82 | 120 | """ |
83 | 121 | Resize an image. |
|