Menu

## Binarizer
in package

Binarizer.php : 34

This class implements a local thresholding algorithm, which while slower than the GlobalHistogramBinarizer, is fairly efficient for what it does. It is designed for high frequency images of barcodes with black data on white backgrounds. For this application, it does a much better job than a global blackpoint with severe shadows and gradients.

However, it tends to produce artifacts on lower frequency images and is therefore not a good general purpose binarizer for uses outside ZXing.

This class extends GlobalHistogramBinarizer, using the older histogram approach for 1D readers, and the newer local approach for 2D readers. 1D decoding using a per-row histogram is already inherently local, and only fails for horizontal gradients. We can revisit that problem later, but for now it was not a win to use local blocks for 1D.

This Binarizer is the default for the unit tests and the recommended class for library users.

##### Tags

author

  dswitkin@google.com (Daniel Switkin)

### Table of Contents

BLOCK_SIZE = 8
BLOCK_SIZE_MASK = 7
BLOCK_SIZE_POWER = 3
LUMINANCE_BUCKETS = 32
LUMINANCE_SHIFT = 3
MIN_DYNAMIC_RANGE = 24
MINIMUM_DIMENSION = 40
$luminances : array<string|int, mixed>
$source : LuminanceSourceInterface
__construct() : mixed
getBlackMatrix() : BitMatrix
  Calculates the final BitMatrix once for all requests. This could be called once from the constructor instead, but there are some advantages to doing it lazily, such as making profiling easier, and not doing heavy lifting when callers don't expect it.
calculateBlackPoints() : array<string|int, mixed>
  Calculates a single black point for each block of pixels and saves it away.
calculateThresholdForBlock() : BitMatrix
  For each block in the image, calculate the average black point using a 5x5 grid of the surrounding blocks. Also handles the corner cases (fractional blocks are computed based on the last pixels in the row/column which are also used in the previous block).
cap() : int
estimateBlackPoint() : int
getHistogramBlackMatrix() : BitMatrix

### Constants

#### BLOCK_SIZE

Binarizer.php : 39
`private mixed BLOCK_SIZE = 8`

#### BLOCK_SIZE_MASK

Binarizer.php : 40
`private mixed BLOCK_SIZE_MASK = 7`

#### BLOCK_SIZE_POWER

Binarizer.php : 38
`private mixed BLOCK_SIZE_POWER = 3`

#### LUMINANCE_BUCKETS

Binarizer.php : 46
`private mixed LUMINANCE_BUCKETS = 32`

#### LUMINANCE_SHIFT

Binarizer.php : 45
`private mixed LUMINANCE_SHIFT = 3`

#### MIN_DYNAMIC_RANGE

Binarizer.php : 42
`private mixed MIN_DYNAMIC_RANGE = 24`

#### MINIMUM_DIMENSION

Binarizer.php : 41
`private mixed MINIMUM_DIMENSION = 40`

### Properties

#### $luminances

Binarizer.php : 49
`private array<string|int, mixed> $luminances`

#### $source

Binarizer.php : 48
`private LuminanceSourceInterface $source`

### Methods

#### __construct()

Binarizer.php : 54
`public __construct(LuminanceSourceInterface $source) : mixed`

##### Parameters

$source : LuminanceSourceInterface

##### Return values

mixed —

#### getBlackMatrix()

Binarizer.php : 138

Calculates the final BitMatrix once for all requests. This could be called once from the constructor instead, but there are some advantages to doing it lazily, such as making profiling easier, and not doing heavy lifting when callers don't expect it.

`public getBlackMatrix() : BitMatrix`

Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or may not apply sharpening. Therefore, a row from this matrix may not be identical to one fetched using getBlackRow(), so don't mix and match between them.

##### Return values

BitMatrix —

The 2D array of bits for the image (true means black).

#### calculateBlackPoints()

Binarizer.php : 206

Calculates a single black point for each block of pixels and saves it away.

`private calculateBlackPoints(int $subWidth, int $subHeight, int $width, int $height) : array<string|int, mixed>`

See the following thread for a discussion of this algorithm:

##### Parameters

$subWidth : int
$subHeight : int
$width : int
$height : int

##### Tags

see
  http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0

##### Return values

array<string|int, mixed> —

#### calculateThresholdForBlock()

Binarizer.php : 301

For each block in the image, calculate the average black point using a 5x5 grid of the surrounding blocks. Also handles the corner cases (fractional blocks are computed based on the last pixels in the row/column which are also used in the previous block).

`private calculateThresholdForBlock(int $subWidth, int $subHeight, int $width, int $height) : BitMatrix`

##### Parameters

$subWidth : int
$subHeight : int
$width : int
$height : int

##### Return values

BitMatrix —

#### cap()

Binarizer.php : 350
`private cap(int $value, int $min, int $max) : int`

##### Parameters

$value : int
$min : int
$max : int

##### Tags

noinspection

  PhpSameParameterValueInspection

##### Return values

int —

#### estimateBlackPoint()

Binarizer.php : 62
`private estimateBlackPoint(array<string|int, mixed> $buckets) : int`

##### Parameters

$buckets : array<string|int, mixed>

##### Tags

throws
  QRCodeDecoderException

##### Return values

int —

#### getHistogramBlackMatrix()

Binarizer.php : 165
`private getHistogramBlackMatrix(int $width, int $height) : BitMatrix`

##### Parameters

$width : int
$height : int

##### Return values

BitMatrix —

## Search results