MCPcopy Create free account
hub / github.com/davisking/dlib / partition_pixels_float_work

Function partition_pixels_float_work

dlib/image_transforms/thresholding.h:29–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 typename basic_pixel_type
28 >
29 void partition_pixels_float_work (
30 unsigned long begin,
31 unsigned long end,
32 U&& cumsum,
33 V&& sorted,
34 basic_pixel_type& pix_thresh,
35 unsigned long& int_thresh
36 )
37 {
38
39 auto histsum = [&](long begin, long end)
40 {
41 return end-begin;
42 };
43 auto histsumi = [&](long begin, long end)
44 {
45 return cumsum[end]-cumsum[begin];
46 };
47
48 // If we split the pixels into two groups, those < thresh (the left group) and
49 // those >= thresh (the right group), what would the sum of absolute deviations of
50 // each pixel from the mean of its group be? total_abs(thresh) computes that
51 // value.
52 unsigned long left_idx = 0;
53 unsigned long right_idx = 0;
54 auto total_abs = [&](unsigned long thresh)
55 {
56 auto left_avg = histsumi(begin,thresh);
57 auto tmp = histsum(begin,thresh);
58 if (tmp != 0)
59 left_avg /= tmp;
60 auto right_avg = histsumi(thresh,end);
61 tmp = histsum(thresh,end);
62 if (tmp != 0)
63 right_avg /= tmp;
64
65
66 while(left_idx+1 < sorted.size() && sorted[left_idx] <= left_avg)
67 ++left_idx;
68 while(right_idx+1 < sorted.size() && sorted[right_idx] <= right_avg)
69 ++right_idx;
70
71 double score = 0;
72 score += left_avg*histsum(begin,left_idx) - histsumi(begin,left_idx);
73 score -= left_avg*histsum(left_idx,thresh) - histsumi(left_idx,thresh);
74 score += right_avg*histsum(thresh,right_idx) - histsumi(thresh,right_idx);
75 score -= right_avg*histsum(right_idx,end) - histsumi(right_idx,end);
76 return score;
77 };
78
79
80
81 int_thresh = begin;
82 double min_sad = std::numeric_limits<double>::infinity();
83 for (unsigned long i = begin; i < end; ++i)
84 {
85 // You can't drop a threshold in-between pixels with identical values. So
86 // skip thresholds corresponding to this degenerate case.

Callers 1

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected