Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<docs lang="markdown">
[TODO: write documentation for this plugin.]
<config lang="json">
"name": "CellPoseDemo",
"type": "web-python",
"version": "0.1.0",
"description": "A demo plugin for running cell-pose segmentation",
"tags": [],
"ui": "",
"cover": "",
"inputs": null,
"outputs": null,
"flags": [],
"icon": "extension",
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": ["pyotritonclient", "kaibu-utils"],
"dependencies": []
<script lang="python">
import io
import numpy as np
from pyotritonclient import execute
from kaibu_utils import fetch_image
from imjoy import api
class ImJoyPlugin():
async def setup(self):
image = await fetch_image('')
image = image.astype('float32')
print("example image downloaded: ", image.shape)
self.image = image
async def run(self, ctx):
viewer = await api.createWindow(src="")
await viewer.view_image(self.image.astype('uint8'), type="itk-vtk", name="input-image")
async def form_submit_callback(fields):
diameter = int(fields['Diameter'])
await viewer.set_loader(True)
# run inference
param = {'diameter': diameter, 'model_type': 'cyto'}
results = await execute([self.image.transpose(2, 0, 1), param],
mask = results['mask']
await viewer.view_image(mask, type="itk-vtk", name="output-mask", opacity=0.4)
await api.showMessage('cellpose prediction completed!')
except Exception as exp:
await api.alert("Failed to run prediction: " + str(exp))
await viewer.set_loader(False)
await viewer.add_widget(
"_rintf": True,
"name": "CellPose Segmentation",
"type": "form",
"form_submit_callback": form_submit_callback,
"fields": [
"label": "Diameter",
"type": "number",
"value": 30,
"rules": {
"min": 1,
"max": 400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment