Hi List,
I'm trying to write a plugin that 1) Uses MaximumFinder to produce a watershed image 2) Uses ParticleAnalyzer to make rois from these segments 3) Saves these rois with RoiManager I can successfully make the watershed image and analyze the particles. However, if I try to save the resulting rois using the code below, RoiManager gives me an error "the selection list is empty". However, while this code is running, I can see the RoiManager, and there are selections in the window. Furthermore, if I run the "Show All" command on the image containing the particles, they show up as expected. I've made this same sequence work without problems using the macro language. I'm including the code I run to accomplish this below, as well. Can anyone tell me what I'm doing wrong/differently than the macro case? Thanks, Adam ----------- This plugin code does not work ----------------------- ResultsTable rt = new ResultsTable(); boolean excludeOnEdges = false; boolean isEDM = false; ImagePlus max = new ImagePlus("segmented", mf.findMaxima(pmanip,1,1,MaximumFinder.SEGMENTED, excludeOnEdges,isEDM)); RoiManager rm = new RoiManager(false); int options = ParticleAnalyzer.ADD_TO_MANAGER+ParticleAnalyzer.INCLUDE_HOLES+ParticleAnalyzer.SHOW_NONE; int measurements = 0; double minSize = 0; double maxSize = 1000; double minCirc = 0; double maxCirc = 1; ParticleAnalyzer pa = new ParticleAnalyzer( options,measurements,rt, minSize,maxSize,minCirc,maxCirc); pa.analyze(max); max.show(); rm.runCommand("Show All"); // This shows the rois, so I know they're in the RoiManager rm.runCommand("Save","1.zip"); // Won't save... "selection list is empty" -------------- End plugin code ----------------------- ----------------- This macro code works fine ------------------ run("Find Maxima...", "noise=1 output=[Segmented Particles]"); cell_mask = getImageID(); roiManager("Reset"); run("Analyze Particles...", "size=0-Infinity circularity=0-1 show=Nothing clear add"); roiManager("Save", path_to_selections); selectImage(cell_mask); close(); --------------- end macro code ----------------- ===== Science is more of an art than a science. |
Hi Adam,
maybe you have two instances of RoiManager, the "standard" one and the one created as 'rm'? My solution would be RoiManager rm = RoiManager.getInstance(); after the particle analyzer has created a RoiManager. Michael ________________________________________________________________ On 25 Feb 2010, at 08:48, Adam wrote: > Hi List, > > I'm trying to write a plugin that > 1) Uses MaximumFinder to produce a watershed image > 2) Uses ParticleAnalyzer to make rois from these segments > 3) Saves these rois with RoiManager > > I can successfully make the watershed image and analyze the > particles. However, if I try to save the resulting rois using the > code below, RoiManager gives me an error "the selection list is > empty". However, while this code is running, I can see the > RoiManager, and there are selections in the window. Furthermore, > if I run the "Show All" command on the image containing the > particles, they show up as expected. > > I've made this same sequence work without problems using the macro > language. I'm including the code I run to accomplish this below, > as well. Can anyone tell me what I'm doing wrong/differently than > the macro case? > > > Thanks, > Adam > > > ----------- This plugin code does not work ----------------------- > ResultsTable rt = new ResultsTable(); > boolean excludeOnEdges = false; > boolean isEDM = false; > ImagePlus max = > new ImagePlus("segmented", > mf.findMaxima(pmanip,1,1,MaximumFinder.SEGMENTED, > excludeOnEdges,isEDM)); > > RoiManager rm = new RoiManager(false); > > int options = > ParticleAnalyzer.ADD_TO_MANAGER > +ParticleAnalyzer.INCLUDE_HOLES+ParticleAnalyzer.SHOW_NONE; > int measurements = 0; > double minSize = 0; > double maxSize = 1000; > double minCirc = 0; > double maxCirc = 1; > ParticleAnalyzer pa = > new ParticleAnalyzer( > > options,measurements,rt, > > minSize,maxSize,minCirc,maxCirc); > pa.analyze(max); > max.show(); > rm.runCommand("Show All"); // This shows the rois, so I > know they're in the RoiManager > rm.runCommand("Save","1.zip"); // Won't save... > "selection list is empty" > -------------- End plugin code ----------------------- > > ----------------- This macro code works fine ------------------ > run("Find Maxima...", "noise=1 output=[Segmented Particles]"); > > cell_mask = getImageID(); > > roiManager("Reset"); > run("Analyze Particles...", "size=0-Infinity circularity=0-1 > show=Nothing clear add"); > roiManager("Save", path_to_selections); > selectImage(cell_mask); > close(); > --------------- end macro code ----------------- > > ===== > Science is more of an art than a science. |
----- Original Message ----
> maybe you have two instances of RoiManager, the "standard" one and the one > created as 'rm'? > > My solution would be > RoiManager rm = RoiManager.getInstance(); > after the particle analyzer has created a RoiManager. That worked, thank you! In general, do ImageJ classes make their own instances of other classes that they need? Does MaximumFinder make its own ResultsTable instance, as well? One of the options to MaximumFinder is 'COUNT' which says that it it simply writes the number of maxima to ResultsTable. I have not been able to get this to work, either. I'm wondering if it is for a similar reason. Adam |
Hi Adam,
most panels in ImageJ are "singletons", i.e., ImageJ has only one instance. It would be confusing for the user to see two ROI Managers or two "Brightness&Contrast" panels: which one is the correct one? Plugins can create their own instances of some panels, including the ResultsTable, e.g. to avoid interfering with that of ImageJ (in that case, one should set a custom title, different from "Results"). ResultsTable.getResultsTable(), equivalent to Analyzer.getResultsTable () should give you the one used by ImageJ. Also the MaximumFinder uses ResultsTable.getResultsTable(). Michael ________________________________________________________________ On 26 Feb 2010, at 02:57, Adam wrote: > ----- Original Message ---- > >> maybe you have two instances of RoiManager, the "standard" one and >> the one >> created as 'rm'? >> >> My solution would be >> RoiManager rm = RoiManager.getInstance(); >> after the particle analyzer has created a RoiManager. > > That worked, thank you! > > In general, do ImageJ classes make their own instances of other > classes that they need? > > Does MaximumFinder make its own ResultsTable instance, as well? > One of the options to MaximumFinder is 'COUNT' which says that it > it simply writes the number of maxima to ResultsTable. I have not > been able to get this to work, either. I'm wondering if it is for a > similar reason. > > Adam |
In reply to this post by Adam Waite
Hi Adam,
I'm very interested in knowing whether your call to rm.runCommand("Show All"); does in fact work? I ask because I experience that if I do the same thing you do (i.e. call ParticleAnalyzer) and follow with the code RoiManager rm = RoiManager.getInstance(); rm.runCommand("Show All"); and then run my code the ROI in the ROI Manager does not get displayed (by label or number) on my image. Have you experienced any such thing? |
Hi Cspr,
> I'm very interested in knowing whether your call to > rm.runCommand("Show All"); > does in fact work? Yes. Strangely, even when I was unable to save the selections and got an error from RoiManager telling me that "the selection list is empty" (i.e., before I fixed my code by adding a call to the "getInstance()" method), I could see the RoiManager *and* the "Show All" command worked (in the sense that the selections, with labels, appeared on my image). Adam |
Free forum by Nabble | Edit this page |