Hello ImageJers,
When I run the following macro (in order to "rotate" a bunch of ROIs in the ROIManager), I get an "out of memory" error after a hundred of rois has been processed . If I comment out the setBatchMode lines, it works (but much slower). It might be related to the roiManager, I wrote another macro duplicating and rotating images in batchmode, without any issue. I tested on OS 10.5 and winXP (jvm1.6_03) with ij1.41g/h with the same results, not yet tested on linux using "Monitor Memory", one can see the macro eating memory quite fast. I uploaded a sample "source" image and a quite big ROI set there: http://xfer.curie.fr/get/gYrE1HY3BYl/OutOfMemSamples.tar I tried to summon ij.IJ.freeMemory and friends as seen in a former thread on the list, but it didn't help. It seems to be a bit more difficult than I expected. Any hint? Thanks sebastien (off topic: I couldn't simply copy and fill all rois on a new black image, rotate and use "analyze particles" to populate the roi manager cause close rois/particles were joined after rotation.) macro "rotateROIs [F1]" { srcpath = File.openDialog("Source image?"); roispath = File.openDialog("Roi set?"); open(srcpath); sid = getImageID(); roiManager("reset"); open(roispath); rot_angle = getNumber("Rot Angle", 5); setBatchMode(true); rois_rotateAll(sid, rot_angle); setBatchMode(false); } function rois_rotateAll(srcid, angle) { iter = 0; roicnt = roiManager("count"); oldroicnt = roicnt; run("Set Measurements...", "area mean min integrated limit redirect=None decimal=3"); setForegroundColor(255, 255, 255); i = 0 ; while ( i < roicnt ) { selectImage(srcid); run("Select All"); run("Duplicate...", "title=TMP_ROIS_masks"); dupid = getImageID(); run("Select All"); run("Cut"); run("8-bit"); setVoxelSize(1, 1, 1, "pixels"); roiManager("Select", i); roiManager("Fill"); run("Select None"); run("Arbitrarily...", "angle=" + angle + " grid=1 interpolate enlarge"); setThreshold(250,255); run("Select None"); run("Clear Results"); run("Analyze Particles...", "size=5-Infinity circularity=0.00-1.00 show=Nothing exclude clear include record"); if ( nResults == 1 ) { x = getResult("XStart", 0); y = getResult("YStart", 0); doWand(x, y); roiManager("Update"); i++; } else { print("warning: rotation of roi " + i + " gives unexpected number of results: " + nResults); print("warning: deletion of roi "+ i); roiManager("Delete"); roicnt--; } selectImage(dupid); run("Select None"); close(); //useless call to freeMemory every 10 iterations //iter++; //if ( (iter % 10) ==0) // { // print(call("ij.IJ.freeMemory")); // wait(1000); //} } } |
Can anyone let me know how to pass parameter to a macro. How do I know
the options for a macro. The specific problem I have is as follows:> I want to run("Channels Tool...") and I only want to check channels 1, 3, and 5. How do I write it in the macro? Thanks! Zhengyu > > Zhengyu Pang, Ph.D. Bioanalytics and Protein Science Laboratory Biosciences Global Technology Organization > One Research Circle, K1 5B37A > Niskayuna, NY12309 > * [hidden email] > *(518) 387-4015 > |
On Jul 8, 2008, at 3:49 PM, Pang, Zhengyu (GE, Research) wrote:
> Can anyone let me know how to pass parameter to a macro. How do I know > the options for a macro. > > The specific problem I have is as follows:> > > I want to run("Channels Tool...") and I only want to check channels 1, > 3, and 5. How do I write it in the macro? Stack.setActiveChannels("10101"); This function was added to the macro language in ImageJ 1.41b. -wayne |
In reply to this post by seb-7
> Hello ImageJers,
> > When I run the following macro (in order to "rotate" a bunch of ROIs > in the ROIManager), I get an "out of memory" error after a hundred of > rois has been processed . > If I comment out the setBatchMode lines, it works (but much slower). > It might be related to the roiManager, I wrote another macro > duplicating and rotating images in batchmode, without any issue. > I tested on OS 10.5 and winXP (jvm1.6_03) with ij1.41g/h with the > same results, not yet tested on linux > using "Monitor Memory", one can see the macro eating memory quite fast. > I uploaded a sample "source" image and a quite big ROI set there: > > http://xfer.curie.fr/get/gYrE1HY3BYl/OutOfMemSamples.tar > > I tried to summon ij.IJ.freeMemory and friends as seen in a former > thread on the list, but it didn't help. > It seems to be a bit more difficult than I expected. > Any hint? > Thanks This bug is fixed in the v1.41h daily build. The ROI Manager "Update" option was saving a reference to the image, which prevented it from being garbage collected. There is also a small bug in the macro that causes it to fail if the background color is not black. This can be fixed by adding setBackgroundColor(0, 0, 0); -wayne > sebastien > > (off topic: I couldn't simply copy and fill all rois on a new black > image, rotate and use "analyze particles" to populate the roi > manager cause close rois/particles were joined after rotation.) > > > macro "rotateROIs [F1]" > { > srcpath = File.openDialog("Source image?"); > roispath = File.openDialog("Roi set?"); > open(srcpath); > sid = getImageID(); > roiManager("reset"); > open(roispath); > rot_angle = getNumber("Rot Angle", 5); > setBatchMode(true); > rois_rotateAll(sid, rot_angle); > setBatchMode(false); > } > > > function rois_rotateAll(srcid, angle) > { > iter = 0; > roicnt = roiManager("count"); > oldroicnt = roicnt; > run("Set Measurements...", "area mean min integrated limit > redirect=None decimal=3"); > setForegroundColor(255, 255, 255); > i = 0 ; > while ( i < roicnt ) > { > selectImage(srcid); > run("Select All"); > run("Duplicate...", "title=TMP_ROIS_masks"); > dupid = getImageID(); > run("Select All"); > run("Cut"); > run("8-bit"); > setVoxelSize(1, 1, 1, "pixels"); > roiManager("Select", i); > roiManager("Fill"); > run("Select None"); > run("Arbitrarily...", "angle=" + angle + " grid=1 interpolate > enlarge"); > setThreshold(250,255); > run("Select None"); > run("Clear Results"); > run("Analyze Particles...", "size=5-Infinity > circularity=0.00-1.00 show=Nothing exclude clear include record"); > if ( nResults == 1 ) > { > x = getResult("XStart", 0); > y = getResult("YStart", 0); > doWand(x, y); > roiManager("Update"); > i++; > } > else > { > print("warning: rotation of roi " + i + " gives unexpected > number of results: " + nResults); > print("warning: deletion of roi "+ i); > roiManager("Delete"); > roicnt--; > } > selectImage(dupid); > run("Select None"); > close(); > //useless call to freeMemory every 10 iterations > //iter++; > //if ( (iter % 10) ==0) > // { > // print(call("ij.IJ.freeMemory")); > // wait(1000); > //} > } > } > |
Wayne Rasband wrote:
> This bug is fixed in the v1.41h daily build. The ROI Manager "Update" > option was saving a reference to the image, which prevented it from > being garbage collected. There is also a small bug in the macro that > causes it to fail if the background color is not black. This can be > fixed by adding > > setBackgroundColor(0, 0, 0); Thanks a lot Wayne, it is at least 20x faster with setBatchMode(true). And I didn't think of the background color bug, I need to check other macros as I always assume black background... Thanks! Best regards sebastien |
Free forum by Nabble | Edit this page |