Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating pyImagej with ImJoy website #147

Open
giovanniani opened this issue Nov 1, 2021 · 10 comments
Open

Integrating pyImagej with ImJoy website #147

giovanniani opened this issue Nov 1, 2021 · 10 comments
Labels
question Further information is requested
Milestone

Comments

@giovanniani
Copy link

I'm looking to integrate pyImagej with a website we are working on with ImJoy, and would like to see how we can send the data from the results back to the website, we already can call macro functions from the website but we still haven't been able to get the results back.

Thanks

@ctrueden
Copy link
Member

ctrueden commented Nov 2, 2021

@giovanniani Do you have a minimal example somewhere we can look at, to better understand what you are trying to do?

CC @oeway

@ctrueden ctrueden added the question Further information is requested label Nov 2, 2021
@oeway
Copy link
Contributor

oeway commented Nov 2, 2021

Hi @giovanniani I think what you are looking for is something like this:

import scyjava as sj
WindowManager = sj.jimport('ij.WindowManager')

# ...run your macro with your image

# Get the image of your current window
current_image = WindowManager.getCurrentImage()

# Convert your image to a numpy array
current_image_ndarray = ij.py.from_java(current_image)

# Display the ndarray in ImJoy e.g. using Kaibu: https://kaibu.org/docs/#/api?id=view_imageimage-options

@ctrueden ctrueden added this to the unscheduled milestone Nov 5, 2021
@ctrueden
Copy link
Member

ctrueden commented Nov 5, 2021

@giovanniani Please close if @oeway's code will work for you, or give more details if not. Thanks!

@giovanniani
Copy link
Author

@oeway thanks for the help with the issue, I have been trying to solve some issues I encountered with the scyjava library.

I hope I can solve them soon and close this issue.
@ctrueden I apologyse for my late reply, as soon as I find a solution to the library I will close the issue.

Thanks

@giovanniani
Copy link
Author

So I tried running the code above but I keep geeting the next issue
Class ij.WindowManager is not found.

@ctrueden
Copy link
Member

ctrueden commented Nov 17, 2021

@giovanniani How are you initializing your ImageJ2 gateway? Try this:

import imagej
ij = imagej.init()

It should spin up an ImageJ2+ImageJ environment, which will include ij.WindowManager.

Double check you are running the latest pyimagej. It should be 1.0.2. (import imagej; print(imagej.config.__version__))

In the next release of pyimagej (1.1.0), you will also have direct access to the WindowManager class by writing ij.WindowManager from there. But for the current release, you can use the suggestion above:

from scyjava import jimport
WindowManager = jimport('ij.WindowManager')

@giovanniani
Copy link
Author

I was using a local version of Fiji

I believe that's why it didn't work for me on the first time.
Now with ij = imagej.init() I don't get the error.

Do you think we can solve this with any workarounds or I should stick to the normal init?

@ctrueden
Copy link
Member

ctrueden commented Nov 18, 2021

@giovanniani A local version of Fiji should certainly work; you should have jars/ij-1.53f.jar in your Fiji folder, which contains all the original ImageJ classes, including ij.WindowManager. No idea why you wouldn't be able to load that class when wrapping a local installation.

As I said above: if you could please post a minimal example demonstrating the problem, that would be very helpful in trying to reproduce and troubleshoot.

@giovanniani
Copy link
Author

giovanniani commented Nov 23, 2021

This is the code that I've been running
We have a local version of Fiji that runs the macro below,

The data is mounted on a separate drive

I can send the data as well if needed.

I've been running the code inside a virtual machine with ubuntu 20.04

import imagej
import scyjava as sj

    
ij = imagej.init('/home/giovanni/Documents/Fiji.app')

scyjava.config.add_option('-Xmx6g')
WindowManager = sj.jimport('ij.WindowManager')

macro = """
open("/run/user/1001/gvfs/smb-share:server=truenas.local,share=data_storage/giovanni/test/a.tif");
run("3D Objects Counter", "threshold=407 slice=151 min.=10 max.=19857408 exclude_objects_on_edges objects surfaces centroids centres_of_masses statistics summary");
selectWindow("Surface map of a.tif");
selectWindow("Centroids map of a.tif");
selectWindow("Centres of mass map of a.tif");
selectWindow("a.tif");
"""
result = ij.py.run_macro(macro)

ij.window().getOpenWindows()
ij.window().clear()

@giovanniani
Copy link
Author

@ctrueden @oeway Do you think we could have a meeting one day to discuss the issues I've been facing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants