MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / hist_equal

Function hist_equal

src/api/c/histeq.cpp:43–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42template<typename T, typename hType>
43static af_array hist_equal(const af_array& in, const af_array& hist) {
44 const Array<T> input = getArray<T>(in);
45
46 af_array vInput = 0;
47 AF_CHECK(af_flat(&vInput, in));
48
49 Array<float> fHist = cast<float>(getArray<hType>(hist));
50
51 const dim4& hDims = fHist.dims();
52 dim_t grayLevels = fHist.elements();
53
54 Array<float> cdf = scan<af_add_t, float, float>(fHist, 0);
55
56 float minCdf = getScalar<float>(reduce_all<af_min_t, float, float>(cdf));
57 float maxCdf = getScalar<float>(reduce_all<af_max_t, float, float>(cdf));
58 float factor = static_cast<float>(grayLevels - 1) / (maxCdf - minCdf);
59
60 // constant array of min value from cdf
61 Array<float> minCnst = createValueArray<float>(hDims, minCdf);
62 // constant array of factor variable
63 Array<float> facCnst = createValueArray<float>(hDims, factor);
64 // cdf(i) - min for all elements
65 Array<float> diff = arithOp<float, af_sub_t>(cdf, minCnst, hDims);
66 // multiply factor with difference
67 Array<float> normCdf = arithOp<float, af_mul_t>(diff, facCnst, hDims);
68 // index input array with normalized cdf array
69 Array<float> idxArr = lookup<float, T>(normCdf, getArray<T>(vInput), 0);
70
71 Array<T> result = cast<T>(idxArr);
72 result = modDims(result, input.dims());
73
74 AF_CHECK(af_release_array(vInput));
75
76 return getHandle<T>(result);
77}
78
79af_err af_hist_equal(af_array* out, const af_array in, const af_array hist) {
80 try {

Callers

nothing calls this directly

Calls 5

af_flatFunction · 0.70
modDimsFunction · 0.70
af_release_arrayFunction · 0.70
dimsMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected