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

  • Comp Sci
  • Thread starter Villiers
  • Start date
  • Tags
    Length
In summary, this data consists of a sequence of 20 white pixels, followed by 5 black pixels, and then 7 white pixels.
  • #1
Villiers
7
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
  • #2
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
  • #4
Villiers said:
Would appreciate any advice
What part of the advice that has already been given do you need more help with?
 
  • #6
Can you write down how many bytes each line takes? Then add them up and see what you get.
 
  • #7
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
 
  • #8
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.
 
  • #9
thank you!
 

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

What is Run Length Encoding?

Run Length Encoding (RLE) is a lossless data compression technique used to reduce the size of data by replacing repeated sequences of characters with a count and a single character. It is commonly used in image and video compression.

How does RLE work?

RLE works by scanning a data stream and identifying repeated sequences of characters. These sequences are then replaced with a count and a single character. For example, in the sequence "8W5K7W", "8W" would be replaced with "8W" to represent 8 occurrences of the character "W".

What are the advantages of using RLE?

RLE is a simple and fast compression technique that can significantly reduce the size of data. It is also a lossless compression technique, meaning that the original data can be fully recovered from the compressed data without any loss of information.

Are there any limitations to RLE?

One limitation of RLE is that it is most effective on data with long sequences of repeated characters. If the data does not have many repeated sequences, RLE may not be as effective in reducing the size of the data. Additionally, RLE is not suitable for compressing data that is already highly compressed.

How is RLE used in real-world applications?

RLE is commonly used in image and video compression, as well as in file archiving and data transmission. It is also used in some text encoding schemes, such as ASCII85, to reduce the size of encoded data. RLE is also used in some computer graphics applications to store and transmit images with a limited color palette.

Similar threads

Replies
5
Views
2K
Replies
7
Views
2K
Replies
2
Views
1K
Replies
2
Views
360
Replies
7
Views
2K
Replies
6
Views
3K
Replies
12
Views
2K
Replies
4
Views
2K
Back
Top