Computes the histogram for the given image rectangle, and the given single channel. Each channel is always one byte per pixel. Histogram is always a kHistogramSize(256) element array to count occurrences of each pixel value.
| 149 | // Histogram is always a kHistogramSize(256) element array to count |
| 150 | // occurrences of each pixel value. |
| 151 | void HistogramRect(Pix* src_pix, int channel, |
| 152 | int left, int top, int width, int height, |
| 153 | int* histogram) { |
| 154 | PERF_COUNT_START("HistogramRect") |
| 155 | int num_channels = pixGetDepth(src_pix) / 8; |
| 156 | channel = ClipToRange(channel, 0, num_channels - 1); |
| 157 | int bottom = top + height; |
| 158 | memset(histogram, 0, sizeof(*histogram) * kHistogramSize); |
| 159 | int src_wpl = pixGetWpl(src_pix); |
| 160 | l_uint32* srcdata = pixGetData(src_pix); |
| 161 | for (int y = top; y < bottom; ++y) { |
| 162 | const l_uint32* linedata = srcdata + y * src_wpl; |
| 163 | for (int x = 0; x < width; ++x) { |
| 164 | int pixel = GET_DATA_BYTE(const_cast<void*>( |
| 165 | reinterpret_cast<const void *>(linedata)), |
| 166 | (x + left) * num_channels + channel); |
| 167 | ++histogram[pixel]; |
| 168 | } |
| 169 | } |
| 170 | PERF_COUNT_END |
| 171 | } |
| 172 | |
| 173 | // Computes the Otsu threshold(s) for the given histogram. |
| 174 | // Also returns H = total count in histogram, and |
no test coverage detected