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

Discussion Overview

The discussion revolves around the calculation of bytes used in a run-length encoded sequence, specifically focusing on how to derive the total byte count from the encoded data. Participants are examining the encoding of pixel data, with references to specific sequences and their respective byte representations.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • Some participants note that each line of the run-length encoded sequence corresponds to a specific byte count based on the number of pixels and their colors.
  • One participant states that the first three lines, each representing 20 white pixels, use 2 bytes per line.
  • Another participant expresses confusion about how the total of 152 bytes was derived, despite understanding the individual line calculations.
  • One participant suggests writing down the byte count for each line to verify the total.
  • Several participants calculate the total bytes used, with one arriving at 156 bytes and another confirming the total as 152 bytes, prompting a check of arithmetic.

Areas of Agreement / Disagreement

There is disagreement regarding the total byte count, with one participant asserting 156 bytes and others confirming 152 bytes. The discussion remains unresolved as participants continue to verify their calculations.

Contextual Notes

Participants reference an original image file to validate their calculations, but the file is not provided in the thread. The calculations depend on the accuracy of the run-length encoding and the assumptions about 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   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
3K
  • · 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