Question: 1 3 . Add Vertical Flipping Extend your implementation of the function flip to include the case vertical is True. Use an if - statement
Add Vertical Flipping
Extend your implementation of the function flip to include the case vertical is True. Use an ifstatement to make sure that you do not break horizontal flipping. Your function should flip horizontally when vertical is False and vertically when it is True.
To test out vertical flipping, you will need to execute pictool.py with the vertical option, adding verticalTrue to the end of the command line. For example, executing the command
python pictool.py flip imagesWalkerpng Walkerpng verticalTrue
should perform the following conversion:
Important: Because you can put anything you want in the vertical option say verticalblue we recommend that you enforce the precondition for vertical in the function with assert statements.
def flipimageverticalFalse:
Returns True after reflecting the image horizontally or vertically.
All plugin functions must return True or False. This function returns True
because it modifies the image. By default it reflects the image horizonally,
or vertically if vertical is True.
Parameter image: The image buffer
Precondition: image is a d table of RGB objects
Parameter vertical: Whether to reflect the image vertically
Precondition: vertical is a bool
# We recommend enforcing the precondition for vertical
assert isinstancevertical bool
rows lenimage
cols lenimage
if not vertical:
for row in image:
row.reverse
else:
image.reverse
# Change this to return True when the function is implemented
return True
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
