| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ | |||
| 21 | 21 | #include <ireduce.hpp> | |
| 22 | 22 | #include <logic.hpp> | |
| 23 | 23 | #include <reduce.hpp> | |
| 24 | + #include <scan.hpp> | ||
| 24 | 25 | #include <sobel.hpp> | |
| 25 | 26 | #include <tile.hpp> | |
| 26 | 27 | #include <transpose.hpp> | |
@@ -76,19 +77,20 @@ Array<float> otsuThreshold(const Array<float>& supEdges, | |||
| 76 | 77 | Array<uint> hist = histogram<float>(supEdges, NUM_BINS, 0, maxVal, false); | |
| 77 | 78 | ||
| 78 | 79 | const dim4& hDims = hist.dims(); | |
| 80 | + auto fhist = cast<float, uint>(hist); | ||
| 79 | 81 | ||
| 80 | - // reduce along histogram dimension i.e. 0th dimension | ||
| 81 | - auto totals = reduce<af_add_t, uint, float>(hist, 0); | ||
| 82 | - | ||
| 83 | - // tile histogram total along 0th dimension | ||
| 84 | - auto ttotals = tile(totals, dim4(hDims[0])); | ||
| 82 | + auto totals = createValueArray<float>(1.f, supEdges.elements()); | ||
| 85 | 83 | ||
| 86 | 84 | // pixel frequency probabilities | |
| 87 | - auto probability = | ||
| 88 | - arithOp<float, af_div_t>(cast<float, uint>(hist), ttotals, hDims); | ||
| 85 | + auto probability = arithOp<float, af_div_t>(fhist, totals, hDims); | ||
| 86 | + auto fscan = detail::scan<af_add_t, float, float>(probability, 0); | ||
| 87 | + | ||
| 88 | + vector<float> hfscan(fscan.elements()); | ||
| 89 | + detail::copyData<float>(hfscan.data(), fscan); | ||
| 89 | 90 | ||
| 90 | 91 | vector<af_seq> seqBegin(4, af_span); | |
| 91 | 92 | vector<af_seq> seqRest(4, af_span); | |
| 93 | + vector<af_seq> sliceIndex(4, af_span); | ||
| 92 | 94 | ||
| 93 | 95 | seqBegin[0] = af_make_seq(0, static_cast<double>(hDims[0] - 1), 1); | |
| 94 | 96 | seqRest[0] = af_make_seq(0, static_cast<double>(hDims[0] - 1), 1); | |
@@ -104,8 +106,8 @@ Array<float> otsuThreshold(const Array<float>& supEdges, | |||
| 104 | 106 | auto frontPartition = createSubArray(probability, seqBegin, false); | |
| 105 | 107 | auto endPartition = createSubArray(probability, seqRest, false); | |
| 106 | 108 | ||
| 107 | - auto qL = reduce<af_add_t, float, float>(frontPartition, 0); | ||
| 108 | - auto qH = reduce<af_add_t, float, float>(endPartition, 0); | ||
| 109 | + auto qL = createValueArray<float>(1, hfscan[b]); | ||
| 110 | + auto qH = createValueArray<float>(1, 1.f - hfscan[b]); | ||
| 109 | 111 | ||
| 110 | 112 | const dim4 fdims(b + 1, hDims[1], hDims[2], hDims[3]); | |
| 111 | 113 | const dim4 edims(NUM_BINS - 1 - b, hDims[1], hDims[2], hDims[3]); | |
@@ -129,11 +131,8 @@ Array<float> otsuThreshold(const Array<float>& supEdges, | |||
| 129 | 131 | auto op2 = arithOp<float, af_mul_t>(qL, qH, tdims); | |
| 130 | 132 | auto sigma = arithOp<float, af_mul_t>(sqrd, op2, tdims); | |
| 131 | 133 | ||
| 132 | - vector<af_seq> sliceIndex(4, af_span); | ||
| 133 | 134 | sliceIndex[0] = {double(b), double(b), 1}; | |
| 134 | - | ||
| 135 | - auto binRes = createSubArray<float>(sigmas, sliceIndex, false); | ||
| 136 | - | ||
| 135 | + auto binRes = createSubArray<float>(sigmas, sliceIndex, false); | ||
| 137 | 136 | copyArray(binRes, sigma); | |
| 138 | 137 | } | |
| 139 | 138 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments