Question: Can you give me another example that does the same thing as this code? It's a compression algorithm that takes an image and compresses it
Can you give me another example that does the same thing as this code? It's a compression algorithm that takes an image and compresses it by taking every th row andor collumn and takes the average of the surrounding RGB elements.
from typing import List
def getgridx y row, col:
return
r c
for r c in
x y x yx y
x y x yx y
x y x yx y
if r row and c col
def getaveragelocations image:
r sumimageij for i j in locations lenlocations
g sumimageij for i j in locations lenlocations
b sumimageij for i j in locations lenlocations
return intr intg intb
def compressimage:
col lenimage
row lenimage
newimage
for x in range row, :
newrow
for y in range col, :
adjacentlocations getgridx y row, col
newcolor getaverageadjacentlocations, image
newrow.appendnewcolor
newimage.appendnewrow
return newimage
# Test case
testimage if r c else for c in range for r in range
printfOriginal image size: lentestimagexlentestimage
compressedimage compresstestimage
printfCompressed image size: lencompressedimagexlencompressedimage
printfThis is the test image:
testimage
printfThis is the compressed image:
compressedimage
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
