Posted by
Michael Schmid on
Feb 25, 2010; 5:40pm
URL: http://imagej.273.s1.nabble.com/Can-t-save-rois-with-RoiManager-in-plugin-tp3689085p3689088.html
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.