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.
RAC = Coding binary transition positions using relative distances
Main concept: Instead of independently encoding every run length, RAC uses the spatial relationship between transitions in two consecutive rows.
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
000111001100
Current row
001110011000
Illustrative binary rows only; the actual positions of transitions must be identified from the image.
A transition occurs when the binary pixel value changes from 0 to 1 or from 1 to 0.
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.
ec = Distance between e and c
B. Distance cc′
cc′ is the distance from c to the first similar transition beyond e, denoted by c′, in the previous line.
cc′ = Distance between c and c′
C. Selection of RAC distance
The smaller of the two distances is selected.
d = min(ec, cc′)
There are two cases:
Case 1
ec ≤ cc′
Select d = ec. The current-line distance is encoded.
Case 2
cc′ < ec
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)
Remember: For d = 0, the code is 0. For d = 1, the code depends on whether the distance is ec, cc′ to the left, or cc′ to the right.
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.
h(d) = Range prefix + Binary offset
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
The h(d) range representation is used for d greater than 1 in the RAC cases above. The special cases d = 0 and d = 1 have their own codes.
7. Numerical Example 1 – From the Textbook Principle
Suppose the measured distances are:
ec = 8
cc′ = 4
Assume c′ is located to the left of c.
Step 1: Compare the distances
ec = 8, cc′ = 4
Step 2: Select the smaller distance
d = min(8,4) = 4
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:
1100
Step 4: Calculate h(4)
Distance 4 belongs to the range 1–4.
Offset = d − 1 = 4 − 1 = 3
Convert 3 into a 2-bit binary number:
3 = (11)₂
Range prefix for 1–4 is 0.
h(4) = 0 + 11 = 011
Step 5: Generate the final RAC code
RAC code = 1100 + 011
1100011
Final answer: RAC code = 1100011. This is the example reported in the accompanying lecture material for ec = 8, cc′ = 4, with c′ to the left.
8. Numerical Example 2 – Current-Line Distance Selected
Suppose:
ec = 3, cc′ = 7
Step 1: Select the smaller distance
d = min(3,7) = 3
Since ec is smaller, the current-line distance is selected.
Step 2: Find h(3)
Distance 3 belongs to range 1–4.
Offset = 3 − 1 = 2
2 in 2-bit binary = 10
h(3) = 0 + 10 = 010
Step 3: Apply the ec code prefix
RAC code = 111 + h(3)
111010
Final RAC code = 111010.
9. Numerical Example 3 – Right Direction
Suppose:
ec = 12, cc′ = 6
Assume c′ is to the right of c.
Step 1: Select the smaller distance
d = min(12,6) = 6
Step 2: Calculate h(6)
6 belongs to the range 5–20.
Offset = 6 − 5 = 1
1 in 4-bit binary = 0001
h(6) = 10 + 0001 = 100001
Step 3: Apply the right-direction prefix
RAC code = 1101 + 100001
1101100001
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
When d = 1, the code identifies the measured-distance case. The encoder/decoder must follow the transition-position convention in the RAC scheme.
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.
Enter the distances and click Calculate RAC Code.
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.
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.
Coordinate convention: All three positions are horizontal pixel positions measured from the same left-hand reference. Point e and point c belong to the current row. Point c′ belongs to the previous row.
Point e
Last transition in the current row.
Point c
Current transition in the current row.
Point c′
Similar transition in the previous row.
Waiting for point input...
Enter e, c and c′, then click Generate RAC Output.
Try this example: e = 10, c = 18, c′ = 14.
Expected distances: ec = 8 and cc′ = 4.
Since cc′ is smaller and c′ is to the left, the final RAC code is 1100011.