Last active
November 25, 2022 11:17
-
-
Save flowernert/b6ab9f8f6c415dab62a447edde3d8dc8 to your computer and use it in GitHub Desktop.
ImageJ FiJi : retrieving indices or names of multiple selected ROIs
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
//returns an array of selected ROIs numeric indices | |
function getSelectedROIsIndexes() { | |
//calls existing java method, then parse it to an ImageJ Macro langage Array | |
rois = eval("script","java.util.Arrays.toString(RoiManager.getInstance().getSelectedIndexes())"); | |
rois = substring(rois, indexOf(rois, "[")+1, lastIndexOf(rois, "]")); | |
rois = split(rois, ","); | |
selectedRois = newArray(rois.length); | |
for (i = 0; i < rois.length; i++) { | |
selectedRois[i] = parseInt(rois[i]); | |
} | |
return selectedRois; | |
} | |
//leverage previously created function to return an array of selected ROIs names | |
function getSelectedROIsNames() { | |
indexes = getSelectedROIsIndexes(); | |
names = newArray(indexes.length); | |
for (i = 0; i < indexes.length; i++) { | |
names[i] = RoiManager.getName(indexes[i]); | |
} | |
return names; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
demo code