BIOP / ijp-LaRoMe

some useful function to get Label from ROIs and vice versa , and more!
BSD 3-Clause "New" or "Revised" License
12 stars 4 forks source link

Use with a different RoiManager #12

Closed lguerard closed 2 years ago

lguerard commented 2 years ago

Hi all !

https://github.com/BIOP/ijp-LaRoMe/blob/ee659bf9eb3dad772c522172ba8cf11de5539430/src/main/java/ch/epfl/biop/ij2command/Labels2Rois.java#L57

I tried using this script which is pretty awesome but I thought that since the call (in python at least) is IJ.run(imp, "Label image to ROIs", "rm=[" + str(rm) + "]") that I would able to use a different RoiManager than the one displayed. So far, I failed doing so..

What's your experience with it ? Do you think it would be hard to implement ? I could check but I don't know much about Java...

Thanks !

NicoKiaru commented 2 years ago

You can try to use a command service to run the command instead of IJ.run.

In groovy this looks like :

#@CommandService cs

def myRoiManager = ...

cs.run(Labels2Rois.class, true, "rm", myRoiManager).get()

import ch.epfl.biop.ij2command.Labels2Rois

(it shouldn't be very different in jython)

We should declare the output image as an output parameter, which would allow to catch it. So far it relies on the GUI to get the output image.

lguerard commented 2 years ago

You can try to use a command service to run the command instead of IJ.run.

This is indeed working thanks ! Here's the code if interested :

#@ CommandService cs
rm2 = RoiManager(False)
cs.run(Labels2Rois, True, "rm", rm2).get()

We should declare the output image as an output parameter, which would allow to catch it. So far it relies on the GUI to get the output image.

Don't you mean input image then ? So the label image should be in front when running the command ?

NicoKiaru commented 2 years ago

You can already specify an input image with:

cs.run(Labels2Rois, True, "rm", rm2, "imp", myImagePlus ).get()

I don't remember how the plugin works. Maybe it writes over the image and does not create a new image. If that's the case, then your input is also the output and we're fine. If there's is another output, then we should declare an ImagePlus object as an output.

lguerard commented 2 years ago

Oh that's super, thanks !

I don't remember how the plugin works. Maybe it writes over the image and does not create a new image.

This plugin is getting an input and putting the ROIs in a ROIManager so no output image needed ! :)

Thanks a lot !