-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle_counter_by_ROI.ijm
131 lines (115 loc) · 5.18 KB
/
particle_counter_by_ROI.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
macro "particleToRoi" {
//input = "/Users/moonbi/Documents/files/document/문서v3/MGI/Data/immunofluorescence/230529 RUSH SCOTIN Time point condition/puncta cell count/230613 puncta cell count T-15/Green"; //분석할 폴더
//output = "/Users/moonbi/Documents/files/document/문서v3/MGI/Data/immunofluorescence/230529 RUSH SCOTIN Time point condition/puncta cell count/230613 puncta cell count T-15/Green/"; //내보낼 위치
outputSummaryDataFileName = "analysis result"; //내보낼 파일의 이름
//outputResultDataFileName = "puncta properties";
suffix = ".czi" //분석할 파일의 확장자명
saveSuffix = "tif" //내보낼 파일의 확장자명
bncMin = 0; //밝기 조정 min
bncMax = 65; //밝기 조정 max
minThresholdROI = 30; //minimum threshold
maxThresholdROI = 255; //maximum threshold
minParticleROI = 10; //particle size threshold, min (>10 for DAPI, 63x)
maxParticleROI = "Infinity"; //particle size threshold, max
minCircularityROI = 0; //particle circularity, min
maxCircularityROI = 1; //particle circularity, max
minThresholdParticle = 90; //minimum threshold
maxThresholdParticle = 255; //maximum threshold
minParticleParticle = 0.01; //particle size threshold, min (>10 for DAPI)
maxParticleParticle = 1; //particle size threshold, max
minCircularityParticle = 0.1; //particle circularity, min
maxCircularityParticle = 1; //particle circularity, max
analysisPropertyROI = "size=" + minParticleROI + "-" + maxParticleROI + "circularity=" + minCircularityROI + "-" + maxCircularityROI + "bins=20 show=[Overlay Masks] noting clear record";
analysisPropertyParticle = "size=" + minParticleParticle + "-" + maxParticleParticle + "circularity=" + minCircularityParticle + "-" + maxCircularityParticle + "show=[Overlay Masks] display summarize";
print("initiating puncta counting macro...");
//print("Target directory: " + input + "\n" + "Output data will save (overwrite) at: " + output + outputSummaryDataFileName + ".csv, " + outputResultDataFileName + ".csv");
run("Clear Results");
run("Bio-Formats Macro Extensions");
//run("Excel Macro Extensions");
processFolder(input);
function processFolder(input) {
input = getDirectory("home");
Dialog.create("Particle Analysis");
Dialog.addDirectory("image folder path", input);
Dialog.show();
input = Dialog.getString();
//resultLocation = input + File.separator + "results";
resultLocation = input + "results";
File.makeDirectory(resultLocation);
area_results = newArray();
list = getFileList(input);
roiBoolean = getBoolean("Do you need ROI check before each analysis?");
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + list[i]))
processFolder("" + input + list[i]);
if(endsWith(list[i], suffix))
processFile(input, input, list[i]); //개별 이미지에 대한 프로세스
else
i++;
};
selectWindow("Summary");
saveAs("Results", input + "results/" + outputSummaryDataFileName + ".csv");
// selectWindow("Results");
// saveAs("Results", output + "/results/" + outputResultDataFileName + ".csv");
run("Clear Results");
print("Data saved at" + input + "results/" + outputSummaryDataFileName + ".csv");
print("Data saved at" + input + "results/" + outputResultDataFileName + ".csv");
print("Processing finished");
};
function processFile(input, output, file) {
MonthNames = newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); // Generate month names
DayNames = newArray("Sun", "Mon","Tue","Wed","Thu","Fri","Sat"); // Generate date names
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec); // Get date and time information
location = input + "/" + file;
fileItem = file;
//open(location);
Ext.openImagePlus(location);
setOption("ScaleConversions", true);
run("8-bit");
setMinAndMax(bncMin, bncMax);
run("Apply LUT");
setThreshold(minThresholdROI, maxThresholdROI, "raw");
run("Analyze Particles...", analysisPropertyROI); //particle property setting
roiManager("reset");
array1 = newArray("0");
for (t=0; t<nResults; t++) {
x = getResult("XStart", t);
y = getResult("YStart", t);
doWand(x,y);
roiManager("add");
};
if (roiBoolean == 1) {
waitForUser("Choose your ROI through ROIManager. Press OK if you are ready.");
processROI(location);
};
if (roiBoolean == 0) {
processROI(location);
};
};
function processROI(filelocation) {
close();
if (roiManager("count") > 0) {
Ext.openImagePlus(location);
setOption("ScaleConversions", true);
run("8-bit");
setMinAndMax(bncMin, bncMax);
run("Apply LUT");
n = roiManager("count");
for (m = 0; m < n; m++) {
roiManager("select", m);
// processing particle by each roi
setThreshold(minThresholdParticle, maxThresholdParticle, "raw");
run("Analyze Particles...", analysisPropertyParticle); //particle property setting
//setResult("Area", row, value);
//processing roi
// selectImage(fileItem);
// newName = fileItem + "_processed_" + m;
// saveAs(saveSuffix, input + "/results/" + newName);
};
close();
};
if (roiManager("count") == 0) {
print("no ROI has detected in " + filelocation);
};
};
};