-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffusion_Generator.java
More file actions
230 lines (196 loc) · 6.4 KB
/
Copy pathDiffusion_Generator.java
File metadata and controls
230 lines (196 loc) · 6.4 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import ij.WindowManager;
import java.util.Random;
import ij.ImagePlus;
import ij.text.*; // import ImageJ text package
public class Image_generator3 implements PlugIn {
static public int[][][] Imageray;
static public String[] Imagetext;
static public String Singleimageline;
public ImageStack stack;
static public double x;
static ImagePlus imp;
static public double y;
static public double y2;
static public double x2;
static public double directionx;
static public double directiony;
static public String v;
static public double angle;
static public double remain;
static public double xold;
static public double yold;
static public double y2old;
static public double x2old;
public int nF;
public int nB;
public int nW;
public int nH;
public int nZ;
public int switchT;
public int radius;
public double Dconst;
public double vconst;
String[] moChoice={"Brownian", "Constrained", "Active+Brownian", "Active", "Still","brown+con"};
public void run(String arg) {//1
IJ.run("Close All", "");
nB=5;
nH=100;
nW=100;
nB=100;
nZ=100;
switchT=50;
radius=10;
Dconst=4;
vconst=4;
GenericDialog gd = new GenericDialog("Stack Averaging");
gd.addNumericField("Number of foci=", nF, 0);//50
gd.addNumericField("Heigth", nH, 0);//50
gd.addNumericField("Width", nW, 0);//50
gd.addNumericField("Time frames", nW, 0);//50
gd.addNumericField("Border", nB,0);//50
gd.addNumericField("Switch (if applicable)", switchT,0);//50
gd.addNumericField("Radius of confinement", radius,0);//50
gd.addNumericField("Diffusion Constant", Dconst,1);//50
gd.addNumericField("speed of active diffusion", vconst,0);//50
gd.addChoice("Type of movement: ", moChoice, moChoice[0]);
gd.showDialog();
nF=(int)gd.getNextNumber();
nH=(int)gd.getNextNumber();
nW=(int)gd.getNextNumber();
nZ=(int)gd.getNextNumber();
nB=(int)gd.getNextNumber();
switchT=(int)gd.getNextNumber();
radius=(int)gd.getNextNumber();
Dconst=gd.getNextNumber();
vconst=gd.getNextNumber();
String moSet=gd.getNextChoice();
Random rG = new Random();
imp = IJ.createImage("Untitled", "8-bit Black", nH+nB+nB, nW+nB+nB, nZ);
IJ.showMessage("Random Image generator","Starting generation!");
Imageray= new int[nH+nB+nB][nW+nB+nB][nZ];
v="";
for (int g=0; g<nF;g++){ //2
x2old=100;
y2old=100;
xold=50;
yold=50;
x2=(int)(rG.nextDouble()*nW+nB);
y2=(int)(rG.nextDouble()*nH+nB);
xold=x2;
yold=y2;
if (moSet=="Brownian"){
for (int z=1;z<nZ+1;z++){ //z, 3
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold);
xold=x;
yold=y;
IJ.run(imp, "Specify...", "width=7 height=7 x="+x+" y="+y+" slice="+z+" oval");
// IJ.showMessage("My_Plugin","Hello world!\n"+x+"\n"+y);
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
}
} else if (moSet=="brown+con") {
for (int z=1;z<switchT;z++){ //z, 3
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold);
xold=x;
yold=y;
IJ.run(imp, "Specify...", "width=3 height=3 x="+x+" y="+y+" slice="+z+" oval");
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
x2=xold;
y2=yold;
}
for (int z=switchT;z<nZ+1;z++){ //z, 3
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold);
while (((x-x2)*(x-x2)+(y-y2)*(y-y2))>radius*radius){
//x<(x2-5)||x>(x2+5)||y<(y2-5)||y>(y2+5)){
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold);
}
xold=x;
yold=y;
IJ.run(imp, "Specify...", "width=3 height=3 x="+x+" y="+y+" slice="+z+" oval");
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
}//3
} else if (moSet=="Constrained") {
for (int z=1;z<nZ+1;z++){ //z, 3
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold);
while (((x-x2)*(x-x2)+(y-y2)*(y-y2))>radius*radius){
// while (x<(x2-10)||x>(x2+10)||y<(y2-10)||y>(y2+10)){
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold);
}
xold=x;
yold=y;
IJ.run(imp, "Specify...", "width=3 height=3 x="+x+" y="+y+" slice="+z+" oval");
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
}//3
} else if (moSet=="Active"){
directionx = (Math.random()*2-1)*Math.sqrt(vconst);
if (Math.random()>0.5){
directiony = Math.sqrt(vconst-directionx*directionx);
} else {
directiony = -Math.sqrt(vconst-directionx*directionx);
}
for (int z=1;z<nZ+1;z++){ //z, 3
x=(xold+directionx);
y=(yold+directiony);
xold=x;
yold=y;
IJ.run(imp, "Specify...", "width=3 height=3 x="+x+" y="+y+" slice="+z+" oval");
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
}
} else if (moSet=="Still") {
x=(x2+rG.nextGaussian());
y=(y2+rG.nextGaussian());
for (int z=1;z<nZ+1;z++){
IJ.run(imp, "Specify...", "width=3 height=3 x="+x+" y="+y+" slice="+z+" oval");
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
}
} else {
directionx = (Math.random()*2-1)*Math.sqrt(vconst);
if (Math.random()>0.5){
directiony = Math.sqrt(vconst-directionx*directionx);
} else {
directiony = 0-Math.sqrt(vconst-directionx*directionx);
}
// IJ.showMessage("Random Image generator","Starting generation!\n"+directionx+";"+directiony);
for (int z=1;z<nZ+1;z++){ //z, 3
angle=rG.nextDouble()*2*Math.PI-Math.PI;
x=(Math.cos(angle)*Math.sqrt(4*Dconst)+xold+directionx);
y=(Math.sin(angle)*Math.sqrt(4*Dconst)+yold+directiony);
xold=x;
yold=y;
IJ.run(imp, "Specify...", "width=3 height=3 x="+x+" y="+y+" slice="+z+" oval");
IJ.run(imp, "Fill", "slice");
IJ.showProgress((double)z/nZ);
}
}
}//1
IJ.run(imp, "Select None", "");
// IJ.run(imp, "Gaussian Blur...", "sigma=1 stack");
imp.show();
}
}