Skip to content

Instantly share code, notes, and snippets.

@oeway
Created June 8, 2020 13:23
Show Gist options
  • Save oeway/f9aafd81f8fcb68550aaeb789850b8b8 to your computer and use it in GitHub Desktop.
Save oeway/f9aafd81f8fcb68550aaeb789850b8b8 to your computer and use it in GitHub Desktop.
<docs lang="markdown">
[TODO: write documentation for this plugin.]
</docs>
<config lang="json">
{
"name": "ITK-VTK-Viewer",
"type": "native-python",
"version": "0.1.0",
"description": "[TODO: describe this plugin with one sentence.]",
"tags": [],
"ui": "",
"cover": "",
"inputs": null,
"outputs": null,
"flags": [],
"icon": "extension",
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": ["itk", "itkwidgets", "imageio", "tifffile"],
"dependencies": []
}
</config>
<script lang="python">
# Run `pip install itk itkwidgets` before trying this example
from imjoy import api
import numpy as np
import itk
from itkwidgets.trait_types import itkimage_to_json, itkimage_from_json
from itkwidgets._transform_types import to_itk_image
from tifffile import imread
# register an encoder for encoding the itk.Image, the name `itkimage` will be used for decoding
# this example only use the encoder part
api.registerCodec({'name': 'itkimage', 'type': itk.Image, 'encoder': itkimage_to_json, 'decoder': itkimage_from_json})
class ImJoyPlugin():
def setup(self):
api.log('plugin initialized')
async def run(self, ctx):
files = await api.showFileDialog()
# load the image data and inspect its shape
membranes = imread(files[0].path)
# image_array = np.random.randint(0, 255, [10,10,10], dtype='uint8')
itk_image = to_itk_image(membranes)
# here the itk_image will be encoded via the registered encoder function (i.e.: itkimage_to_json)
api.createWindow(type="itk-vtk-viewer", src="https://oeway.github.io/itk-vtk-viewer/", data={"image_array": itk_image})
api.export(ImJoyPlugin())
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment