-
Notifications
You must be signed in to change notification settings - Fork 1
/
100x100_red_border.ijm
112 lines (90 loc) · 2.26 KB
/
100x100_red_border.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
/*
* Instructions: Open your image. Run the macro
* Macro by Johnny Gan [email protected]
*
*/
//Resets and establish minimal settings
roiManager("reset");
run("Options...", "iterations=1 count=1 black do=Nothing");
//Process Image first
run("8-bit");
setForegroundColor(255, 255, 255);
run("Invert");
//Threshold image
run("Auto Threshold", "method=Otsu white");
//Analyze image
run("Analyze Particles...", "add");
total = roiManager("count");
addx = 0;
addy = 0;
//Get coordinates of the ROIs
for (i = 0; i < total; i++) {
roiManager("deselect");
roiManager("select", i);
Roi.getBounds(x, y, width, height);
addx = addx+x;
addy = addy+y;
}
//Get dimensions of image and creates a pseudo squared image
getDimensions(width, height, channels, slices, frames);
if (width>height) {
box=height*1.5;
}
else {
box=width*1.5;
}
newImage("square", "8-bit black", box, box, 1);
//Rearranges ROIs in new image
newx=box*0.03;
newy=box*0.03;
maxy = 0;
for (i = 0; i < total; i++) {
roiManager("deselect");
roiManager("select", i);
Roi.getBounds(boundx, boundy, boundwidth, boundheight);
newx_check = boundwidth + newx;
if (newx_check <= box ) {
Roi.move(newx, newy);
newx = boundwidth + newx + (box*0.03);
if(boundheight>maxy){
maxy=boundheight+maxy;
}
}
else {
newx = 0;
newy=newy+maxy;
if (newy>box) {
newy = maxy;
}
Roi.move(newx, newy);
newx = boundwidth + newx + (box*0.03);
}
roiManager("Show All");
}
//Wait for user to rearrange the images
waitForUser("Press on the number of each ROI and move them to desired location. Keep them far apart form each other and from the borders. Once done press OK");
for (i = 0; i < total; i++) {
roiManager("select", i);
setForegroundColor(255,255,255);
run("Fill", "slice");
}
run("Select None");
roiManager("reset");
selectImage("square");
//Rescale image to 100x100
run("Scale...", "x=- y=- width=100 height=100 interpolation=None create");
run("Analyze Particles...", "add");
run("Select None");
run("Dilate");
run("RGB Color");
run("Select None");
changeValues(0xffffff, 0xffffff, 0xff0000);
run("Select None");
total = roiManager("count");
setForegroundColor(255,255,255);
for (i = 0; i < total; i++) {
roiManager("select", i);
run("Fill", "slice");
}
run("Select None");
roiManager("reset");