// TraceROI Multi-Image Straightening Macro ////////////////////////////////////////////////////////////////////////////// // // v1 // By T W Lee twlee at twlee dot nz // 2015-12-04 // ////////////////////////////////////////////////////////////////////////////// // // Convenience macro for straightening multiple images with TraceROI. Provides // the following macro commands: // // Begin (shortcut key: b) // Initialize macro & TraceROI with foreground image. // Save (shortcut key: s) // Straighten all segments, and save ROIs and straightened images. // Close (shortcut key: c) // Close all images, warning if not saved. // Select save location // Select directory to save segments and images to, called automatically // on first execution of 'Save' command. // // // Example usage: // 1) Open an image. // // 2) Press the 'b' key or use Plugins\Macros\Begin. This will // initialize TraceROI. // // 3) Trace the ROIs using TraceROI. // // 4) Press the 's' key or Plugins\Macros\Save. The first time you run // this it will ask for a folder to save to. Then, the macro will run // the 'TraceROI Join & straighten all subsegments' command to // straighten all segments. The macro will save the traced // segments (ROIs) and the straightened segment images in your chosen // folder. // // 5) Press 'c' or Plugins\Macros\Close to close all images. // ////////////////////////////////////////////////////////////////////////////// var saveLocation = ""; var title = ""; var saved = 0; function getWindowNamed(wndName, maxWait, showError) { // return first window name containing str waited = 0; waitStep = 100; while (waited0) basename = substring(title,0,ext_index); else basename = title; path = saveLocation + basename+ "_segmentROIs.zip"; roiManager("Deselect"); roiManager("Save", path); run("TraceROI Join & straighten all subsegments"); for (i=1;i<100;i++) { segment_imgname = basename+"_segment"+i; nextWnd = getWindowNamed(segment_imgname,200,false); if (nextWnd == "") break; selectWindow(nextWnd); wndType = getInfo("window.type"); if (wndType=="Image") { path = saveLocation + nextWnd + ".tif"; confirmForeground(nextWnd); } saveAs(path); saved+=1; } print ("Saved "+saved+" segments for "+title); } macro "Close [c]" { if (saved==0) showMessageWithCancel("TraceROI macro","Segments not saved, close anyway?"); run("Close All"); }