-
Notifications
You must be signed in to change notification settings - Fork 3
/
SMG-get-mesenchyme-DAPI-actin-images.ijm
89 lines (74 loc) · 2.96 KB
/
SMG-get-mesenchyme-DAPI-actin-images.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
inputFolder = getDirectory("Choose the folder containing images to process:");
// Create an output folder based on the inputFolder
parentFolder = getPath(inputFolder); inputFolderPrefix = getPathFilenamePrefix(inputFolder);
roiFolder = parentFolder + inputFolderPrefix + "-ROIs" + File.separator;
outputFolder = parentFolder + inputFolderPrefix + "-mesenchyme-images" + File.separator;
if ( !(File.exists(outputFolder)) ) { File.makeDirectory(outputFolder); }
run("Close All"); roiManager("reset");
setBackgroundColor(0, 0, 0); // set background to be black
setBatchMode(true);
fileList = getFileList(inputFolder);
for (i=0; i<fileList.length; i++) {
filename = inputFolder+fileList[i];
outputPrefix = getFilenamePrefix(fileList[i]);
if (endsWith(filename, "nd2")) {
roi_file = roiFolder + outputPrefix + ".roi";
merged_file = outputFolder + outputPrefix + "-mesenchyme.tif";
// merged_file = outputFolder + outputPrefix + "-mesenchyme.jpg";
open(filename); id0 = getImageID();
selectImage(id0); run("Duplicate...", "duplicate channels=1"); rename("DAPI");
selectWindow("DAPI");
saturation=0.35; run("Enhance Contrast", "saturated="+saturation); run("8-bit");
selectImage(id0); run("Duplicate...", "duplicate channels=3"); rename("actin");
selectWindow("actin");
saturation=0.35; run("Enhance Contrast", "saturated="+saturation); run("8-bit");
run("Merge Channels...", "c1=actin c2=DAPI c3=actin"); rename("merged");
selectWindow("merged");
roiManager("reset"); roiManager("Open", roi_file); roiManager("Select", 0);
run("Clear", "slice");
selectWindow("merged");
saveAs("Tiff", merged_file);
run("Close All");
}
}
run("Close All"); roiManager("reset");
function getPath(pathFileOrFolder) {
// this one takes full path of the file (input can also be a folder) and returns the parent folder path
temp = split(pathFileOrFolder, File.separator);
if ( File.separator == "/" ) {
// Mac and unix system
pathTemp = File.separator;
for (i=0; i<temp.length-1; i++) {pathTemp = pathTemp + temp[i] + File.separator;}
}
if ( File.separator == "\\" ) {
// Windows system
pathTemp = temp[0] + File.separator;
for (i=1; i<temp.length-1; i++) {pathTemp = pathTemp + temp[i] + File.separator;}
}
return pathTemp;
}
function getPathFilenamePrefix(pathFileOrFolder) {
// this one takes full path of the file
temp = split(pathFileOrFolder, File.separator);
temp = temp[temp.length-1];
temp = split(temp, ".");
return temp[0];
}
function getFilenamePrefix(filename) {
// this one takes just the file name without folder path
temp = split(filename, ".");
return temp[0];
}
function deleteFolder(folder) {
// Delete all the files inside the folder, then the folder itself
list = getFileList(folder);
// Delete the files and the folder
for (i=0; i<list.length; i++){
ok = File.delete(folder+list[i]);
}
ok = File.delete(folder);
if (File.exists(folder))
exit("Unable to delete the folder: " + folder);
else
print("Successfully deleted: " + folder);
}