AI Glossary / MLOps and deployment / Advanced

Modified Huffman coding

Definition

Modified Huffman coding, or MH, is a one-dimensional lossless run-length coding method associated with bilevel facsimile images. It represents alternating runs of white and black picture elements using specified variable-length code tables. Longer runs are represented using make-up information followed by a terminating code. The name refers to a particular coding scheme, not any custom modification of the general Huffman algorithm.

What it means

A black-and-white document image often contains consecutive pixels of the same color. Instead of describing each pixel individually, a coder can describe how many white pixels occur, then how many black pixels, and so on. The run lengths must be encoded unambiguously. MH applies separate coding tables for the two colors and rules that keep the decoder synchronized with the intended sequence. It reconstructs the bilevel image supplied to it; it does not restore gray levels that may have been removed during scanning or thresholding.

How it works

The historical T.4 description reproduced in RFC 804 starts each data line with a white-run code, using a zero-length white run if the actual line begins black. Runs from zero through 63 use terminating codes. Longer runs use make-up code information plus a terminating remainder. The color changes after completion of the run, not merely after every codeword. Line framing supplies additional structure. Actual interoperability requires the specified tables and framing, including the conventions of the relevant format or protocol; generic run-length numbers alone are not an MH bitstream.

Three practical examples

  • A facsimile-coding lesson converts a simple bilevel scan line into alternating white and black run lengths.
  • An archival-image investigation checks whether a decoder expects MH rather than a related two-dimensional facsimile scheme.
  • A test suite includes lines that begin black and runs whose lengths are exact multiples of 64 to check boundary behavior.

Think of it this way

Imagine describing a striped row by saying how long each white and black stripe lasts. A shared rule says which color comes first, and a codebook expresses the stripe lengths compactly. If a stripe is long, its description can have a large portion followed by a remainder. The listener must finish that complete description before switching colors. The analogy explains the run structure without implying that everyday spoken numbers are the actual binary codewords or that all documents compress equally well.

Worked example

Take an original example of a white run containing 70 picture elements. Using the white table reproduced in RFC 804, the make-up code for 64 is 11011 and the terminating code for six is 1110. Concatenating them gives 110111110, nine bits representing that run. A white run of exactly 64 still requires its terminating zero code after the make-up code; stopping at the make-up code alone would leave the run unfinished. This example covers one run, not a complete scan line or fax transmission. It excludes other runs, line markers and any additional framing, so it must not be used as a whole-page compression-ratio estimate.

Illustrative case study

A fictional document-preservation team sees occasional decoding errors in a small MH reader. Ordinary short runs pass its tests, but a line containing a 64-pixel white run fails. The developer discovers that the reader switches color immediately after a make-up code instead of waiting for the terminating part. The team adds tests for exact multiples, black-starting lines and complete line reconstruction. The scenario illustrates a parsing rule that can be missed when a scheme is described only as “Huffman-compressed runs.” It does not claim that this defect exists in any named product.

Common misconceptions and mistakes

MH is not the same as every Huffman-based compressor, and it is not interchangeable with Modified READ or Modified Modified READ. Another mistake is ignoring the required zero-length white run when a line starts black. Make-up and terminating codewords are parts of a run representation, not necessarily separate color runs. The method is lossless relative to the bilevel raster, but converting a grayscale scan to that raster may already have discarded information. Finally, a historical draft reproduction is useful technical evidence without being a substitute for the exact current specification required by a particular implementation.

Business use

The term matters in document imaging, facsimile compatibility and preservation of older compressed records. Identify the exact coding and container conventions before converting files. Verify reconstructed pixel dimensions and values, and treat scanning or thresholding as separate stages with their own quality effects. Test edge cases rather than relying solely on a page that appears readable. Preserve source files during migration until the defined content checks pass. This supports reliable conversion while avoiding the assumption that every black-and-white image uses the same compression scheme.

People also ask

Is MH lossless?

Yes, with respect to the encoded bilevel image under correct decoding.

What happens if a scan line begins black?

The stated convention first encodes a zero-length white run.

Does a make-up code alone finish a long run?

No. A terminating code completes the run representation.

Check your understanding

How was the 70-pixel white run decomposed?

Answer: Into 64 plus six.

How many bits were used for its two cited codewords?

Answer: Nine.

Why is a terminating zero needed for an exact 64-pixel run?

Answer: It marks completion of the run even when no additional pixels remain after the make-up portion.

Related terms

  • Run-length encoding
  • Huffman coding
  • bilevel image
  • facsimile coding
  • terminating code
  • make-up code

Learn next

Encode several short white and black runs using the appropriate tables. Include a black-starting line and a run of exactly 64. Then decode the full sequence and verify both pixel count and color order before adding line framing.

More in MLOps and deployment

  • Model parallelism - Model parallelism distributes parts of a model's computation across multiple processing devices.
  • Model Registry - A model registry is a system for organizing named machine-learning models, their versions, and associated metadata so that teams can identify, retrieve, and...
  • Modified discrete cosine transform - The modified discrete cosine transform, or MDCT, is a lapped time-frequency transform used in audio coding.
  • Modulo-N code - Modulo-N coding represents a value by its remainder after division by N and uses correlated information at the decoder to help recover the intended value.
  • Motion compensation - Motion compensation uses motion information to form a prediction of image content from one or more reference images.
  • Move-to-front transform - The move-to-front transform, or MTF, is a reversible transformation that replaces each input symbol with its current position in an ordered list, then moves...

Sources

RFC 804, historical reproduction of CCITT Draft Recommendation T.4: https://www.rfc-editor.org/rfc/rfc804.html ITU-T, T.4 recommendation record: https://www.itu.int/rec/T-REC-T.4/en The 70-pixel calculation, stripe analogy and preservation case are original educational illustrations. The codewords are checked against the historical table; deployment-specific conformance requires the applicable specification and container rules.

Previous: Modified discrete cosine transform Next: Modified Kumaraswamy distribution

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer