Run Length Encoding: 20W, 8W5K7W, 9W3K8W, 7W7R6W, 6W4R1Y4R5W

  • Context: Comp Sci 
  • Thread starter Thread starter Villiers
  • Start date Start date
  • Tags Tags
    Length
Click For Summary
SUMMARY

The forum discussion centers on the calculation of bytes used in a run-length encoded (RLE) image sequence. Users analyze the byte count for various encoded lines, confirming that the total is 152 bytes based on the formula: 2 bytes for each line of 20 pixels and varying bytes for other sequences. The breakdown includes specific byte counts for each line, with the community providing insights into the arithmetic involved in reaching the total. The discussion emphasizes the importance of verifying calculations in RLE compression.

PREREQUISITES
  • Understanding of Run-Length Encoding (RLE) principles
  • Basic knowledge of byte representation in digital images
  • Familiarity with color coding in pixel data
  • Ability to perform arithmetic operations for byte counting
NEXT STEPS
  • Study the Run-Length Encoding algorithm in detail
  • Learn about image compression techniques and their applications
  • Explore byte representation and data storage in digital images
  • Investigate common errors in byte calculations and how to avoid them
USEFUL FOR

This discussion is beneficial for software developers, data compression engineers, and anyone involved in image processing or optimization of RLE algorithms.

Villiers
Messages
7
Reaction score
0
Homework Statement
The file size of this image is calculated by firstly determining the resolution or how many pixels there are: 20 x 20 = 400 pixels.

Each pixel is described by 8 bits so the file size is: 400 pixels x 8 bits = 3,200 bits or 400 bytes.

a) Run length encoding is applied to the file in order to reduce its file size. An encoded sequence of the same data is stored as 2 bytes: the value of the repetition and the colour code. For example the first line would be stored as 20W (the W would be the binary code for white but is summarised here as a character).

For each line show how the data would be encoded using the format: [LengthColour]. The first and fourth lines have been done for you.

(W=White, K=Black, R=Red, Y=Yellow, B=Blue, N=Brown)
Relevant Equations
b) Determine what the RLE compressed file size is bytes
Line Run length encoded sequence
1 20W
2 20W
3 20W
4 8W5K7W
5 8W5K7W
6 8W5K7W
7 8W5K7W
8 9W3K8W
9 7W7R6W
10 6W4R1Y4R5W
11 6W1R1W5R1W1R5W
12 6W1R1W2R1Y2R1W1R5W
13 6W1R1W5R1W1R5W
14 6W1R1W2R1Y2R1W1R5W
15 9W3B8W
16 9W3B8W
17 9W3B8W
18 9W3B8W
19 9W3B8W
20 8W5N7Wthe answer is 152 bytes but i don't understand how they arrived at this number.
any help would be appreciated.
 
Physics news on Phys.org
Welcome to PF.

Count the bytes used to represent the number of pixels and the colour.

We do not have your original 400 byte data file. Please attach it to a post.
Obviously, we could regenerate it from the RLL data file.
But that would not check the algorithm employed if there was an error in the output file you present.

The first three lines are each 20 White pixels, = 2 bytes per line.
The count of 20 fits in the first byte, the W in the second byte.

The fourth line is 8 White, followed by 5 blacK, then 7 White pixels, = 6 bytes.
Notice that the numbers in any line should add up to 20.
 
Last edited:
  • Like
Likes   Reactions: pbuk
Villiers said:
Would appreciate any advice
What part of the advice that has already been given do you need more help with?
 
Can you write down how many bytes each line takes? Then add them up and see what you get.
 
I get 156
Line Run length encoded sequence
1 20W 2 bytes
2 20W 2 bytes
3 20W 2 bytes
4 8W5K7W 6 bytes
5 8W5K7W 6 bytes
6 8W5K7W 6 bytes
7 8W5K7W 6 bytes
8 9W3K8W 6 bytes
9 7W7R6W 6 bytes
10 6W4R1Y4R5W 10 bytes
11 6W1R1W5R1W1R5W 14 bytes
12 6W1R1W2R1Y2R1W1R5W 18 bytes
13 6W1R1W5R1W1R5W 14 bytes
14 6W1R1W2R1Y2R1W1R5W 18 bytes
15 9W3B8W 6 bytes
16 9W3B8W 6 bytes
17 9W3B8W 6 bytes
18 9W3B8W 6 bytes
19 9W3B8W 6 bytes
20 8W5N7W 6 bytes
 
Villiers said:
I get 156
2+2+2 + 6+6+6+6+6+6 + 10+14+18+14+18 + 6+6+6+6+6+6 = 152
Check your arithmetic, I get 152.
 
thank you!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
7
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K