Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
- 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.
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started