RELATIVE ADDRESS CODING (RAC)
Two-Dimensional Run-Length Coding
Digital Image Processing | Binary Image Compression
1. Introduction
Relative Address Coding (RAC) is a two-dimensional run-length coding technique used for binary image compression. It is based on tracking the binary transitions that begin and end each black and white run.
In ordinary one-dimensional RLE, we encode consecutive identical pixel values by storing their values and run lengths. In RAC, the transition positions in the current row are encoded by comparing them with corresponding transitions in the previous row.
This use of information from the previous row makes RAC a two-dimensional coding approach.
2. Why is RAC Required?
Consider a binary image containing text, diagrams or large black-and-white regions. The positions of transitions in neighbouring rows may be similar.
If the current row has a transition close to a similar transition in the previous row, it may be more efficient to encode the relative distance rather than its absolute position.
Previous row
Contains already processed binary transitions.
Current row
Contains the transitions that are being encoded.
Relative distance
Measures the relationship between transitions in the two rows.
RAC is particularly useful when binary patterns in neighbouring rows have related transition positions.
3. Understanding the Symbols in Figure 8.17
| Symbol | Meaning |
|---|---|
| c | Current transition in the current row. |
| e | Last transition of the current row. |
| c′ | First similar transition beyond e, in the previous row. |
| ec | Distance from e to c. |
| cc′ | Distance from c to c′. |
| d | Distance selected for RAC coding. |
Visual understanding
Previous row
Current row
Illustrative binary rows only; the actual positions of transitions must be identified from the image.
4. Important Distance Calculations
According to Gonzalez and Woods, two distances are considered for the current transition c.
A. Distance ec
ec is the distance from the current transition c to the last transition e of the current line.
B. Distance cc′
cc′ is the distance from c to the first similar transition beyond e, denoted by c′, in the previous line.
C. Selection of RAC distance
The smaller of the two distances is selected.
There are two cases:
Case 1
Select d = ec. The current-line distance is encoded.
Case 2
Select d = cc′. The direction of c′ (left or right) is also encoded.
5. RAC Coding Table – Figure 8.17
The following table reproduces the coding structure shown in the textbook screenshot.
| Distance measured | Distance | Code |
|---|---|---|
| cc′ | 0 | 0 |
| ec or cc′ (left) | 1 | 100 |
| cc′ (right) | 1 | 101 |
| ec | d (d > 1) | 111 h(d) |
| cc′ (c′ to left) | d (d > 1) | 1100 h(d) |
| cc′ (c′ to right) | d (d > 1) | 1101 h(d) |
6. Understanding the Variable-Length Code h(d)
For distances greater than 1, RAC uses a variable-length code h(d). The distance is first placed into a range. A prefix identifies the range, and the remaining bits represent the offset within that range.
| Distance range | Prefix | Offset bits | h(d) |
|---|---|---|---|
| 1 – 4 | 0 | 2 | 0 XX |
| 5 – 20 | 10 | 4 | 10 XXXX |
| 21 – 84 | 110 | 6 | 110 XXXXXX |
| 85 – 340 | 1110 | 8 | 1110 XXXXXXXX |
| 341 – 1364 | 11110 | 10 | 11110 XXXXXXXXXX |
| 1365 – 5460 | 111110 | 12 | 111110 XXXXXXXXXXXX |
How to calculate h(d)
For each range, subtract the first value of that range to obtain the offset. Convert the offset into binary using the specified number of bits, then attach the range prefix.
| Range | Offset calculation | Offset width |
|---|---|---|
| 1–4 | d − 1 | 2 bits |
| 5–20 | d − 5 | 4 bits |
| 21–84 | d − 21 | 6 bits |
| 85–340 | d − 85 | 8 bits |
| 341–1364 | d − 341 | 10 bits |
| 1365–5460 | d − 1365 | 12 bits |
7. Numerical Example 1 – From the Textbook Principle
Suppose the measured distances are:
Assume c′ is located to the left of c.
Step 1: Compare the distances
Step 2: Select the smaller distance
Since cc′ is smaller than ec, the relative distance to c′ is selected.
Step 3: Determine the direction
c′ is to the left of c. Therefore, the appropriate code prefix is:
Step 4: Calculate h(4)
Distance 4 belongs to the range 1–4.
Convert 3 into a 2-bit binary number:
Range prefix for 1–4 is 0.
Step 5: Generate the final RAC code
8. Numerical Example 2 – Current-Line Distance Selected
Suppose:
Step 1: Select the smaller distance
Since ec is smaller, the current-line distance is selected.
Step 2: Find h(3)
Distance 3 belongs to range 1–4.
Step 3: Apply the ec code prefix
Final RAC code = 111010.
9. Numerical Example 3 – Right Direction
Suppose:
Assume c′ is to the right of c.
Step 1: Select the smaller distance
Step 2: Calculate h(6)
6 belongs to the range 5–20.
Step 3: Apply the right-direction prefix
Final RAC code = 1101100001.
10. Special Cases: d = 0 and d = 1
| Condition | Meaning | RAC code |
|---|---|---|
| cc′ = 0 | c is directly below the similar transition c′. | 0 |
| ec = 1 | Current-line distance is one. | 100 |
| cc′ = 1, c′ left | Similar previous-row transition is one position to the left. | 100 |
| cc′ = 1, c′ right | Similar previous-row transition is one position to the right. | 101 |
11. RAC Encoding Procedure
- Take the binary image and process it row by row.
- Use the previous row as the reference row.
- Identify the binary transitions in the current row.
- For the current transition c, determine the last transition e in the current row.
- Find the first similar transition c′ beyond e in the previous row.
- Calculate ec and cc′.
- Compare the two distances and select the smaller distance d.
- If d = 0 or d = 1, use the appropriate special code.
- If d is greater than 1, calculate h(d).
- Use the prefix for ec, cc′ left, or cc′ right.
- Repeat for the required transitions and rows.
Algorithm – Pseudocode
Algorithm RAC_Encode
For each current image row:
Select the previous row as reference.
Identify binary transitions in current row.
For each current transition c:
Find the last transition e
in the current row.
Find the first similar transition c'
beyond e in the previous row.
Calculate:
ec = distance(e, c)
cc' = distance(c, c')
If ec <= cc':
d = ec
If d = 0:
output special code 0
Else if d = 1:
output special code 100
Else:
output 111 + h(d)
Else:
d = cc'
If d = 1 and c' is left:
output 100
Else if d = 1 and c' is right:
output 101
Else if d > 1 and c' is left:
output 1100 + h(d)
Else if d > 1 and c' is right:
output 1101 + h(d)
Continue until all required transitions
have been encoded.
This is a teaching outline of the decision rules in Figure 8.17, not a complete standards-compliant RAC file encoder. Full image encoding also requires precise transition-search, row-boundary and initialization conventions.
12. Interactive RAC Code Calculator
Enter the two distances and choose the direction of c′. The calculator selects d, calculates h(d), and generates the RAC code according to the textbook table.
13. Advantages of RAC
- Uses information from two consecutive image rows.
- Exploits similarity between transition positions in neighbouring rows.
- Uses variable-length codes for representing distances.
- Can reduce the number of bits needed for suitable binary images.
- Useful for images containing structured black-and-white patterns.
- Encodes spatial relationships between transitions.
14. Disadvantages of RAC
- More complex than simple one-dimensional RLE.
- Requires transition detection and reference-row information.
- Encoding and decoding require careful tracking of positions.
- Compression efficiency depends on the relationship between neighbouring rows.
- Less suitable for images without useful binary transition patterns.
- Requires correct handling of image boundaries and initial reference rows.
15. RLE vs RAC
| Feature | Ordinary RLE | Relative Address Coding |
|---|---|---|
| Dimension | Usually one-dimensional scan | Two-dimensional row-based coding |
| Basic information | Pixel value and run length | Relative positions of binary transitions |
| Previous row | Not normally required | Used as reference |
| Distance coding | Run count | ec and cc′ distances |
| Code structure | Value-count pairs | Special prefixes and h(d) |
| Complexity | Simple | More complex |
16. Important Examination Questions
- What is Relative Address Coding?
- Explain the principle of two-dimensional run-length coding.
- Define ec and cc′ in RAC.
- Explain the selection rule d = min(ec, cc′).
- Write the RAC coding table given in Figure 8.17.
- What is the purpose of h(d)?
- Explain the variable-length distance ranges used in RAC.
- Calculate the RAC code when ec = 8, cc′ = 4 and c′ is to the left.
- Explain the special coding cases for d = 0 and d = 1.
- Differentiate between ordinary RLE and RAC.
17. Conclusion
Relative Address Coding is a two-dimensional extension of run-length coding. It tracks binary transitions in the current row and compares their positions with similar transitions in the previous row. By selecting the smaller of ec and cc′ and representing the selected distance with special prefixes and h(d), RAC can exploit similarities between neighbouring rows of a binary image.
18. References
- Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing, 2nd Edition, Chapter 8 – Image Compression, Two-Dimensional Run-Length Coding, Figure 8.17.
- Gonzalez and Woods – Chapter 8, Figure 8.17: Relative Address Coding
- Digital Image Processing – 1-D and 2-D Run-Length Coding lecture material
The coding table and distance definitions follow the supplied textbook screenshot. Numerical examples are educational calculations based on that table.
19. Interactive RAC Calculator – Point Input and Step-by-Step Output
Enter the horizontal positions of the three transition points. The calculator will automatically calculate the distances and generate the RAC code.
Point e
Last transition in the current row.
Point c
Current transition in the current row.
Point c′
Similar transition in the previous row.
Enter e, c and c′, then click Generate RAC Output.
Expected distances: ec = 8 and cc′ = 4.
Since cc′ is smaller and c′ is to the left, the final RAC code is 1100011.