MCPcopy Create free account
hub / github.com/SSARCandy/Coherent-Line-Drawing / visualizeETF

Function visualizeETF

src/postProcessing.cpp:9–57  ·  view source on GitHub ↗

visualize the ETF

Source from the content-addressed store, hash-verified

7
8// visualize the ETF
9cv::Mat visualizeETF(const cv::Mat &flowfield)
10{
11 cv::Mat noise = cv::Mat::zeros(cv::Size(flowfield.cols / 2, flowfield.rows / 2), CV_32F);
12 cv::Mat dst = cv::Mat::zeros(flowfield.size(), CV_32F);
13 cv::randu(noise, 0, 1.0f);
14 cv::resize(noise, noise, flowfield.size(), 0, 0, cv::INTER_NEAREST);
15
16 constexpr int s = 10;
17 constexpr float sigma = 2 * s * s;
18 const int nRows = noise.rows;
19 const int nCols = noise.cols;
20
21
22#pragma omp parallel for
23 for (int i = 0; i < nRows; ++i) {
24 for (int j = 0; j < nCols; ++j) {
25 float w_sum = 0.0;
26 float x = i;
27 float y = j;
28 for (int k = 0; k < s; ++k) {
29 cv::Vec3f v = cv::normalize(flowfield.at<cv::Vec3f>(int(x + nRows) % nRows, int(y + nCols) % nCols));
30 if (v[0] != 0) x = x + (abs(v[0]) / float(abs(v[0]) + abs(v[1]))) * (abs(v[0]) / v[0]);
31 if (v[1] != 0) y = y + (abs(v[1]) / float(abs(v[0]) + abs(v[1]))) * (abs(v[1]) / v[1]);
32 const float r2 = k * k;
33 const float w = (1 / (constant::PI * sigma)) * exp(-(r2) / sigma);
34 int xx = (int(x) + nRows) % nRows;
35 int yy = (int(y) + nCols) % nCols;
36 dst.at<float>(i, j) += w * noise.at<float>(xx, yy);
37 w_sum += w;
38 }
39
40 x = i;
41 y = j;
42 for (int k = 0; k < s; ++k) {
43 cv::Vec3f v = -cv::normalize(flowfield.at<cv::Vec3f>(int(x + nRows) % nRows, int(y + nCols) % nCols));
44 if (v[0] != 0) x = x + (abs(v[0]) / float(abs(v[0]) + abs(v[1]))) * (abs(v[0]) / v[0]);
45 if (v[1] != 0) y = y + (abs(v[1]) / float(abs(v[0]) + abs(v[1]))) * (abs(v[1]) / v[1]);
46
47 const float r2 = k * k;
48 const float w = (1 / (constant::PI * sigma)) * exp(-(r2) / sigma);
49 dst.at<float>(i, j) += w * noise.at<float>(int(x + nRows) % nRows, int(y + nCols) % nCols);
50 w_sum += w;
51 }
52 dst.at<float>(i, j) /= w_sum;
53 }
54 }
55
56 return dst;
57}
58
59// visualize ETF by drawing red arrowline
60cv::Mat visualizeFlowfield(const cv::Mat &flowfield)

Callers 2

renderMethod · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected