MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / getThreshVal_Triangle

Function getThreshVal_Triangle

tests/cvcuda/system/TestOpThreshold.cpp:75–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75static double getThreshVal_Triangle(std::vector<uint8_t> &src)
76{
77 int N = 256;
78 std::vector<int> h(N, 0);
79 int i, j;
80
81 int size = src.size();
82 for (i = 0; i < size; i++) h[src[i]]++;
83
84 int left_bound = 0, right_bound = 0, max_ind = 0, max = 0;
85 int temp;
86 bool isflipped = false;
87
88 for (i = 0; i < N; i++)
89 {
90 if (h[i] > 0)
91 {
92 left_bound = i;
93 break;
94 }
95 }
96 if (left_bound > 0)
97 left_bound--;
98
99 for (i = N - 1; i > 0; i--)
100 {
101 if (h[i] > 0)
102 {
103 right_bound = i;
104 break;
105 }
106 }
107 if (right_bound < N - 1)
108 right_bound++;
109
110 for (i = 0; i < N; i++)
111 {
112 if (h[i] > max)
113 {
114 max = h[i];
115 max_ind = i;
116 }
117 }
118
119 if (max_ind - left_bound < right_bound - max_ind)
120 {
121 isflipped = true;
122 i = 0, j = N - 1;
123 while (i < j)
124 {
125 temp = h[i];
126 h[i] = h[j];
127 h[j] = temp;
128 i++;
129 j--;
130 }
131 left_bound = N - 1 - right_bound;
132 max_ind = N - 1 - max_ind;

Callers 1

ThresholdFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected