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

ChasNelson1990 opened this issue Nov 19, 2019 · 2 comments


Copy link

@ChasNelson1990 ChasNelson1990 commented Nov 19, 2019

Trying to use a plugin within a Python kernel Jupyter Notebook, as per the tutorial ( section 6.2).

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

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

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

# Load UI and send NumPy Array
np_Slice = np_allChannels[26,:,:,0].copy()

# Run Plugin
plugin = 'Mean'
args = { 
    'block_radius_x': 100,
    'block_radius_y': 100
}, args)

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

# Get back data
results =

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

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

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

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


This comment has been minimized.

Copy link

@ChasNelson1990 ChasNelson1990 commented Nov 19, 2019

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


This comment has been minimized.

Copy link

@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
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.