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

Function simple_partition_pixels

dlib/test/image.cpp:2099–2172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2097 typename image_type
2098 >
2099 typename pixel_traits<typename image_traits<image_type>::pixel_type>::basic_pixel_type
2100 simple_partition_pixels (
2101 const image_type& img
2102 )
2103 {
2104 matrix<unsigned long,1> hist;
2105 get_histogram(img,hist);
2106
2107 auto average1 = [&](unsigned long thresh)
2108 {
2109 double accum = 0;
2110 double cnt = 0;
2111 for (unsigned long i = 0; i < thresh; ++i)
2112 {
2113 accum += hist(i)*i;
2114 cnt += hist(i);
2115 }
2116
2117 if (cnt != 0)
2118 return accum/cnt;
2119 else
2120 return 0.0;
2121 };
2122
2123 auto average2 = [&](unsigned long thresh)
2124 {
2125 double accum = 0;
2126 double cnt = 0;
2127 for (long i = thresh; i < hist.size(); ++i)
2128 {
2129 accum += hist(i)*i;
2130 cnt += hist(i);
2131 }
2132
2133 if (cnt != 0)
2134 return accum/cnt;
2135 else
2136 return 0.0;
2137 };
2138
2139
2140 auto total_abs = [&](unsigned long thresh)
2141 {
2142 auto a = average1(thresh);
2143 auto b = average2(thresh);
2144
2145 double score = 0;
2146 for (long i = 0; i < hist.size(); ++i)
2147 {
2148 if (i < (long)thresh)
2149 score += std::abs(a-i)*hist(i);
2150 else
2151 score += std::abs(b-i)*hist(i);
2152 }
2153 return score;
2154 };
2155
2156

Callers 1

test_partition_pixelsFunction · 0.85

Calls 3

get_histogramFunction · 0.85
absFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected