Skip to content

Commit

Permalink
scripts to export annotations as rois and create masks from them
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-baecker committed Sep 23, 2024
1 parent 5d14e41 commit 0dbc8a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.class
# User-specific stuff
**/.idea/**

18 changes: 18 additions & 0 deletions volker/toolsets/tree_ring_segmentation/groovy/export_rois.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ij.plugin.frame.RoiManager


def imageData = getCurrentImageData()
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def path = buildFilePath(PROJECT_BASE_DIR, name + ".zip")

def annotations = getAnnotationObjects()
def roiMan = new RoiManager(false)
double x = 0
double y = 0
double downsample = 1 // Increase if you want to export to work at a lower resolution
annotations.each {
def roi = IJTools.convertToIJRoi(it.getROI(), x, y, downsample)
roiMan.addRoi(roi)
}
roiMan.runCommand("Save", path)
roiMan.runCommand("Reset")
39 changes: 37 additions & 2 deletions volker/toolsets/tree_ring_segmentation/mri_tree_ring_tools.ijm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro "extract masks Action Tool - C000T4b12e" {


macro "batch extract masks Action Tool - C000T4b12b" {
batchExtractMasks();
batchExtractMasksFromZip();
}


Expand All @@ -40,7 +40,7 @@ function extractMasks() {
}
}


// Unused
function batchExtractMasks() {
folder = getDir("Select the input folder!");
if (!File.exists(folder + "masks/")) {
Expand All @@ -59,6 +59,41 @@ function batchExtractMasks() {
}
}

function batchExtractMasksFromZip() {
folder = getDir("Select the input folder!");
if (!File.exists(folder + "masks/")) {
File.makeDirectory(folder + "masks/");
}
files = getFileList(folder);
zipFiles = filterFilesByExtension(files, "zip");
for (i=0; i<zipFiles.length; i++) {
zipFile = zipFiles[i];
image = replace(zipFile, ".zip", ".tif");
open(folder + image);
Overlay.remove()
roiManager("open", folder + zipFile);
run("From ROI Manager");
roiManager("reset");
extractMasks();
save(folder + "masks/" + image);
close("*");
}
}


function filterFilesByExtension(files, ext) {
results = newArray(0);
for (i=0; i<files.length; i++) {
file = files[i];
if (!endsWith(file, "." + ext)) {
continue;
}
results = Array.concat(results, file);
}
return results;
}


function showOptionsForCommand(command) {
call("ij.Prefs.set", "mri.options.only", "true");
run(command);
Expand Down

0 comments on commit 0dbc8a3

Please sign in to comment.