-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(itkwasm-image-io-wasi): add bindgen output
- Loading branch information
Showing
46 changed files
with
3,389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# itkwasm-image-io-wasi | ||
|
||
[![PyPI version](https://badge.fury.io/py/itkwasm-image-io-wasi.svg)](https://badge.fury.io/py/itkwasm-image-io-wasi) | ||
|
||
Input and output for scientific and medical image file formats. WASI implementation. | ||
|
||
This package provides the WASI WebAssembly implementation. It is usually not called directly. Please use [`itkwasm-image-io`](https://pypi.org/project/itkwasm-image-io/) instead. | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
pip install itkwasm-image-io-wasi | ||
``` | ||
|
||
## Development | ||
|
||
```sh | ||
pip install pytest | ||
pip install -e . | ||
pytest | ||
|
||
# or | ||
pip install hatch | ||
hatch run test | ||
``` |
48 changes: 48 additions & 0 deletions
48
packages/image-io/python/itkwasm-image-io-wasi/itkwasm_image_io_wasi/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
"""itkwasm-image-io-wasi: Input and output for scientific and medical image file formats. WASI implementation.""" | ||
|
||
from .bio_rad_read_image import bio_rad_read_image | ||
from .bio_rad_write_image import bio_rad_write_image | ||
from .bmp_read_image import bmp_read_image | ||
from .bmp_write_image import bmp_write_image | ||
from .fdf_read_image import fdf_read_image | ||
from .fdf_write_image import fdf_write_image | ||
from .gdcm_read_image import gdcm_read_image | ||
from .gdcm_write_image import gdcm_write_image | ||
from .ge_adw_read_image import ge_adw_read_image | ||
from .ge_adw_write_image import ge_adw_write_image | ||
from .ge4_read_image import ge4_read_image | ||
from .ge4_write_image import ge4_write_image | ||
from .ge5_read_image import ge5_read_image | ||
from .ge5_write_image import ge5_write_image | ||
from .gipl_read_image import gipl_read_image | ||
from .gipl_write_image import gipl_write_image | ||
from .jpeg_read_image import jpeg_read_image | ||
from .jpeg_write_image import jpeg_write_image | ||
from .lsm_read_image import lsm_read_image | ||
from .lsm_write_image import lsm_write_image | ||
from .meta_read_image import meta_read_image | ||
from .meta_write_image import meta_write_image | ||
from .mgh_read_image import mgh_read_image | ||
from .mgh_write_image import mgh_write_image | ||
from .mrc_read_image import mrc_read_image | ||
from .mrc_write_image import mrc_write_image | ||
from .nifti_read_image import nifti_read_image | ||
from .nifti_write_image import nifti_write_image | ||
from .nrrd_read_image import nrrd_read_image | ||
from .nrrd_write_image import nrrd_write_image | ||
from .png_read_image import png_read_image | ||
from .png_write_image import png_write_image | ||
from .scanco_read_image import scanco_read_image | ||
from .scanco_write_image import scanco_write_image | ||
from .tiff_read_image import tiff_read_image | ||
from .tiff_write_image import tiff_write_image | ||
from .vtk_read_image import vtk_read_image | ||
from .vtk_write_image import vtk_write_image | ||
from .wasm_read_image import wasm_read_image | ||
from .wasm_write_image import wasm_write_image | ||
from .wasm_zstd_read_image import wasm_zstd_read_image | ||
from .wasm_zstd_write_image import wasm_zstd_write_image | ||
|
||
from ._version import __version__ |
1 change: 1 addition & 0 deletions
1
packages/image-io/python/itkwasm-image-io-wasi/itkwasm_image_io_wasi/_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.3.0" |
76 changes: 76 additions & 0 deletions
76
packages/image-io/python/itkwasm-image-io-wasi/itkwasm_image_io_wasi/bio_rad_read_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
from pathlib import Path, PurePosixPath | ||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from importlib_resources import files as file_resources | ||
|
||
_pipeline = None | ||
|
||
from itkwasm import ( | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
Pipeline, | ||
BinaryFile, | ||
Image, | ||
) | ||
|
||
def bio_rad_read_image( | ||
serialized_image: os.PathLike, | ||
information_only: bool = False, | ||
) -> Tuple[Any, Image]: | ||
"""Read an image file format and convert it to the itk-wasm file format | ||
:param serialized_image: Input image serialized in the file format | ||
:type serialized_image: os.PathLike | ||
:param information_only: Only read image metadata -- do not read pixel data. | ||
:type information_only: bool | ||
:return: Whether the input could be read. If false, the output image is not valid. | ||
:rtype: Any | ||
:return: Output image | ||
:rtype: Image | ||
""" | ||
global _pipeline | ||
if _pipeline is None: | ||
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bio-rad-read-image.wasi.wasm'))) | ||
|
||
pipeline_outputs: List[PipelineOutput] = [ | ||
PipelineOutput(InterfaceTypes.JsonCompatible), | ||
PipelineOutput(InterfaceTypes.Image), | ||
] | ||
|
||
pipeline_inputs: List[PipelineInput] = [ | ||
PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))), | ||
] | ||
|
||
args: List[str] = ['--memory-io',] | ||
# Inputs | ||
if not Path(serialized_image).exists(): | ||
raise FileNotFoundError("serialized_image does not exist") | ||
args.append(str(PurePosixPath(serialized_image))) | ||
# Outputs | ||
could_read_name = '0' | ||
args.append(could_read_name) | ||
|
||
image_name = '1' | ||
args.append(image_name) | ||
|
||
# Options | ||
input_count = len(pipeline_inputs) | ||
if information_only: | ||
args.append('--information-only') | ||
|
||
|
||
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) | ||
|
||
result = ( | ||
outputs[0].data, | ||
outputs[1].data, | ||
) | ||
return result | ||
|
79 changes: 79 additions & 0 deletions
79
packages/image-io/python/itkwasm-image-io-wasi/itkwasm_image_io_wasi/bio_rad_write_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
from pathlib import Path, PurePosixPath | ||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from importlib_resources import files as file_resources | ||
|
||
_pipeline = None | ||
|
||
from itkwasm import ( | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
Pipeline, | ||
Image, | ||
BinaryFile, | ||
) | ||
|
||
def bio_rad_write_image( | ||
image: Image, | ||
serialized_image: str, | ||
information_only: bool = False, | ||
use_compression: bool = False, | ||
) -> Tuple[Any]: | ||
"""Write an itk-wasm file format converted to an image file format | ||
:param image: Input image | ||
:type image: Image | ||
:param serialized_image: Output image serialized in the file format. | ||
:type serialized_image: str | ||
:param information_only: Only write image metadata -- do not write pixel data. | ||
:type information_only: bool | ||
:param use_compression: Use compression in the written file | ||
:type use_compression: bool | ||
:return: Whether the input could be written. If false, the output image is not valid. | ||
:rtype: Any | ||
""" | ||
global _pipeline | ||
if _pipeline is None: | ||
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bio-rad-write-image.wasi.wasm'))) | ||
|
||
pipeline_outputs: List[PipelineOutput] = [ | ||
PipelineOutput(InterfaceTypes.JsonCompatible), | ||
PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))), | ||
] | ||
|
||
pipeline_inputs: List[PipelineInput] = [ | ||
PipelineInput(InterfaceTypes.Image, image), | ||
] | ||
|
||
args: List[str] = ['--memory-io',] | ||
# Inputs | ||
args.append('0') | ||
# Outputs | ||
could_write_name = '0' | ||
args.append(could_write_name) | ||
|
||
serialized_image_name = str(PurePosixPath(serialized_image)) | ||
args.append(serialized_image_name) | ||
|
||
# Options | ||
input_count = len(pipeline_inputs) | ||
if information_only: | ||
args.append('--information-only') | ||
|
||
if use_compression: | ||
args.append('--use-compression') | ||
|
||
|
||
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) | ||
|
||
result = outputs[0].data | ||
return result | ||
|
76 changes: 76 additions & 0 deletions
76
packages/image-io/python/itkwasm-image-io-wasi/itkwasm_image_io_wasi/bmp_read_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
from pathlib import Path, PurePosixPath | ||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from importlib_resources import files as file_resources | ||
|
||
_pipeline = None | ||
|
||
from itkwasm import ( | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
Pipeline, | ||
BinaryFile, | ||
Image, | ||
) | ||
|
||
def bmp_read_image( | ||
serialized_image: os.PathLike, | ||
information_only: bool = False, | ||
) -> Tuple[Any, Image]: | ||
"""Read an image file format and convert it to the itk-wasm file format | ||
:param serialized_image: Input image serialized in the file format | ||
:type serialized_image: os.PathLike | ||
:param information_only: Only read image metadata -- do not read pixel data. | ||
:type information_only: bool | ||
:return: Whether the input could be read. If false, the output image is not valid. | ||
:rtype: Any | ||
:return: Output image | ||
:rtype: Image | ||
""" | ||
global _pipeline | ||
if _pipeline is None: | ||
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bmp-read-image.wasi.wasm'))) | ||
|
||
pipeline_outputs: List[PipelineOutput] = [ | ||
PipelineOutput(InterfaceTypes.JsonCompatible), | ||
PipelineOutput(InterfaceTypes.Image), | ||
] | ||
|
||
pipeline_inputs: List[PipelineInput] = [ | ||
PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))), | ||
] | ||
|
||
args: List[str] = ['--memory-io',] | ||
# Inputs | ||
if not Path(serialized_image).exists(): | ||
raise FileNotFoundError("serialized_image does not exist") | ||
args.append(str(PurePosixPath(serialized_image))) | ||
# Outputs | ||
could_read_name = '0' | ||
args.append(could_read_name) | ||
|
||
image_name = '1' | ||
args.append(image_name) | ||
|
||
# Options | ||
input_count = len(pipeline_inputs) | ||
if information_only: | ||
args.append('--information-only') | ||
|
||
|
||
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) | ||
|
||
result = ( | ||
outputs[0].data, | ||
outputs[1].data, | ||
) | ||
return result | ||
|
79 changes: 79 additions & 0 deletions
79
packages/image-io/python/itkwasm-image-io-wasi/itkwasm_image_io_wasi/bmp_write_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
from pathlib import Path, PurePosixPath | ||
import os | ||
from typing import Dict, Tuple, Optional, List, Any | ||
|
||
from importlib_resources import files as file_resources | ||
|
||
_pipeline = None | ||
|
||
from itkwasm import ( | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
Pipeline, | ||
Image, | ||
BinaryFile, | ||
) | ||
|
||
def bmp_write_image( | ||
image: Image, | ||
serialized_image: str, | ||
information_only: bool = False, | ||
use_compression: bool = False, | ||
) -> Tuple[Any]: | ||
"""Write an itk-wasm file format converted to an image file format | ||
:param image: Input image | ||
:type image: Image | ||
:param serialized_image: Output image serialized in the file format. | ||
:type serialized_image: str | ||
:param information_only: Only write image metadata -- do not write pixel data. | ||
:type information_only: bool | ||
:param use_compression: Use compression in the written file | ||
:type use_compression: bool | ||
:return: Whether the input could be written. If false, the output image is not valid. | ||
:rtype: Any | ||
""" | ||
global _pipeline | ||
if _pipeline is None: | ||
_pipeline = Pipeline(file_resources('itkwasm_image_io_wasi').joinpath(Path('wasm_modules') / Path('bmp-write-image.wasi.wasm'))) | ||
|
||
pipeline_outputs: List[PipelineOutput] = [ | ||
PipelineOutput(InterfaceTypes.JsonCompatible), | ||
PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_image))), | ||
] | ||
|
||
pipeline_inputs: List[PipelineInput] = [ | ||
PipelineInput(InterfaceTypes.Image, image), | ||
] | ||
|
||
args: List[str] = ['--memory-io',] | ||
# Inputs | ||
args.append('0') | ||
# Outputs | ||
could_write_name = '0' | ||
args.append(could_write_name) | ||
|
||
serialized_image_name = str(PurePosixPath(serialized_image)) | ||
args.append(serialized_image_name) | ||
|
||
# Options | ||
input_count = len(pipeline_inputs) | ||
if information_only: | ||
args.append('--information-only') | ||
|
||
if use_compression: | ||
args.append('--use-compression') | ||
|
||
|
||
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) | ||
|
||
result = outputs[0].data | ||
return result | ||
|
Oops, something went wrong.