-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathndpi_rgba_to_8bit.ijm
60 lines (46 loc) · 2.14 KB
/
ndpi_rgba_to_8bit.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This script converts NDPI files to 8-bit single color TIFFs
// Enable batch mode to speed up the macro by disabling the display of images during processing.
setBatchMode(true);
// Prompt the user to select the directory containing the images
inputFolder = getDirectory("Select input directory");
// Get a list of NDPI files in the folder
list = getFileList(inputFolder);
// Set the bit depth to 8
bit_depth = 8;
// Prompt the user to enter a letter representing the color channel (R, G, or B)
inputString = getString("Select color channel (R, G, or B):", "B");
// Prompt the user to enter the series
selectedSeries = getNumber("Enter the series you want to select:", 3);
// Convert the input string to a number representing the color channel
colorChannel = -1; // initialize to an invalid value
if (inputString == "R") {
colorChannel = 0;
} else if (inputString == "G") {
colorChannel = 1;
} else if (inputString == "B") {
colorChannel = 2;
} else {
// Show an error message if the input is invalid
showMessage("Invalid input: " + inputString);
}
// Loop through each TIFF file in the input folder
for (i = 0; i < list.length; i++) {
if (endsWith(list[i], ".ndpi")) {
// Open the image using the Bio-Formats Importer plugin
run("Bio-Formats Importer", "open=[" + inputFolder + list[i] + "] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_"+(selectedSeries));
// Split the channels of the image
run("Split Channels");
// Get the titles of the split channel windows
titles = getList("image.titles");
// Select the window corresponding to the specified color channel
selectWindow(titles[colorChannel]);
// Construct the output filename by appending the bit depth to the input filename
outputFilename = replace(list[i], ".tif", "_" + bit_depth + "bit"+inputString+".tif");
outputPath = inputFolder + outputFilename;
// Save the selected color channel with the new filename
saveAs("Tiff", outputPath);
// Close all images to free up memory, even in batch mode
close("*");
}
}
setBatchMode(false);