Code readingGuide

How to decode an intelligent mail barcode from an image

No native Intelligent Mail reader in your vision library? Decode the barcode from any grayscale image: 65 bars, four states, code words and a frame check.

LumaSpec Vision12 min read Share on LinkedIn

On this page 9 sections
  1. 01Check for 4-state support before you write any code
  2. 02What the symbol carries and why a camera can read it
  3. 03The decode pipeline, step by step
    1. Step 1: threshold to solid bars
    2. Step 2: find the band and its mid-line
    3. Step 3: count the runs — it must be 65
    4. Step 4: classify each bar's state
    5. Step 5: map characters, unpack fields, check the frame
  4. 04Worked example: resolving a 0.020 in IMb at a 300 mm field of view
  5. 05Hardware that can feed the pipeline
  6. 06Lighting and contrast for envelope stock
  7. 07Checks before you trust the decode
  8. 08When to buy the decode instead of writing it
  9. 09Questions

Most vision libraries stop at the retail symbologies: Code 128, UPC/EAN, QR, PDF417, DataMatrix. The Intelligent Mail barcode on US letters and flats is a 4-state postal symbol, and when your toolkit ships no decoder for it, the reflex is to buy one. Before you pay: the IMb — also called the One Code Solution or 4-State Customer Barcode — is a fixed 65-bar symbol with four bar states, printed code-word tables and an 11-digit frame check. Every step of reading it is ordinary image processing plus table lookups. This guide gives you the structure, the pixel math that decides whether a camera can resolve the bars, a step-by-step decode pipeline, and the checks that make a home-grown decoder trustworthy on a line.

Check for 4-state support before you write any code

Open the symbology menu of your decode software or fixed code readers and look for Intelligent Mail, IMb, 4-State Customer Barcode, 4-CB or USPS4CB. Industrial reader menus list the retail set first — Code 128, UPC/EAN, QR, PDF417, DataMatrix — and postal 4-state support varies by firmware, so the menu is the only answer that counts. If the entry exists, enable it and stop reading: a maintained firmware decoder beats anything you can write in a day.

If it does not exist, you have two paths: pull frames from a camera into your own code and decode them yourself, or change hardware. One trap first: IMpb, the package barcode, is a GS1-128 symbol that ordinary readers handle; IMb, the letter barcode, is the 4-state symbol this guide covers. They are not interchangeable.

What the symbol carries and why a camera can read it

The IMb always carries exactly 65 bars, whatever the payload. Each bar sits in one of four vertical states, and USPS encoder tools print the symbol as a 65-character string of the letters A, D, F and T. What defeats ordinary 1D decoders is height, not width: there are no wide and narrow elements, only four possible states per position, so the reader must resolve how far each bar extends, not how long it is.

The 65 bars hold a fixed 130-bit payload. The USPS 4-State Customer Barcode guide lays that payload out in printed tables: a bit-range table for the fields (a 2-digit barcode identifier, a 3-digit service type, a 6- or 10-digit mailer ID with the matching 9- or 5-digit serial number, a 5-, 9- or 11-digit routing ZIP when present, and an 11-digit frame check computed over the other fields), the integer rule that folds the 130 bits into thirteen 10-bit code words, and a 65-entry table that maps each character value to a bar position and state. Your decoder reads these tables as arrays; nothing is derived at runtime.

For camera work, three print dimensions matter: bars sit on a pitch of about 0.020 in (0.51 mm), a full bar stands 0.125–0.160 in (3.2–4.1 mm) tall, and the 65 bars therefore span roughly 1.3–1.5 in (33–38 mm). Those are envelope-print values; measure your own mail if it runs off-standard.

State Letter Bar extends Height vs band
Full F band top to band bottom about the whole band
Ascender A band top to mid-line about half
Descender D mid-line to band bottom about half
Tracker T centred on the mid-line a third or less

The band, its mid-line and these shares all come from your own image: the classifier below measures them rather than assuming them.

The decode pipeline, step by step

The whole decoder is a few hundred lines of code: threshold, project, count, classify, look up, check. It follows the same image-to-validated-data stages as any camera barcode decoding job, with the 4-state twist in step 4, and it runs in milliseconds per cropped frame on a PC.

Step 1: threshold to solid bars

Envelope paper is fibrous and the ink fades, so a single global threshold breaks. Use a local adaptive threshold with a window around twice the pitch, then a one-pixel morphological opening to clean speckle. The contrast tricks that rescue low-contrast codes in the decode-rate guide apply here directly. Target: a column cut through the symbol shows clean black bars with paper gaps between them.

Step 2: find the band and its mid-line

Sum the binary pixels row by row across the symbol area: the 65 bars form one dense horizontal band about 3.2–4.1 mm tall in scene units. Take the band's top edge t and bottom edge b, and set the mid-line m halfway between. If the envelope is tilted, bars smear across rows and both edges blur — deskew first with the standard image rotation correction pass.

Step 3: count the runs — it must be 65

