Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HybridBinarizer

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.

author

dswitkin@google.com (Daniel Switkin)

Hierarchy

Index

Constructors

constructor

Properties

Private matrix

matrix: BitMatrix | null = null

Static Private BLOCK_SIZE

BLOCK_SIZE: number = 1 << HybridBinarizer.BLOCK_SIZE_POWER

Static Private BLOCK_SIZE_MASK

BLOCK_SIZE_MASK: number = HybridBinarizer.BLOCK_SIZE - 1

Static Private BLOCK_SIZE_POWER

BLOCK_SIZE_POWER: number = 3

Static Private MINIMUM_DIMENSION

MINIMUM_DIMENSION: number = HybridBinarizer.BLOCK_SIZE * 5

Static Private MIN_DYNAMIC_RANGE

MIN_DYNAMIC_RANGE: number = 24

Methods

createBinarizer

getBlackMatrix

getBlackRow

getHeight

  • getHeight(): number

getLuminanceSource

getWidth

  • getWidth(): number

Static Private calculateBlackPoints

  • calculateBlackPoints(luminances: Uint8ClampedArray, subWidth: number, subHeight: number, width: number, height: number): Int32Array[]

Static Private calculateThresholdForBlock

  • calculateThresholdForBlock(luminances: Uint8ClampedArray, subWidth: number, subHeight: number, width: number, height: number, blackPoints: Int32Array[], matrix: BitMatrix): void
  • 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

    • luminances: Uint8ClampedArray
    • subWidth: number
    • subHeight: number
    • width: number
    • height: number
    • blackPoints: Int32Array[]
    • matrix: BitMatrix

    Returns void

Static Private cap

  • cap(value: number, min: number, max: number): number

Static Private thresholdBlock

  • thresholdBlock(luminances: Uint8ClampedArray, xoffset: number, yoffset: number, threshold: number, stride: number, matrix: BitMatrix): void
  • Applies a single threshold to a block of pixels.

    Parameters

    • luminances: Uint8ClampedArray
    • xoffset: number
    • yoffset: number
    • threshold: number
    • stride: number
    • matrix: BitMatrix

    Returns void

Generated using TypeDoc