-
Notifications
You must be signed in to change notification settings - Fork 2
/
Lutz_Macro.ijm
105 lines (95 loc) · 2.6 KB
/
Lutz_Macro.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
//Auto process the data for the Lutz test
run("Close All");
print("\\Clear");
roiManager("reset");
path1 = File.openDialog("Select Image #1");
path2 = File.openDialog("Select Image #2");
nlev = 800;
open(path1);
rename("im1");
dOff = getWidth(); //offset for processing via images (keeps numbers from being negative)
run("Duplicate...", "title=findBB1.dcm");
run("Find Maxima...", "noise="+nlev+" output=[Maxima Within Tolerance]");
run("Invert");
run("Analyze Particles...", "size=1-infinity circularity=0.0-1.00 show=Masks exclude add");
run("Close");
cnt = roiManager("count");
x1 = newArray(cnt);
y1 = newArray(cnt);
for (i = 0; i < cnt; i++)
{
//get centroid of each point
roiManager("select",i);
List.setMeasurements;
//get the centroid position
x1[i] = List.getValue("X");
y1[i] = List.getValue("Y");
}
roiManager("reset");
open(path2);
rename("im2");
run("Flip Horizontally");
run("Duplicate...", "title=findBB2.dcm");
run("Find Maxima...", "noise="+nlev+" output=[Maxima Within Tolerance]");
run("Invert");
run("Analyze Particles...", "size=1-infinity circularity=0.0-1.00 show=Masks exclude add");
run("Close");
cnt = roiManager("count");
x2 = newArray(cnt);
y2 = newArray(cnt);
for (i = 0; i < cnt; i++)
{
//get centroid of each point
roiManager("select",i);
List.setMeasurements;
//get the centroid position
x2[i] = List.getValue("X");
y2[i] = List.getValue("Y");
}
//find the distance from each point to every other point
cnt = x1.length*x2.length;
dx = newArray(cnt);
dy = newArray(cnt);
idx = 0;
for (i = 0; i < x1.length; i++)
{
for (j = 0; j < x2.length; j++)
{
dx[idx] = x1[i]-x2[j]+dOff;
dy[idx] = y1[i]-y2[j]+dOff;
idx++;
}
}
//find the most common offset distance in each direction
newImage("dx arr","16-bit",cnt,1,1);
for (i = 0; i < dx.length; i++)
{
//change to integer
setPixel(i,0,round(dx[i]));
}
List.setMeasurements;
dxm = List.getValue("Mode")-dOff;
run("Close");
print("shift x: " + dxm);
newImage("dy arr","16-bit",cnt,1,1);
for (i = 0; i < dy.length; i++)
{
//change to integer
setPixel(i,0,round(dy[i]));
}
List.setMeasurements;
dym = List.getValue("Mode")-dOff;
run("Close");
print("shift y: " + dym);
//apply offsets to original image
selectWindow("im2");
run("Translate...", "x="+dxm+" y="+dym+" interpolation=None");
//add results
imageCalculator("Add create 32-bit", "im1","im2");
rename("Lutz Result");
//setMinAndMax(27700, 32975);
//save results
dir1 = File.directory;
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
saveAs("Tiff", dir1 + "Lutz_Result_" + d2s(year,0) + "_" + d2s(month+1,0) + "_" + d2s(dayOfMonth,0) + ".tif");
setLocation(0,0);