Retrieve current window image using server plugin in imageJ

imagej
imagej-server

#1

Posting this as requested from gitter.im/imagej at @ctrueden’s request.

I’m trying to help a colleague out; I know nothing about imageJ. I did discover though that I can ask it to start a server up, which I can then talk to on port 8080. What I’m trying to do is get the server to grab the image in the current window, so I can retrieve it with another call. Evidently though I’m using an “old” API when I do something like this:

curl -XPOST -H "Content-Type: application/json" -d '{"language":"py","script":"# #@output image\nimage = imageDisplay.getImageDisplays()[0].getActiveView().getData().getImgPlus()"}' localhost:8080/modules/'command:net.imagej.server.external.ScriptEval'?process=false
iptEval'?process=false().getImgPlus()"}' localhost:8080/modules/'command:net.imagej.server.external.ScriptEval'?process=false

I then follow that up with

$ curl localhost:8080/objects/object:jp6hpetkmh5tgusb/png

which replies

{"code":400,"message":"Retrival for Object type not supported yet: ij.ImagePlus"}

So, the basic question is:

  1. How can I send a command using the imageJ server plugin to the server that grabs whatever is showing in the “most active” window and squirrels it away as a 24-bit image I could retrieve with a subsequent call?
  2. Note that if the window is showing some sort of stack/slice/frame sequence, I simply want an image which corresponds to whatever is currently being presented on screen.

Failing that, I have determined that I can make imageJ save the current image in a file, with this command;

$ curl -XPOST -H "Content-Type: application/json" \
   -d '{"language":"groovy","script":"import ij.IJ\nimp2 = IJ.image.crop()\nIJ.run(imp2, \"RGB Color\", \"\")\nIJ.saveAs(imp2, \"PNG\", \"/Users/deb/extract.png\")\n"}' \
   localhost:8080/modules/'command:net.imagej.server.external.ScriptEval'?process=false

I can then use a completely separate process running on that machine to send me back that file. This works, but is needlessly clunky.

In case it’s not clear, the point is to allow a remote device, not on the machine, to ask the imageJ GUI to ship back the current image, for further manipulation/display on the remote device.

Thanks for any thought/suggestions. My knowledge of ImageJ and it’s scripting capabilities is rudimentary at best — I’ve never used ImageJ at all before a day or so ago.