\Zxing\CommonHybridBinarizer

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.

Summary

Methods
Properties
Constants
__construct()
getBlackRow()
getBlackMatrix()
createBinarizer()
getLuminanceSource()
getWidth()
getHeight()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
initArrays()
estimateBlackPoint()
calculateBlackPoints()
calculateThresholdForBlock()
cap()
thresholdBlock()
$LUMINANCE_BITS
$LUMINANCE_SHIFT
$LUMINANCE_BUCKETS
$EMPTY
$luminances
$buckets
$source
$BLOCK_SIZE_POWER
$BLOCK_SIZE
$BLOCK_SIZE_MASK
$MINIMUM_DIMENSION
$MIN_DYNAMIC_RANGE
$matrix
N/A

Properties

$LUMINANCE_BITS

$LUMINANCE_BITS

$LUMINANCE_SHIFT

$LUMINANCE_SHIFT

$LUMINANCE_BUCKETS

$LUMINANCE_BUCKETS

$EMPTY

$EMPTY

$luminances

$luminances

$buckets

$buckets

$source

$source

$BLOCK_SIZE_POWER

$BLOCK_SIZE_POWER

$BLOCK_SIZE

$BLOCK_SIZE

$BLOCK_SIZE_MASK

$BLOCK_SIZE_MASK

$MINIMUM_DIMENSION

$MINIMUM_DIMENSION

$MIN_DYNAMIC_RANGE

$MIN_DYNAMIC_RANGE

$matrix

$matrix

Methods

__construct()

__construct(mixed  $source) : mixed

Parameters

mixed $source

Returns

mixed —

getBlackRow()

getBlackRow(mixed  $y, mixed  $row) : array

Converts one row of luminance data to 1 bit data. May actually do the conversion, or return cached data. Callers should assume this method is expensive and call it as seldom as possible.

This method is intended for decoding 1D barcodes and may choose to apply sharpening. For callers which only examine one row of pixels at a time, the same BitArray should be reused and passed in with each call for performance. However it is legal to keep more than one row at a time if needed.

Parameters

mixed $y
mixed $row

Throws

\Zxing\NotFoundException

if row can't be binarized

Returns

array —

The array of bits for this row (true means black).

getBlackMatrix()

getBlackMatrix() : \Zxing\Common\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.

Returns

\Zxing\Common\BitMatrix —

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

createBinarizer()

createBinarizer(mixed  $source) : \Zxing\Binarizer

Creates a new object with the same type as this Binarizer implementation, but with pristine state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache of 1 bit data. See Effective Java for why we can't use Java's clone() method.

Parameters

mixed $source

Returns

\Zxing\Binarizer —

A new concrete Binarizer implementation object.

getLuminanceSource()

getLuminanceSource() : \Zxing\LuminanceSource

Returns

\Zxing\LuminanceSource —

getWidth()

getWidth() : mixed

Returns

mixed —

getHeight()

getHeight() : mixed

Returns

mixed —

initArrays()

initArrays(mixed  $luminanceSize) : mixed

Parameters

mixed $luminanceSize

Returns

mixed —

estimateBlackPoint()

estimateBlackPoint(mixed  $buckets) : mixed

Parameters

mixed $buckets

Returns

mixed —

calculateBlackPoints()

calculateBlackPoints(mixed  $luminances, mixed  $subWidth, mixed  $subHeight, mixed  $width, mixed  $height) : mixed

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

See the following thread for a discussion of this algorithm: http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0

Parameters

mixed $luminances
mixed $subWidth
mixed $subHeight
mixed $width
mixed $height

Returns

mixed —

calculateThresholdForBlock()

calculateThresholdForBlock(mixed  $luminances, mixed  $subWidth, mixed  $subHeight, mixed  $width, mixed  $height, mixed  $blackPoints, mixed  $matrix) : mixed

For each block in the image, calculate the average black point using a 5x5 grid of the blocks around it. 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).

Parameters

mixed $luminances
mixed $subWidth
mixed $subHeight
mixed $width
mixed $height
mixed $blackPoints
mixed $matrix

Returns

mixed —

cap()

cap(mixed  $value, mixed  $min, mixed  $max) : mixed

Parameters

mixed $value
mixed $min
mixed $max

Returns

mixed —

thresholdBlock()

thresholdBlock(mixed  $luminances, mixed  $xoffset, mixed  $yoffset, mixed  $threshold, mixed  $stride, mixed  $matrix) : mixed

Applies a single threshold to a block of pixels.

Parameters

mixed $luminances
mixed $xoffset
mixed $yoffset
mixed $threshold
mixed $stride
mixed $matrix

Returns

mixed —