I am writing a Python script in which I want to save an ROI.
I thought that RoiWriter ought to do this, with the following method: |*saveRoi <http://imagej.nih.gov/ij/developer/api/ij/plugin/filter/RoiWriter.html#saveRoi%28ij.ImagePlus%29>*(ImagePlus <http://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html> imp)| However, I do not see how to specify the path. RoiReader takes the path as an argument, but not RoiWriter. So, tried saving with the Roi manager, while recording the command. However, the save command did nto record anything. Open form a file recorded, as did everything else I tried, but not Save... So I am apparently missing something really obvious, but I must ask -- how does one save an Roi to a file, similar to what the Roi manager does? Thanks is advance, --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Feb 1, 2014, at 3:46 PM, Aryeh Weiss wrote:
> I am writing a Python script in which I want to save an ROI. > I thought that RoiWriter ought to do this, with the following method: > > |*saveRoi <http://imagej.nih.gov/ij/developer/api/ij/plugin/filter/RoiWriter.html#saveRoi%28ij.ImagePlus%29>*(ImagePlus <http://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html> imp)| > > However, I do not see how to specify the path. RoiReader takes the path as an argument, but not RoiWriter. > So, tried saving with the Roi manager, while recording the command. However, the save command did nto record anything. Open form a file recorded, as did everything else I tried, but not Save... > > So I am apparently missing something really obvious, but I must ask -- how does one save an Roi to a file, similar to what the Roi manager does? Try using the command recorder (Plugins>Macros>Record). This is what I get when I record the File>Save As>Selection command: IJ.saveAs(imp, "Selection", path); -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 2/2/14, 2:17 AM, Rasband, Wayne (NIH/NIMH) [E] wrote:
> On Feb 1, 2014, at 3:46 PM, Aryeh Weiss wrote: > >> I am writing a Python script in which I want to save an ROI. >> I thought that RoiWriter ought to do this, with the following method: >> >> |*saveRoi <http://imagej.nih.gov/ij/developer/api/ij/plugin/filter/RoiWriter.html#saveRoi%28ij.ImagePlus%29>*(ImagePlus <http://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html> imp)| >> >> However, I do not see how to specify the path. RoiReader takes the path as an argument, but not RoiWriter. >> So, tried saving with the Roi manager, while recording the command. However, the save command did nto record anything. Open form a file recorded, as did everything else I tried, but not Save... >> >> So I am apparently missing something really obvious, but I must ask -- how does one save an Roi to a file, similar to what the Roi manager does? > Try using the command recorder (Plugins>Macros>Record). This is what I get when I record the File>Save As>Selection command: > > IJ.saveAs(imp, "Selection", path); > > -wayne > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > Thank you for your quick reply. I tried using the command recorder while saving the ROI with the ROI Manager, using More>Save... , but this did nto record anything. 1. Why did that not work? 2. Why does the saveRoi method not accept a path to save and ROI the way that readRoi does? Is this just the way ti developed, or is the something sbout ROIsl that makes it unreasonable to do that? Best regards, --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On Feb 1, 2014, at 10:51 PM, Aryeh Weiss wrote:
> On 2/2/14, 2:17 AM, Rasband, Wayne (NIH/NIMH) [E] wrote: >> On Feb 1, 2014, at 3:46 PM, Aryeh Weiss wrote: >> >>> I am writing a Python script in which I want to save an ROI. >>> I thought that RoiWriter ought to do this, with the following method: >>> >>> |*saveRoi <http://imagej.nih.gov/ij/developer/api/ij/plugin/filter/RoiWriter.html#saveRoi%28ij.ImagePlus%29>*(ImagePlus <http://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html> imp)| >>> >>> However, I do not see how to specify the path. RoiReader takes the path as an argument, but not RoiWriter. >>> So, tried saving with the Roi manager, while recording the command. However, the save command did nto record anything. Open form a file recorded, as did everything else I tried, but not Save... >>> >>> So I am apparently missing something really obvious, but I must ask -- how does one save an Roi to a file, similar to what the Roi manager does? >> Try using the command recorder (Plugins>Macros>Record). This is what I get when I record the File>Save As>Selection command: >> >> IJ.saveAs(imp, "Selection", path); >> >> -wayne >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > Thank you for your quick reply. > I tried using the command recorder while saving the ROI with the ROI Manager, using > More>Save... , but this did nto record anything. > > 1. Why did that not work? It did not work because of a bug that is fixed in the latest ImageJ daily build (1.48r1). Saving a single ROI with the ROI Manager now records imp = IJ.getImage(); IJ.saveAs(imp, "Selection", path); when the recorder is in "JavaScript", "BeanShell" or "Java" mode. 2. Why does the saveRoi method not accept a path to save and ROI the way that readRoi does? > Is this just the way ti developed, or is the something sbout ROIsl that makes it unreasonable to do that? The daily build adds two static methods for saving and opening ROIs: RoiEncoder.save(roi, path) RoiDecoder.open(path) Here is a JavaScript that demonstrates how to use these methods: dir = IJ.getDirectory("temp"); path = dir + "test.roi"; imp = IJ.getImage(); roi = imp.getRoi(); if (roi==null) IJ.error("No ROI"); ok = RoiEncoder.save(roi, path); print("ok="+ok); imp.deleteRoi(); IJ.wait(2000); roi = RoiDecoder.open(path); if (roi==null) print("Error opening "+path); else imp.setRoi(roi); -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 2/2/14, 8:48 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:
> On Feb 1, 2014, at 10:51 PM, Aryeh Weiss wrote: > >> On 2/2/14, 2:17 AM, Rasband, Wayne (NIH/NIMH) [E] wrote: >>> On Feb 1, 2014, at 3:46 PM, Aryeh Weiss wrote: >>> >>>> I am writing a Python script in which I want to save an ROI. >>>> I thought that RoiWriter ought to do this, with the following method: >>>> >>>> |*saveRoi <http://imagej.nih.gov/ij/developer/api/ij/plugin/filter/RoiWriter.html#saveRoi%28ij.ImagePlus%29>*(ImagePlus <http://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html> imp)| >>>> >>>> However, I do not see how to specify the path. RoiReader takes the path as an argument, but not RoiWriter. >>>> So, tried saving with the Roi manager, while recording the command. However, the save command did nto record anything. Open form a file recorded, as did everything else I tried, but not Save... >>>> >>>> So I am apparently missing something really obvious, but I must ask -- how does one save an Roi to a file, similar to what the Roi manager does? >>> Try using the command recorder (Plugins>Macros>Record). This is what I get when I record the File>Save As>Selection command: >>> >>> IJ.saveAs(imp, "Selection", path); >>> >>> -wayne >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >> Thank you for your quick reply. >> I tried using the command recorder while saving the ROI with the ROI Manager, using >> More>Save... , but this did nto record anything. >> >> 1. Why did that not work? > It did not work because of a bug that is fixed in the latest ImageJ daily build (1.48r1). Saving a single ROI with the ROI Manager now records > > imp = IJ.getImage(); > IJ.saveAs(imp, "Selection", path); > > when the recorder is in "JavaScript", "BeanShell" or "Java" mode. > > 2. Why does the saveRoi method not accept a path to save and ROI the way that readRoi does? >> Is this just the way it developed, or is there something about ROIs that makes it unreasonable to do that? > The daily build adds two static methods for saving and opening ROIs: > > RoiEncoder.save(roi, path) > RoiDecoder.open(path) Thank you very much for these additions and the fix. Besides what is written above, I found that now the RoiManager save command works properly to save the entire Roi set, as in: rm.runCommand("Save", doSomething.outDir+doSomething.inputPrefix+"_RoiSet.zip" ) where "doSomething" is what my mouse listener calls, shamelessly copied from one of the many useful examples provided, --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |