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

Calling "Label image to ROIs" from jython #8

Closed giocard closed 3 years ago

giocard commented 3 years ago

The only way I could find to call the command from jython is to use the following line IJ.run(imp, "Label image to ROIs", "") but imp is ignored. Instead, the command is always applied to the active image.

romainGuiet commented 3 years ago

Hi @giocard ,

I'm not familiar with jython, but I tested the "groovy" script below with the latest version 0.2.4 (available on our update site).

import ij.*
import ch.epfl.biop.ij2command.*

#@CommandService command
#@RoiManager rm

rm.reset();
IJ.run("Close All", "");

// Open blobs and detect ROIs
imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
imp.show()
IJ.setAutoThreshold(imp, "Default");
IJ.run(imp, "Analyze Particles...", "add");

// from ROIs make a Label image
label_imp = command.run( Rois2Labels , false , 'imp' , imp , 'rm', rm).get().getOutput("label_imp")
label_imp.show()

// reset the ROImanager
rm.reset();

// from the label image make ROIs
command.run( Labels2Rois , false , 'imp' , label_imp , 'rm', rm).get()

Please let me know if it works better for you this way,

Cheers,

Romain

giocard commented 3 years ago

Hi @romainGuiet,

the command service works nicely also in jython. The only minor issue is then that, being ij2, the command is not macro-recordable.

Thank you very much! Giovanni

romainGuiet commented 3 years ago

Hi @giocard

the command service works nicely also in jython.

Great!

The only minor issue is then that, being ij2, the command is not macro-recordable.

Indeed the commands are murch easier to create but have this macro-recording issue (@NicoKiaru and I really hope it will be fixed soon)

I created a script folder with an ijm and groovy example, and I will modify the readme to point to them.

Cheers,

Romain