Question: Write a code to compress a binary image using Run length Encoding. encode image function: Write your code to compute run length code for the

Write a code to compress a binary image using Run length Encoding.

  • encode image function:
    • Write your code to compute run length code for the binary image. The input to your function will be a binary image(0's and 255's) and output a run length code.
      • decode image function: Write your code to get binary image from run length code returned by encode image funtion. The input of the function is run length code, height and width of the binary image The output of the function is binary image reconstructed from run length code.

Do not use any in-built functions from opencv and numpy. In general, you can use function from math library. Functions allowed np.array(), np.matrix(), np.zeros(), np.ones(), cv2.imread(), cv2.namedWindow(), cv2.waitKey().

import numpy as np class runlength: def encode_image(self,binary_image): """ Compress the image takes as input: image: binary_image returns run length code """ return np.zeros(100) #replace zeros with rle_code def decode_image(self, rle_code, height , width): """ Get original image from the rle_code takes as input: rle_code: the run length code to be decoded Height, width: height and width of the original image returns decoded binary image """ return np.zeros((100,100), np.uint8) #replace zeros with image reconstructed from rle_Code 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!