Project the band onto the horizontal axis and cut it into connected ink runs, left to right. The count gate is absolute: 65 runs, or reject the frame. More runs means speckle or a broken bar; fewer means two bars merged, usually from blur, tilt or a dark threshold. This one check catches most bad images before they reach the decode tables.

Step 4: classify each bar's state

For each run, record the rows of its top and bottom edges, then compare both against t, m and b. Call an edge matched when it lands within a tolerance of the reference line, and start that tolerance at 20% of the band height, tuning it between 15% and 25% on about 20 sample envelopes. Full matches top and bottom; ascender matches top only; descender matches bottom only; tracker matches neither but sits centred on m. The output is the 65-letter ADFT string.

Step 5: map characters, unpack fields, check the frame

Run the ADFT string and the bar positions through the guide's 65-entry character table, pair the characters into the thirteen code words with the guide's integer rule, and rebuild the 130-bit payload. The bit-range table then hands you the barcode identifier, service type, mailer ID, serial number, routing ZIP and the 11-digit frame check. Recompute that check from the data fields with the guide's polynomial method — it is CRC-style error detection — and compare. A mismatch means one bar went into the wrong state: reject the frame and log the image. From here the fields flow to your PLC or database like any other read.

Worked example: resolving a 0.020 in IMb at a 300 mm field of view

This is the same pixel-budget calculation as the Code 128 module-size math; here it decides whether the four states are separable at all. Case: a letter-sorting belt with a 300 mm wide field of view, covered by a 5 MP fixed reader with a 2560 × 2048 global-shutter sensor — the class shown below. Inputs:

  • Bar pitch 0.020 in = 0.508 mm (USPS print envelope, nominal).
  • Minimum full-bar height 0.125 in = 3.18 mm (same envelope).
  • Sensor width 2560 px (5 MP reader, catalog spec).
  • Field of view 300 mm wide, covering the address area of a #10 envelope with mounting margin (application setting).
  • Belt speed 0.5 m/s = 500 mm/s (typical single-station letter feed; substitute your own).
  • Blur budget: keep smear under a quarter of a pitch.

Rule in words: pixels per pitch equals the pitch scaled by sensor pixels over field width, and the exposure ceiling is the blur budget divided by belt speed.

px_per_pitch = pitch_mm × sensor_px / FOV_mm exposure_max_s = (pitch_mm / 4) / belt_speed_mm_s

Arithmetic:

  • Scale: 2560 px ÷ 300 mm = 8.53 px/mm.
  • Pixels per pitch: 0.508 mm × 8.53 px/mm = 4.3 px.
  • Bar height: 3.18 mm × 8.53 px/mm = 27 px, about 13 px per half for the ascender/descender/tracker split.
  • Exposure ceiling: 0.508 mm ÷ 4 = 0.127 mm of allowed blur; 0.127 mm ÷ 500 mm/s = 0.00025 s ≈ 0.25 ms.
  • Vertical check: 2048 px ÷ 8.53 px/mm = 240 mm of field height, more than twice the ~105 mm of a #10 envelope.

Decision: this sensor resolves the symbol. Four pixels per pitch is the working floor for thresholded postal bars — two is the sampling minimum and paper noise eats the rest — and 4.3 px clears it with margin, so hold the field at or under 300 mm. Beyond about 430 mm the same sensor falls under 3 px per pitch, where adjacent bars merge and the 65-count fails. Keep exposure at or below 0.25 ms at this belt speed. Need a wider field instead? Add pixels (a 12 MP reader) rather than pushing thresholds. Size your own case with the camera resolution calculator.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

Hardware that can feed the pipeline

Whatever reads the pixels needs four things: frames you can pull into your own code, a global shutter for belt motion, four or more pixels per 0.508 mm pitch, and light that holds contrast across the letter. Camera-plus-your-code is the clean path; a code reader also works when its tools expose frames, which is a menu item to check in the manual before you build around it.

For a letter-sorting station the 5 MP class is the workable middle, and it is the sensor in the worked example: the LS-CRD-0028 prints 2560 × 2048 pixels, 30 fps and an 8 mm lens, with a global shutter for belt motion.

Fixed code readers2560 x 2048 fixed code reader, 30 fps, 60 codes/s, 8 mm lens (LS-CRD-0028)LS-CRD-0028
Interface
Fast Ethernet
Resolution
5 MP
Sensor format
1/1.7"
Shutter
Global
$920.00View part

When one frame must cover a whole flats tray or several envelopes at once, pixels beat speed: the MV-ID5120RM-08M-RBN reads 12 MP over GigE. Its rolling shutter makes it a station for paused mail, not for a running belt.

Fixed code readersHikrobot MV-ID5120RM-08M-RBN Industrial Code ReaderMV-ID5120RM-08M-RBN
Interface
GigE
Resolution
12 MP
Shutter
Rolling
Lens mount
M12
$1,969.00View part

A tight view spends its pixels where they count: the MV-ID3013PM-12M-WBN pairs a 1.3 MP sensor with a 12 mm lens for a narrow field that follows the barcode band alone.

