Last active
November 24, 2022 10:41
-
-
Save flowernert/d609ce8c3073b7dfb19e6e3bc712d80b to your computer and use it in GitHub Desktop.
ImageJ shift RoiSet numbering : rename your ROIs first 4 numbers (the xxxx in your ROI xxxx-yyyy-zzzz) by shifting the numbering according to value giver in the Dialog. Useful for ROIs generated on a stack that was not yet complete and some images have been appended to the beginning of the stack later on.
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
// licensed CC BY-NC-SA Florian Wernert | |
macro "shift RoiSet numbering" { | |
roiManager("select", 0); | |
roi1_name = split(Roi.getName(), "-"); | |
min_val = -1* (parseInt(roi1_name[0]) - 1); | |
max_val = pow(2, 16); | |
Dialog.create("By how many do you want to shift"); | |
Dialog.addSlider("Shift by :", min_val , max_val, 0); | |
Dialog.show(); | |
shift_n = Dialog.getNumber(); | |
print(shift_n); | |
n = roiManager('count'); | |
for (i = 0; i < n; i++) { | |
roiManager('select', i); | |
rn = Roi.getName(); | |
tokens = split(rn, "-"); | |
rn1 = tokens[0]; | |
new_rn1 = IJ.pad(toString(parseInt(rn1) + shift_n), 4); | |
new_roiName = new_rn1 + "-" + tokens[1] + "-" + tokens[2] + "-" + tokens[3] + "-" + tokens[4]; | |
print(rn + " becomes " + new_roiName); | |
roiManager("rename", new_roiName); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment