33 const auto tf =
static_cast<float>(t);
34 if (dispParams.simple)
35 return dispParams.a1 * tf;
36 return dispParams.a1 * tf + dispParams.a2 * tf * tf + std::cos(tf / 10.
f) / 10.f;
42 const auto tf =
static_cast<float>(t);
43 if (dispParams.simple)
44 return dispParams.b1 * tf;
45 return dispParams.b1 * tf + dispParams.b2 * tf * tf + (std::sin(tf * tf)) / 5.
f;
51 auto x_center =
static_cast<float>(src.
xdim) / 2.
f;
52 auto y_center =
static_cast<float>(src.
ydim) / 2.
f;
53 const auto xdim =
static_cast<float>(src.
xdim);
57 auto xc = std::ceil(x);
59 auto yc = std::ceil(y);
62 auto vff = src.
data[
static_cast<size_t>(xdim * yf + xf)];
63 auto vfc = src.
data[
static_cast<size_t>(xdim *
yc + xf)];
64 auto vcf = src.
data[
static_cast<size_t>(xdim * yf +
xc)];
65 auto vcc = src.
data[
static_cast<size_t>(xdim *
yc +
xc)];
66 return vff * (1.f - xw) * (1.
f - yw) + vcf * xw * (1.f - yw) + vfc * (1.
f - xw) * yw + vcc * xw * yw;
72 auto x_shift = options.skipShift ? 0 : shiftX(params.req_size.n() - n - 1);
73 auto y_shift = options.skipShift ? 0 : shiftY(params.req_size.n() - n - 1);
74 if (options.skipBarrel)
81 auto x_center =
static_cast<float>(params.req_size.x()) / 2.
f;
82 auto y_center =
static_cast<float>(params.req_size.y()) / 2.
f;
83 auto k1 = dispParams.k1_start +
static_cast<float>(
n) * (dispParams.k1_end - dispParams.k1_start) / (
static_cast<float>(params.req_size.n()) - 1);
84 auto k2 = dispParams.k2_start +
static_cast<float>(
n) * (dispParams.k2_end - dispParams.k2_start) / (
static_cast<float>(params.req_size.n()) - 1);
85 auto y_norm = (y - y_center + (options.shiftAfterBarrel ? 0 : y_shift)) / y_center;
86 auto x_norm = (x - x_center + (options.shiftAfterBarrel ? 0 : x_shift)) / x_center;
87 auto r_out =
sqrt(x_norm * x_norm + y_norm * y_norm);
88 auto r_out_2 = r_out * r_out;
89 auto r_out_4 = r_out_2 * r_out_2;
90 auto scale = (1 + k1 * r_out_2 + k2 * r_out_4);
91 x = (x_norm * scale * x_center) + x_center + (options.shiftAfterBarrel ? x_shift : 0);
92 y = (y_norm * scale * y_center) + y_center + (options.shiftAfterBarrel ? y_shift : 0);
101 case PhantomType::grid:
102 return addGrid(frame);
103 case PhantomType::particleCircle:
104 return addCircles(frame);
105 case PhantomType::particleCross:
106 return addCrosses(frame);
108 throw std::logic_error(
"Unsupported PhantomType");
112 template <
typename T>
115 std::cout <<
"Generating circles" << std::endl;
116 auto drawCircle = [&frame](
const auto r,
const auto x,
const auto y,
const int thickness,
const auto val)
118 const auto xdim = frame.
xdim;
119 for (
int j = -r - thickness;
j <= r + thickness; ++
j)
121 for (
int i = -r- thickness;
i <= r + thickness; ++
i)
124 if (d >= r - thickness / 2 && d <= r + thickness / 2)
126 frame.
data[(y +
j) * xdim +
i + x] += val;
132 std::mt19937 gen(content.seed);
133 const auto border = content.maxSize / 2 + content.thickness / 2 + 3;
136 std::uniform_int_distribution<> size(content.minSize, content.maxSize);
137 for (
auto i = 0;
i < content.count; ++
i)
139 auto r = size(gen) / 2;
142 drawCircle(r, x, y, content.thickness, content.signal_val);
146 template <
typename T>
149 std::cout <<
"Generating crosses" << std::endl;
150 auto drawCross = [&frame](
const auto s,
const auto x,
const auto y,
const auto val)
152 const auto xdim = frame.
xdim;
153 for (
int d = 0;
d < s; ++
d)
155 frame.
data[(y -
d) * xdim -
d + x] += val;
156 frame.
data[(y -
d) * xdim +
d + x] += val;
157 frame.
data[(y +
d) * xdim -
d + x] += val;
158 frame.
data[(y +
d) * xdim +
d + x] += val;
162 std::mt19937 gen(content.seed);
163 std::uniform_int_distribution<size_t> distX(content.maxSize / 2 + content.thickness / 2, frame.
xdim - 1 - content.maxSize / 2 - content.thickness / 2);
164 std::uniform_int_distribution<size_t> distY(content.maxSize / 2 + content.thickness / 2, frame.
ydim - 1 - content.maxSize / 2 - content.thickness / 2);
165 std::uniform_int_distribution<> size(content.minSize, content.maxSize);
166 const auto xdim = frame.
xdim;
167 const int thickness = content.thickness;
168 for (
auto i = 0;
i < content.count; ++
i)
170 auto s = size(gen) / 2;
174 for (
int t = 0; t < thickness / 2; ++t)
177 drawCross(s, x, y - t, content.signal_val);
178 drawCross(s, x - t, y, content.signal_val);
179 drawCross(s, x + t, y, content.signal_val);
180 drawCross(s, x, y + t, content.signal_val);
185 template <
typename T>
188 std::cout <<
"Generating grid" << std::endl;
189 const auto xdim = frame.
xdim;
190 const auto ydim = frame.
ydim;
192 for (
auto y = content.ystep - (content.thickness / 2); y < ydim - (content.thickness / 2) + 1; y += content.ystep)
194 for (
auto t = 0; t < content.thickness; ++t)
196 size_t y_offset = (y + t) * xdim;
197 for (
size_t x = 0; x < xdim; ++
x)
199 size_t index = y_offset +
x;
205 for (
auto x = content.xstep; x < xdim - (content.thickness / 2) + 1; x += content.xstep)
207 for (
int t = 0; t < content.thickness; ++t)
209 size_t x_offset = (x + t);
210 for (
size_t y = 0; y < ydim; ++
y)
212 size_t index = x_offset + y * xdim;
219 template <
typename T>
222 auto x_max_shift = 0.f;
223 auto y_max_shift = 0.f;
224 const auto x =
static_cast<float>(params.req_size.x());
225 const auto y =
static_cast<float>(params.req_size.y());
226 for (
size_t n = 0; n < params.req_size.n(); ++
n)
232 displace(x_0, y_0, n);
233 displace(x_n, y_n, n);
237 x_max_shift =
std::max(x_max_shift, x_shift);
238 y_max_shift =
std::max(y_max_shift, y_shift);
243 auto x_new = params.req_size.x() + 2 *
static_cast<size_t>(std::ceil(x_max_shift)) + 10;
244 auto y_new = params.req_size.y() + 2 *
static_cast<size_t>(std::ceil(y_max_shift)) + 10;
245 std::cout <<
"Due to displacement, working with frames of size [" << x_new <<
", " << y_new <<
"]\n";
246 return MultidimArray<T>(1, 1,
static_cast<int>(y_new), static_cast<int>(x_new));
249 template <
typename T>
252 std::cout <<
"Applying low-pass filter\n";
254 filter.w1 = ice.low_w1;
255 filter.raised_w = ice.low_raised_w;
261 template <
typename T>
264 std::cout <<
"Generating ice\n";
265 std::mt19937 gen(ice.seed);
266 std::normal_distribution<>
d(ice.avg, ice.stddev);
267 const auto nzyxdim = frame.
nzyxdim;
268 for (
size_t i = 0;
i < nzyxdim; ++
i)
274 template <
typename T>
275 template <
bool SKIP_DOSE>
278 MultidimArray<T> frame(1, 1, static_cast<int>(params.req_size.y()), static_cast<int>(params.req_size.x()));
279 params.fn_out.deleteFile();
280 std::mt19937 gen(content.seed);
282 auto genFrame = [&frame, &refFrame, &gen,
this](
auto n)
284 float x_center =
static_cast<float>(frame.
xdim) / 2.
f;
285 float y_center =
static_cast<float>(frame.
ydim) / 2.
f;
286 std::cout <<
"Processing frame " << n << std::endl;
287 for (
size_t y = 0; y < params.req_size.y(); ++
y)
289 for (
size_t x = 0; x < params.req_size.x(); ++
x)
291 auto x_tmp =
static_cast<float>(
x);
292 auto y_tmp =
static_cast<float>(
y);
293 displace(x_tmp, y_tmp, n);
295 auto val = bilinearInterpolation(refFrame, x_tmp - x_center, y_tmp - y_center);
298 auto dist = std::poisson_distribution<int>(val * content.dose);
306 for (
size_t n = 0; n < params.req_size.n(); ++
n)
314 template <
typename T>
317 auto refFrame = findWorkSize();
318 if (!options.skipIce)
320 generateIce(refFrame);
321 applyLowPass(refFrame);
322 refFrame.rangeAdjust(ice.min, ice.max);
324 addContent(refFrame);
325 if (options.skipDose)
327 generateMovie<true>(refFrame);
331 generateMovie<false>(refFrame);
333 if (!params.fn_gain.empty())
335 Image<T> gain(static_cast<int>(params.req_size.x()), static_cast<int>(params.req_size.y()));
336 gain().initConstant(1);
337 gain.
write(params.fn_gain);
339 if (!params.fn_dark.empty())
341 Image<T> dark(static_cast<int>(params.req_size.x()), static_cast<int>(params.req_size.y()));
342 dark().initConstant(0);
343 dark.
write(params.fn_dark);
__host__ __device__ float2 floor(const float2 v)
void sqrt(Image< double > &op)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void border(const MultidimArray< double > &img, MultidimArray< double > &border)
void abs(Image< double > &op)
void max(Image< double > &op1, const Image< double > &op2)