Fixed code readersHikrobot MV-ID3013PM-12M-WBN 12mm focal length 1.3 MP Compact Industrial Code ReaderMV-ID3013PM-12M-WBN
Interface
Fast Ethernet
Resolution
Up to 3 MP
Shutter
Global
Lens mount
M12
$1,979.00View part

On dry stock with weak ink, light on the spot earns its keep: the MV-ID813M-05S-WBN-SR carries its own white light and a 4.9 mm lens over GigE.

Fixed code readersHikrobot MV-ID813M-05S-WBN-SR 1.3 MP resolution, 4.9 mm focal length, White light, SR, GigE, Static cableMV-ID813M-05S-WBN-SR
Interface
GigE
Resolution
Up to 3 MP
Lens mount
M10
$719.00View part

If the inspection must stay on the device, note that smart cameras run their vendor's inspection tools, so a custom 4-state decoder is a PC job unless your camera platform loads your own code. The camera finder filters by resolution, shutter and interface, and the configurator pairs the sensor with lens, light and mount.

Lighting and contrast for envelope stock

Dark bars on fibrous paper read with plain diffuse white front light; you are hunting contrast, not gloss. Three practical points. First, shield the station from ambient swings, because envelope decode fails quietly when the threshold drifts. Second, window film glares under a point light — cross-polarize, the same trick used for reading codes on shiny patches. Third, some producers print the IMb in a reddish meter ink instead of black: test all three color channels on ten sample envelopes and fix the channel with the strongest bar-to-paper contrast in the job. Mono sensors sidestep the channel question but keep the polarizer.

Checks before you trust the decode

Run this list on every station that goes live:

  • Count gate: exactly 65 runs per frame; anything else is rejected before the tables are touched.
  • Frame check gate: the recomputed 11-digit FCS must match the decoded value; log mismatches with the image.
  • Stability gate: decode the same frame at two binarization levels and require identical 65-letter strings.
  • Field sanity: mailer ID 6 or 10 digits with the serial the complementary length; ZIP 0, 5, 9 or 11 digits.
  • Read-rate gate: measure on 100+ envelopes across shifts and paper stocks, and archive failing frames so the failure modes stay visible — the image archiving habit exists for exactly this.

Judge every accepted read by its confidence signals rather than the raw count alone; the read confidence guide shows what to score.

When to buy the decode instead of writing it

Write the decoder when the job is bounded: one station, envelopes of one format, bars in known condition — the pipeline above is days of work, not months. Buy when any of these hold: a continuous high-speed sorter, where reading on a fast conveyor is its own discipline; mixed mail with crushed, smeared or overlapped symbols; or several symbologies on one line, where one supported decoder covers all of them. A home-grown decoder also needs an owner, because new paper stocks and print methods arrive without asking.

Decision per case: a single controlled station at or under 300 mm field with a 5 MP class sensor — write it, using the numbers above. High-speed sortation or an unknown mail mix — source 4-state support in the reader or library. IMpb only — any GS1-128 reader already qualifies.

For help matching a reader or camera to your belt speed and envelope mix, contact the applications team with a sample envelope and your line speed, or keep browsing the code-reading guides for the retail symbologies.

Questions

How many bars does an Intelligent Mail barcode always have?

Exactly 65, whatever the payload. The 130-bit symbol maps to thirteen code words and 65 bar positions, and USPS encoder tools print it as a 65-character string of A, D, F and T states. That fixed count is your first decode gate: a projection that finds 64 or 66 ink runs means the threshold, the tilt or the exposure is wrong, not the mail.

Can a normal barcode reader decode an IMb?

Only if its symbology list includes Intelligent Mail, IMb, 4-State Customer Barcode or USPS4CB — check the menu, because retail 1D and 2D lists do not cover it. The IMpb package barcode is different: it is a GS1-128 symbol, so a reader with GS1-128 enabled reads it without any postal 4-state support at all.

What do the A, D, F and T letters in an IMb encoder string mean?

Ascender, descender, full and tracker: the four possible states of each of the 65 bars. A full bar spans the whole symbol height, ascender and descender occupy the top and bottom halves, and a tracker sits at the mid-line. Your image classifier must output the same 65-letter string the encoder tools print.

What is the frame check sequence in an Intelligent Mail barcode?

An 11-digit check value computed from the barcode identifier, service type, mailer ID, serial number and routing ZIP with the polynomial method printed in the USPS 4-State Customer Barcode guide. After you unpack the fields, recompute it and compare: a mismatch means at least one bar was classified into the wrong state, so reject and log the image.

How many pixels do I need across one IMb bar?

Plan on at least four pixels across the 0.508 mm pitch, with three as the hard floor where decoding starts to fail. At a 300 mm field of view, a 2560 px wide sensor gives 4.3 pixels per pitch; push the field wider and you must add sensor pixels or accept merged bars. Keep motion blur under a quarter of a pitch as well.