Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HELP for Python!!!! Need code done with No run may be longer than 15 pixels; if any pixel runs longer, it should be broken into
HELP for Python!!!!
Need code done with No run may be longer than 15 pixels; if any pixel runs longer, it should be broken into a new run.
I have my code done, but don't know how to into new run if longer than 15 pixels.
There are my works:
def count_runs(flat_data): count = 0 i = 0 while i
def encode_rle(flat_data): runs = [] count = 0 for i in range(len(flat_data)): if (i == 0): count += 1 else: if (flat_data[i] == flat_data[i - 1]): count += 1 else: runs.append(count) runs.append(flat_data[i - 1]) count = 1 runs.append(count) runs.append(flat_data[-1]) return runs
def decode_rle(rle_data): rle = [] for i in range(0, len(rle_data), 2): count = rle_data[i] data = rle_data[i + 1] for m in range(count): rle.append(data) return rlecount += 1 else: runs.append(count) runs.append(flat_data[i - 1]) count = 1 runs.append(count) runs.append(flat_data[-1]) return runs2. count_runs(flat_data) Returns number of runs of data in an image data set; double this result for length of encoded (RLE) list. Ex: count_runs ([15,15,15,4,4,4,4,4,4]) yields integer 2. 3. encode_rle(flat_data) Returns encoding (in RLE) of the raw data passed in; used to generate RLE representation of a data. Ex: encode_rle ([15,15,15,4,4,4,4,4,4]) yields list [3,15,6,4]. 5. decode_rle(rle_data) Returns the decoded data set from RLE encoded data. This decompresses RLE data for use. (Inverse of \#3) Ex: decode_rle ([3,15,6,4]) yields list [15,15,15,4,4,4,4,4,4]. 1. count_runs - input: [4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,7] - output: 6 - input: [1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5] - output: 25 2. encode_rle - input: [4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,7] - output: [2,4,15,1,15,1,5,1,1,8,1,7] - input: [1,2,3,4,1,2,3,4] - output: [1,1,1,2,1,3,1,4,1,1,1,2,1,3,1,4] - input: [4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] - output: [2,4,15,1,15,1,5,1] - input: [4,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] - output: [1,4,1,515,1,15,1,5,1] 3. decode_rle - input: [2,4,15,1,15,1,5,1,1,8,1,7] - output: [4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,7]
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