FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve performance of canny by removing a few reductions · arrayfire/arrayfire@804535b · GitHub

Repository navigation

Commit 804535b

Browse files
committed
Improve performance of canny by removing a few reductions
1 parent fec777e commit 804535b

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

‎src/api/c/canny.cpp‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <ireduce.hpp>
2222
#include <logic.hpp>
2323
#include <reduce.hpp>
24+
#include <scan.hpp>
2425
#include <sobel.hpp>
2526
#include <tile.hpp>
2627
#include <transpose.hpp>
@@ -76,19 +77,20 @@ Array<float> otsuThreshold(const Array<float>& supEdges,
7677
Array<uint> hist = histogram<float>(supEdges, NUM_BINS, 0, maxVal, false);
7778

7879
const dim4& hDims = hist.dims();
80+
auto fhist = cast<float, uint>(hist);
7981

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());
8583

8684
// 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);
8990

9091
vector<af_seq> seqBegin(4, af_span);
9192
vector<af_seq> seqRest(4, af_span);
93+
vector<af_seq> sliceIndex(4, af_span);
9294

9395
seqBegin[0] = af_make_seq(0, static_cast<double>(hDims[0] - 1), 1);
9496
seqRest[0] = af_make_seq(0, static_cast<double>(hDims[0] - 1), 1);
@@ -104,8 +106,8 @@ Array<float> otsuThreshold(const Array<float>& supEdges,
104106
auto frontPartition = createSubArray(probability, seqBegin, false);
105107
auto endPartition = createSubArray(probability, seqRest, false);
106108

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]);
109111

110112
const dim4 fdims(b + 1, hDims[1], hDims[2], hDims[3]);
111113
const dim4 edims(NUM_BINS - 1 - b, hDims[1], hDims[2], hDims[3]);
@@ -129,11 +131,8 @@ Array<float> otsuThreshold(const Array<float>& supEdges,
129131
auto op2 = arithOp<float, af_mul_t>(qL, qH, tdims);
130132
auto sigma = arithOp<float, af_mul_t>(sqrd, op2, tdims);
131133

132-
vector<af_seq> sliceIndex(4, af_span);
133134
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);
137136
copyArray(binRes, sigma);
138137
}
139138

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL