Question: Please write a similar code to this example, prompt is on the bottom. from typing import List def get _ adjacent _ locations ( row:
Please write a similar code to this example, prompt is on the bottom.
from typing import List
def getadjacentlocationsrow: int, col: int, m: int, n: int ListListint:
Given a particular location, it returns all the adjacent locations WITHIN the boundaries of the grid
return r c for r c in row col row colrow col row col row colrow col row col row colrow col if r m and c n
def getaveragelocations: ListListint image Listint:
Take in a list of the locations within which we need to average out the r g b values.
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 r g b
def compressorig: ListListListint ListListListint:
m lenorig
n lenorig
newimage
for row in rangelenorig:
newrow
for col in rangelenorig:
red, green, blue origrowcol
if row and col :
# Get the locations adjacent to this
adjacentlocations getadjacentlocationsrow col, m n
# get the averaged out new color based on this locations
newcolor getaverageadjacentlocations, orig
# add this new color to row of new image
newrow.appendnewcolor
# row of new image complete so add it to new image
if row :
newimage.appendnewrow
return newimage
testimage None for c in range for r in range
for r in range:
for c in range:
if r c :
testimagerc
else:
testimagerc
printlentestimage lentestimage
newimage compresstestimage
printlennewimage lennewimage
printnewimage
Prompt:
Please consider the following compression algorithm. As an input, you receive a image. This image is formatted as
follows. The image is a dimensional array if you are using python it could be thought of as a d array where the
individual elements are tuples r g b Write a compression algorithm which takes in an image and only
includes the pixels with location r c such that r is divisible by and s is divisible by For those locations to be
included, the new value is the average of the surrounding values.
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
