Created
January 23, 2026 10:52
-
-
Save ekatrukha/1361c256f7c6f243784bf1c32a645cfd to your computer and use it in GitHub Desktop.
run and save KymoResliceWide over multiple ROIs in ROI Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** macro running KymoResliceWide plugin | |
| over multiple ROIs present in the ROI Manager | |
| and saving output. | |
| Requires a stack opened in ImageJ | |
| and a set of line (or polyline/freehand) ROIs in ROI Manager **/ | |
| sVersion = "20260123"; | |
| //check image | |
| if (nImages < 1) | |
| { | |
| exit("This macro needs an input image. Open something"); | |
| } | |
| origID = getImageID(); | |
| sTitle = getTitle(); | |
| Stack.getDimensions(width, height, channels, slices, frames); | |
| if(slices == 1 && frames == 1) | |
| { | |
| exit("A stack is required, not a single."); | |
| } | |
| nRoiCount = roiManager("count"); | |
| if(nRoiCount == 0) | |
| { | |
| exit("There are no ROIs in ROI Manager!"); | |
| } | |
| Dialog.create("KymoResliceWide parameters"); | |
| items = newArray("Maximum", "Average"); | |
| Dialog.addChoice("Intensity projection", items) | |
| Dialog.addCheckbox("Rotate 90 degrees", false); | |
| Dialog.addCheckbox("Add ROI to overlay", false); | |
| Dialog.addCheckbox("Ignore image calibration", false); | |
| Dialog.addCheckbox("Ignore NaN values", true); | |
| Dialog.show(); | |
| runstring = "intensity="; | |
| runstring = runstring + Dialog.getChoice(); | |
| if(Dialog.getCheckbox()) | |
| { | |
| runstring = runstring + " rotate"; | |
| } | |
| if(Dialog.getCheckbox()) | |
| { | |
| runstring = runstring + " add"; | |
| } | |
| if(Dialog.getCheckbox()) | |
| { | |
| runstring = runstring + " ignore"; | |
| } | |
| if(Dialog.getCheckbox()) | |
| { | |
| runstring = runstring + " ignore_0"; | |
| } | |
| //print(runstring); | |
| //ask for a folder to save files | |
| sOutFolder = getDir("Choose a folder to save kymographs"); | |
| print("\\Clear"); | |
| print ("Multi Kymoreslice (v. " + sVersion + ") log"); | |
| print ("Input image (stack) title:" + sTitle); | |
| print("Number of ROIs " + toString(nRoiCount)); | |
| sTimeStamp = getTimeStamp_sec(); | |
| for(nRoi = 0; nRoi < nRoiCount; nRoi++) | |
| { | |
| roiManager("select", nRoi); | |
| sRoiName = RoiManager.getName(nRoi); | |
| //print(selectionType); | |
| if(selectionType == 5 || //straight | |
| selectionType == 6 || //segmented line | |
| selectionType == 7 ) // freehand line | |
| { | |
| selectImage(origID); | |
| run("KymoResliceWide", runstring); | |
| saveAs("Tiff", sOutFolder + "ROI" + IJ.pad(nRoi + 1, 3) + "_" + sRoiName + ".tif" ); | |
| close(); | |
| } | |
| else | |
| { | |
| print("ROI "+ sRoiName + " is not a line ROI, skipping!"); | |
| } | |
| } | |
| selectImage(origID); | |
| selectWindow("Log"); | |
| saveAs("Text", sOutFolder + sTimeStamp + "_multikymo_log.txt"); | |
| function getTimeStamp_sec() | |
| { | |
| // returns timestamp: yearmonthdayhourminutesecond | |
| getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec); | |
| TimeStamp = toString(year)+IJ.pad(month+1,2)+IJ.pad(dayOfMonth,2); | |
| TimeStamp = TimeStamp+IJ.pad(hour,2)+IJ.pad(minute,2)+IJ.pad(second,2); | |
| return TimeStamp; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment