21BCE9902 Assignment-7 DIP
21BCE9902 Assignment-7 DIP
Processing
Assignment-9
Name: K.Jayanth Nayak
Reg.No: 21BCE9616
Slot: L33+L34
Lab: 9
Theory:
Encoding (Compression):
Scan the image pixel by pixel.
Whenever a run of the same pixel value is encountered, encode it as a
pair of values: the pixel value and the count of the consecutive
occurrences of that value.
The resulting compressed data is a sequence of these value-count pairs.
Decoding (Decompression):
Read the compressed data, which is a sequence of value-count pairs.
For each pair, repeat the pixel value the number of times specified by
the count.
The resulting decompressed data is the original image.
The main advantages of RLE are its simplicity, low computational cost,
and effectiveness in compressing images with large areas of the same
color or grayscale value. However, RLE may not be as effective for
images with a lot of variation in pixel values, as the compression ratio
may be lower in such cases.
Code:
Output:
Result:
Encoding (Compression):
The RLE encoding process identified the following runs in the input
string:
Run 1: 6 occurrences of the value 5
Run 2: 3 occurrences of the value 4
Run 3: 2 occurrences of the value 3
Run 4: 1 occurrence of the value 2
The encoded values are: [5, 4, 3, 2]
The encoded counts are: [6, 3, 2, 1]
The total length of the encoded data (values + counts) is 8 elements.
Compression Ratio:
Decoding (Decompression):
The decoding process takes the encoded values and counts and
reconstructs the original input string by repeating each encoded value
the specified number of times.
The decompressed string is identical to the original input string: [5 5 5
5 5 5 4 4 4 3 3 2].
Theoretical Analysis: