| 65 | |
| 66 | namespace { |
| 67 | Array<float> gradientMagnitude(const Array<float>& gx, const Array<float>& gy, |
| 68 | const bool& isf) { |
| 69 | using detail::abs; |
| 70 | if (isf) { |
| 71 | Array<float> gx2 = abs<float, float>(gx); |
| 72 | Array<float> gy2 = abs<float, float>(gy); |
| 73 | return arithOp<float, af_add_t>(gx2, gy2, gx2.dims()); |
| 74 | } else { |
| 75 | Array<float> gx2 = arithOp<float, af_mul_t>(gx, gx, gx.dims()); |
| 76 | Array<float> gy2 = arithOp<float, af_mul_t>(gy, gy, gy.dims()); |
| 77 | Array<float> sg = arithOp<float, af_add_t>(gx2, gy2, gx2.dims()); |
| 78 | return unaryOp<float, af_sqrt_t>(sg); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | Array<float> otsuThreshold(const Array<float>& in, const unsigned NUM_BINS, |
| 83 | const float maxVal) { |