Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def flip_vertical (image, col_index, row_index, region_height, region_width) We want to select a specific rectangular region of the image and flip the region top to bottom.
def flip_vertical (image, col_index, row_index, region_height, region_width) We want to select a specific rectangular region of the image and flip the region top to bottom. - input: - image : 2D list of tuples representing RGB values - col_index : an integer value that represents the starting column of the pixel at the upperleft corner of the selected rectangular region - row_index : an integer value that represents the starting row of the pixel at the upper-left corner of the selected rectangular region - region_width : the width of the rectangular region that we want to flip - region_height : the height of the rectangular region that we want to flip - output: - return False if parameters are not valid and no operations would be done to the image - return True if the image is flipped successfully def check_validity(image, col_index, row_index, region_height, region_width) You would implement another function to check if input parameters are valid. Input parameters are the same as above, and you need to return True if parameters are valid, and False otherwise. Rules for valid parameters are as follow: 1. col_index, row_index, region_height, region_width should all be greater than or equal to 0 2. The rectangular region specified by the parameter should be entirely inside the image 3. You can assume image is always a valid 2D list of tuples and we don't test on this edge case [ Example 1]: Image=[([240,240,0),(200,100,0),(240,240,0),(200,200,0)][(160,240,0),(140,200,0),(160,240,0),(120,200,0)],[(240,240,0),(200,200,0),(240,240,0),(200,200,0)].[(160,240,0)(120,200,0),(160,240,0),(120,200,0)]] If we call flip_vertical(1ng, ,,4,2 ), inage becomes [I(160, 240, 0), (120, 200, 0), (240, 240, 0) (200,200,0)]. [(240,240,0),(200,200,0),(160,240,0),(120,200,0)]. [(160,240,0),(140,200,0),(240,240,0),(200,200,0)]. [(240,240,0),(200,100,0),(160,240,0),(120,200,0)]] The bolded region is the region selected by this function call. [ Example 2] Original image (200300) If we do following steps: - 1nage = load_ing( "input.png') - flip_vertical(1mage, 19e, 68, 120, 120) - save_ing(inage, 'fltipped.png") We got the image below Starter code for your flip.py from FudanImgLib import * def check_validity(image, col_index, row_index, region_height, region_width): \# TODO def flip_vertical(image, col_index, row_index, region_height, region_width): \# Check validity of input parameters if not check_validity(image, col_index, row_index, region_height, region_width): return False \# TODO \# Return True if successfully flipped the image return True
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