This post was updated on .
*UPDATE*: The code still fails, BUT I got it to stop throwing the error...by calling RoiManager by the name I'd set for it earlier in the script. Ahem. Any idea why moveRoisToOverlay might still not be working?
Hi all, I'm trying to move all (several hundred) ROIs from a processed/mask image onto the original (well, a duplicate of it) in Jython. The error I get is: TypeError: moveRoisToOverlay(): expected 2 args; got 1 But the imagej API says the usage is: moveRoisToOverlay(ImagePlus imp). What am I doing wrong? Here are my imports: import os import time from ij import IJ, ImagePlus, Prefs from ij.gui import GenericDialog, WaitForUserDialog, PolygonRoi, Roi from ij.plugin import Duplicator from ij.process import ImageConverter, ImageProcessor from ij.measure import ResultsTable, Measurements <b>from ij.plugin.frame import RoiManager</b> from ij.plugin.filter import Binary, MaximumFinder from ij.plugin.filter import ParticleAnalyzer as pa from jarray import array import math import csv And here's the bit of script that fails (don't mind the sloppiness, it's in testing): if RoiManager.moveRoisToOverlay(imp3): print "RoiManager.moveRoisToOverlay(imp3) worked" else: print "RoiManager.moveRoisToOverlay(imp3) didn't work. Trying getRoisAsArray" for roi in RoiManager.getInstance().getRoisAsArray(): imp3.setRoi(roi) print "imp3.setRoi(roi) executed without error. Now updateAndDraw-ing." imp3.updateAndDraw() Any suggestions would be much appreciated. Thanks in advance! |
jswalker,
Pasting your method call in from Nabble (it doesn't get copied to the email list...), I assume your error message occurs when you run this line: if RoiManager.moveRoisToOverlay(imp3): From the API documentation (you already referenced, but for others who don't know, go to http://rsb.info.nih.gov/ij/developer/api/, then select the RoiManager class in lower left pane, and finally find the moveRoisToOverlay method in right-hand pane), you'll see it is an instance method, *not* a static method. That means you need to call it with an instance of RoiManager, not the class name as you called it. Something more like r = RoiManager.getInstance() # getInstance() *is* a static method r.moveRoisToOverlay(imp3) # now you have 2 arguments--"r", the RoiManager instance and "imp3". Your if statement can then be something like if r is not None: I just took your snippets of code, and suggested other snippets without seeing the whole thing, so I hope this works, and gets you started. *-- Jim Passmore* Principal Scientist Sealed Air Corporation On Thu, May 5, 2016 at 10:34 AM, jswalker <[hidden email]> wrote: > Hi all, > > I'm trying to move all (several hundred) ROIs from a processed/mask image > onto the original (well, a duplicate of one) in Jython. The error I get is: > TypeError: moveRoisToOverlay(): expected 2 args; got 1 > > But the imagej API says the usage is: moveRoisToOverlay(ImagePlus imp). > What > am I doing wrong? > > Here are my imports: > > import os > import time > > from ij import IJ, ImagePlus, Prefs > from ij.gui import GenericDialog, WaitForUserDialog, PolygonRoi, Roi > from ij.plugin import Duplicator > from ij.process import ImageConverter, ImageProcessor > from ij.measure import ResultsTable, Measurements > *from ij.plugin.frame import RoiManager* > from ij.plugin.filter import Binary, MaximumFinder > from ij.plugin.filter import ParticleAnalyzer as pa > from jarray import array > import math > import csv > > And here's the bit of script that fails (don't mind the sloppiness, it's in > testing): > > > > Any suggestions would be much appreciated. Thanks in advance! > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/Jython-moveRoisToOverlay-unexpected-number-of-args-tp5016320.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |