Skip to content

Commit

Permalink
Merge pull request #1240 from thewtex/wasi-file-format-example
Browse files Browse the repository at this point in the history
docs(itk-python): example of file format conversion via wasm io packages
  • Loading branch information
thewtex authored Sep 24, 2024
2 parents 057db0c + c1bff61 commit bf4cb27
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions docs/python/itk_python.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ itkwasm_image = Image(**image_dict)

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.

### Wasm Python Packages

These file formats can be use with the ITK-Wasm Python packages, both on the system
or in the browser.

Install the wasm Python IO packages:

```shell
pip install itkwasm-image-io
pip install itkwasm-mesh-io
```

Then use with `itkwasm_image_io.imread`, `itkwasm_image_io.imwrite`,
`itkwasm_mesh_io.meshread`, `itkwasm_mesh_io.meshwrite`. Example:

```python
from itkwasm_image_io import imread, imwrite
from itkwasm_mesh_io import meshread, meshwrite

image = imread('cthead1.png')
imwrite(image, 'cthead1.iwi')
imwrite(image, 'cthead1.iwi.cbor')

mesh = meshread('cow.vtk')
meshwrite(mesh, 'cow.iwm')
meshwrite(mesh, 'cow.iwm.cbor')
```

### Native Python Packages

These file formats can also be used with native ITK Python.

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

```python
import itk
from itk import imread, imwrite, meshread, meshwrite

image = itk.imread('cthead1.png')
itk.imwrite(image, 'cthead1.iwi')
itk.imwrite(image, 'cthead1.iwi.cbor')
image = imread('cthead1.png')
imwrite(image, 'cthead1.iwi')
imwrite(image, 'cthead1.iwi.cbor')

mesh = itk.meshread('cow.vtk')
itk.meshwrite(mesh, 'cow.iwm')
itk.meshwrite(mesh, 'cow.iwm.cbor')
mesh = meshread('cow.vtk')
meshwrite(mesh, 'cow.iwm')
meshwrite(mesh, 'cow.iwm.cbor')
```

0 comments on commit bf4cb27

Please sign in to comment.