Skip to content

Instantly share code, notes, and snippets.

@flowernert
Last active November 24, 2022 10:41
Show Gist options
  • Save flowernert/d609ce8c3073b7dfb19e6e3bc712d80b to your computer and use it in GitHub Desktop.
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.
// 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