Skip to content

Commit bf4cb27

Browse files
authored
Merge pull request #1240 from thewtex/wasi-file-format-example
docs(itk-python): example of file format conversion via wasm io packages
2 parents 057db0c + c1bff61 commit bf4cb27

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

docs/python/itk_python.md

+37-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,36 @@ itkwasm_image = Image(**image_dict)
4141

4242
The file extensions for these formats are `.iwi` and `.iwm` for images and mesh-like data, respectively. When written, these will output directories with an `index.json` file and raw binary files. When `.iwi.cbor` or `.iwm.cbor` extensions are used, a single [CBOR](https://en.wikipedia.org/wiki/CBOR) file is created.
4343

44+
### Wasm Python Packages
45+
46+
These file formats can be use with the ITK-Wasm Python packages, both on the system
47+
or in the browser.
48+
49+
Install the wasm Python IO packages:
50+
51+
```shell
52+
pip install itkwasm-image-io
53+
pip install itkwasm-mesh-io
54+
```
55+
56+
Then use with `itkwasm_image_io.imread`, `itkwasm_image_io.imwrite`,
57+
`itkwasm_mesh_io.meshread`, `itkwasm_mesh_io.meshwrite`. Example:
58+
59+
```python
60+
from itkwasm_image_io import imread, imwrite
61+
from itkwasm_mesh_io import meshread, meshwrite
62+
63+
image = imread('cthead1.png')
64+
imwrite(image, 'cthead1.iwi')
65+
imwrite(image, 'cthead1.iwi.cbor')
66+
67+
mesh = meshread('cow.vtk')
68+
meshwrite(mesh, 'cow.iwm')
69+
meshwrite(mesh, 'cow.iwm.cbor')
70+
```
71+
72+
### Native Python Packages
73+
4474
These file formats can also be used with native ITK Python.
4575

4676
Install the binary Python package:
@@ -52,13 +82,13 @@ pip install itk-webassemblyinterface
5282
Then use with `itk.imread`, `itk.imwrite`, `itk.meshread`, `itk.meshwrite`. Example:
5383

5484
```python
55-
import itk
85+
from itk import imread, imwrite, meshread, meshwrite
5686

57-
image = itk.imread('cthead1.png')
58-
itk.imwrite(image, 'cthead1.iwi')
59-
itk.imwrite(image, 'cthead1.iwi.cbor')
87+
image = imread('cthead1.png')
88+
imwrite(image, 'cthead1.iwi')
89+
imwrite(image, 'cthead1.iwi.cbor')
6090

61-
mesh = itk.meshread('cow.vtk')
62-
itk.meshwrite(mesh, 'cow.iwm')
63-
itk.meshwrite(mesh, 'cow.iwm.cbor')
91+
mesh = meshread('cow.vtk')
92+
meshwrite(mesh, 'cow.iwm')
93+
meshwrite(mesh, 'cow.iwm.cbor')
6494
```

0 commit comments

Comments
 (0)