-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb_to_labels.ijm
40 lines (32 loc) · 1.26 KB
/
rgb_to_labels.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Set batch mode to true to speed up the macro by disabling the display of images during processing.
setBatchMode(true);
// Ask the user to select the input directory
inputDir = getDirectory("Choose Input Directory");
// Create the output directory and subfolders in the same location as the input
outputDir = inputDir + "masks/";
File.makeDirectory(outputDir);
File.makeDirectory(outputDir + "0/");
File.makeDirectory(outputDir + "1/");
File.makeDirectory(outputDir + "2/");
// Get a list of files in the input directory
fileList = getFileList(inputDir);
// Loop through each file
for (i = 0; i < fileList.length; i++) {
if (endsWith(fileList[i], ".tif")) {
// Open the current file
open(inputDir + fileList[i]);
// Split the channels
run("Split Channels");
// Save the channels in separate folders with the same name as the original file
selectWindow(fileList[i] + " (red)");
saveAs("Tiff", outputDir + "0/" + fileList[i]);
selectWindow(fileList[i] + " (green)");
saveAs("Tiff", outputDir + "1/" + fileList[i]);
selectWindow(fileList[i] + " (blue)");
saveAs("Tiff", outputDir + "2/" + fileList[i]);
// Close all open images
run("Close All");
}
}
setBatchMode(false);
print("Batch processing complete!");