DICOM PS3.5 2017b - Data Structures and Encoding

G.3 The RLE Algorithm
Prev | G Encapsulated RLE Compressed Images (Normative) | Next

## G.3 The RLE Algorithm

The RLE algorithm described in this section is used to compress Byte Segments into RLE Segments. There is a one-to-one correspondence between Byte Segments and RLE Segments. Each RLE segment must be an even number of bytes or padded at its end with zero to make it even.

### G.3.1 The RLE Encoder

A stream of identical bytes (Replicate Run) is encoded as a two-byte code:

- < -count + 1 > <byte value>, where

  - count = the number of bytes in the run, and

  - 2 <= count <= 128

and a non-repetitive octet-stream (Literal Run) is encoded as:

- < count - 1 > <Literal octet-stream>, where

  - count = number of bytes in the octet-stream, and

  - 1 <= count <= 128.

The value of -128 may not be used to prefix a byte value.

### Note

It is common to encode a 2-byte repeat run as a Replicate Run except when preceded and followed by a Literal Run, in which case it's best to merge the three runs into a Literal Run.

Three-byte repeats shall be encoded as Replicate Runs. Each row of the image shall be encoded separately and not cross a row boundary.

Prev | Up | Next
G.2 Byte Segments | Home | G.3.2 The RLE Decoder

DICOM PS3.5 2017b - Data Structures and Encoding