-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLocalMaximaSMLM.ijm
73 lines (68 loc) · 2.64 KB
/
LocalMaximaSMLM.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
// ----------------------------------------------------------------------------------------------
// This macro finds the local maxima of an image that is lower than a certain threshold. Results
// are provided as a 2D image and a table.
// This code is a replication the post-processing at Deep-STORM_2D_ZeroCostDL4Mic notebook.
// Credits:
// - ZeroCostDL4Mic: Lucas von Chamier, et al., bioRxiv 2020.
// - DeepImageJ: Gómez-de-Mariscal, E., García-López-de-Haro, C., Ouyang, W. et al., Nat Methods 18, 1192–1195 (2021).
// ----------------------------------------------------------------------------------------------
// PARAMS BY DEFAULT (same variables in the notebook)
// If condition acts as >= rather than >
thresh = 0.10;
L2_weighting_factor = 170.21;
neighborhood_size = 3;
pixelSize = 12; // in nm and after upsampling
//-------------------------------------------------------
rename("normalizedConfidence");
// Remove negative values from the image
run("Min...", "value=0");
//correct the weighting factor
run("Divide...", "value=" + L2_weighting_factor);
// Local maxima finder
//-------------------------------------------------------
run("Duplicate...", "title=maxPooling");
run("Duplicate...", "title=filteredConfidence");
// MaxPoolig of radius 3 with stride of 1x1
// (kernel is a circle)
selectWindow("maxPooling");
run("Maximum...", "radius="+neighborhood_size);
// True maximum
imageCalculator("Subtract","maxPooling", "normalizedConfidence");
run("Manual Threshold...", "min=0 max=0");
setOption("BlackBackground", true);
run("Convert to Mask");
// Make binary
run("32-bit");
run("Divide...", "value=255");
// Recover confidence values
imageCalculator("Multiply", "filteredConfidence","maxPooling");
// run("Min...", "value=" + thresh); // remove everything below thresh
close("maxPooling");
// Create a csv file with the localizations and confidence values
// (brutal code with loops).
//-------------------------------------------------------
// The loop filters low confidence values as well.
selectWindow("filteredConfidence");
// One chance of finding a maxima localization just with the threshold
// run("Find Maxima...", "prominence=0.10 strict output=List");
row=0;
w=getWidth();
h=getHeight();
for(x=0;x<w;x++){
for(y=0;y<h;y++){
v=getPixel(x,y);
if (v<thresh){
setPixel(x, y, 0.00);
}
else {
setResult("frame",row,1);
setResult("x [nm]",row,x*pixelSize);
setResult("y [nm]",row,y*pixelSize);
setResult("confidence [a.u.]",row,v);
row++;
}
}
}
updateResults();
// To store the table just run:
// saveAs("Results", "/media/DeepSTORM/results_frame001.csv");