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

  • Thread starter Thread starter Villiers
  • Start date Start date
  • Tags Tags
    Length
AI Thread Summary
The discussion focuses on calculating the total byte count for a run-length encoded sequence, with the final answer being 152 bytes. Participants clarify that each line's byte usage is derived from the number of pixels and their respective colors, with specific calculations provided for each line. The confusion arises from the discrepancy in calculations, with one user initially believing the total was 156 bytes. Ultimately, the correct breakdown confirms that the total is indeed 152 bytes, emphasizing the importance of accurate arithmetic in such encoding scenarios. The conversation highlights the collaborative effort to understand run-length encoding and its byte representation.
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 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
Views
3K
Replies
7
Views
3K
Replies
2
Views
1K
Replies
7
Views
3K
Replies
6
Views
3K
Replies
12
Views
2K
Replies
4
Views
2K
Back
Top