| 359 | } |
| 360 | |
| 361 | double medianBetweenValidPoints(const cv::Mat& Input){ |
| 362 | std::vector<ushort> array; |
| 363 | if (Input.isContinuous()) { |
| 364 | array.assign(Input.datastart, Input.dataend); |
| 365 | } else { |
| 366 | for (int i = 0; i < Input.rows; ++i) { |
| 367 | array.insert(array.end(), Input.ptr<ushort>(i), |
| 368 | Input.ptr<ushort>(i)+Input.cols); |
| 369 | } |
| 370 | } |
| 371 | // jump over the 0s |
| 372 | std::vector<ushort> array_with_no_zero; |
| 373 | array_with_no_zero.reserve(array.size()); |
| 374 | for(uint i = 0; i < array.size(); ++i) |
| 375 | { |
| 376 | if (not fabs(array[i]) < 0.01f) |
| 377 | { |
| 378 | array_with_no_zero.push_back(array[i]); |
| 379 | } |
| 380 | } |
| 381 | if (array_with_no_zero.size() == 0) return 0.0f; |
| 382 | auto nth_position = array_with_no_zero.begin() + |
| 383 | array_with_no_zero.size() / 2; |
| 384 | std::nth_element(array_with_no_zero.begin(), |
| 385 | nth_position, |
| 386 | array_with_no_zero.end()); |
| 387 | return array_with_no_zero[array_with_no_zero.size() * 0.5]; |
| 388 | } |
| 389 | double medianBetweenValidPoints(std::vector<double>& array){ |
| 390 | std::vector<double> array2; |
| 391 | array2.reserve(array.size()); |
no test coverage detected