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

Working with Plugins: WindowManager.getCurrentImage() doesn't work #51

Open
ChasNelson1990 opened this issue Nov 19, 2019 · 2 comments
Open
Milestone

Comments

@ChasNelson1990
Copy link

@ChasNelson1990 ChasNelson1990 commented Nov 19, 2019

Trying to use a plugin within a Python kernel Jupyter Notebook, as per the tutorial (https://nbviewer.jupyter.org/github/imagej/tutorials/blob/master/notebooks/1-Using-ImageJ/6-ImageJ-with-Python-Kernel.ipynb section 6.2).

However, my output from WindowManager.getCurrentImage() is the same both before and after running ij.py.run_plugin(). Any ideas?

My code (using pyimagej 0.4 as that's what's on conda forge):

ij = imagej.init('/home/chas/Fiji.app', headless=False)

# Load UI and send NumPy Array
ij.ui().showUI()
np_Slice = np_allChannels[26,:,:,0].copy()
ij.ui().show('Image',ij.py.to_java(np_Slice))

# Run Plugin
plugin = 'Mean'
args = { 
    'block_radius_x': 100,
    'block_radius_y': 100
}
ij.py.run_plugin(plugin, args)

# Create a window manager for interacting with the UI
windowManager = jnius.autoclass('ij.WindowManager')

# Get back data
results = ij.py.from_java(windowManager.getCurrentImage())
display(np_Slice-results)

# Display
f, axes = plt.subplots(1,2)  # Create one subplot (1x1 grid)
(aO, aM) = axes.flatten()

aO.grid(False)
aO.imshow(np_allChannels[26,:,:,0], cmap='gray', interpolation='none')

aM.grid(False)
aM.imshow(results, cmap='gray', interpolation='none')

plt.show()

My data np_allChannels is a 52x1024x1024x4 numpy array of float64 dtype.

@ChasNelson1990

This comment has been minimized.

Copy link
Author

@ChasNelson1990 ChasNelson1990 commented Nov 19, 2019

See also my issue on the imageJ tutorials repo: imagej/tutorials#78

@mpinkert

This comment has been minimized.

Copy link
Contributor

@mpinkert mpinkert commented Feb 15, 2020

Sorry this took so long to respond to; we had to track down this down to a synchronization bug between ImageJ1 and ImageJ2. This is not actually the same issue as imagej/tutorials#78. What is happening here is that the plugin modifies the ImagePlus for the open image, but does not properly modify the linked Dataset or ImageDisplay. Most ways of accessing the ImagePlus data will actually link back to the Dataset, so you never get the modified values and they are in fact overwritten by the original ones.

We are working on a proper bug fix for this issue, but for now here is a way of getting the data out programmtically.

imp = windowManager.getCurrentImage()
stack = imp.getStack();
stack.setPixels(imp.getProcessor().getPixels(), imp.getCurrentSlice());

The setPixels command should update the Dataset and ImageDisplay properly.

In addition, if you have a multi-slice image and change slices, the data will sync properly. However, if you subsequently modify the latest slice and do not move from that slice, it will still require the above code to synchronize the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.