Esempio n. 1
0
/**
* Applies a single threshold to a block of pixels.
*/
static void ThresholdBlock(const uint8_t* luminances, int xoffset, int yoffset, int threshold, int stride, BitMatrix& matrix)
{
	for (int y = 0, offset = yoffset * stride + xoffset; y < BLOCK_SIZE; y++, offset += stride) {
		for (int x = 0; x < BLOCK_SIZE; x++) {
			// Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
			if (luminances[offset + x] <= threshold) {
				matrix.set(xoffset + x, yoffset + y);
			}
		}
	}
}
// Applies a single threshold to an 8x8 block of pixels.
void LocalBlockBinarizer::threshold8x8Block(const unsigned char* luminances, int xoffset, int yoffset, int threshold,
    int stride, BitMatrix& matrix) {
  for (int y = 0; y < 8; y++) {
    int offset = (yoffset + y) * stride + xoffset;
    for (int x = 0; x < 8; x++) {
      int pixel = luminances[offset + x];
      if (pixel < threshold) {
        matrix.set(xoffset + x, yoffset + y);
      }
    }
  }
}