Skip to content

Commit

Permalink
control kaibu view dataset with imjoy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Oct 16, 2023
1 parent be02bc1 commit 83c6b50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions public/plugins/viewer.imjoy.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
</config>

<script lang="python">
import io
import tifffile
from imjoy import api

class Plugin():
async def setup(self):
Expand All @@ -29,6 +31,7 @@
src="https://kaibu.org/#/app",
window_id="kaibu-container"
)
await self.viewer.open_sidebar(False)
self.image = None

def load_image_from_bytes(self, file_name, img_bytes):
Expand All @@ -37,12 +40,17 @@
with tifffile.TiffFile(_file) as tif:
image = tif.asarray()
self.image = image
return image

async def view_img_from_bytes(self, file_name, bytes_):
await self.viewer.clear_layers()
image = self.load_image_from_bytes(file_name, bytes_)
await self.viewer.view_image(image, name=file_name)
return image.shape

async def add_points(self, points, name="points"):
await self.viewer.add_points(points, name=name)

async def run(self, ctx):
pass

Expand Down
14 changes: 7 additions & 7 deletions src/views/DatasetView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ export default {
async loadViewer() {
if (imjoy !== null) {
const viewer = await imjoy.api.createWindow(
{ src: "https://kaibu.org/#/app", window_id: "kaibu-container" })
const pluginUrl = window.location.origin + "/plugins/viewer.imjoy.html"
const viewer = await imjoy.api.loadPlugin({ src: pluginUrl })
this.viewer = viewer
await viewer.set_mode("full")
} else {
setTimeout(() => this.loadViewer(), 1000)
}
Expand All @@ -96,14 +95,15 @@ export default {
const point = data.points[0];
const imgName = point.text.split("<br>")[0].split(":</b> ")[1]
console.log(`You clicked on point: ${imgName} at position (x: ${point.x}, y: ${point.y})`)
//const imgURL = this.imgBaseURL + imgName
//await this.viewer.view_image(imgURL, { name: imgName, type: 'itk-vtk' })
const imgURL = this.imgBaseURL + imgName
const imgBytes = await fetch(imgURL).then(resp => resp.arrayBuffer())
await this.viewer.view_img_from_bytes(imgName, imgBytes)
const csvName = imgName.replace(".tif", ".csv")
const csvURL = this.csvBaseURL + csvName
const csvContent = await fetch(csvURL).then(resp => resp.text())
const csvData = csv.toObjects(csvContent)
const points = csvData.map((d: any) => [d['axis-0'], d['axis-1']])
await this.viewer.add_points(points, { name: csvName })
const points = csvData.map((d: any) => [d['axis-1'], d['axis-0']])
await this.viewer.add_points(points, csvName)
}
},
Expand Down

0 comments on commit 83c6b50

Please sign in to comment.