def apply_filter(image: Cimpl.Image, command: str) -> Cimpl.Image: """ Author: Ibrahim Kasim, Himanshu Singh RETURNS a Cimpl.Image object and applies a filter to image based on command, and displays the result. image is a Cimpl.Image object command is a str representing the filter to be applied >>> apply_filter(Cimpl.load_image(Cimpl.choose_file()), 'X') """ filter_functions = { '2': two_tone, '3': three_tone, 'X': extreme_contrast, 'T': sepia, 'P': posterize, 'E': detect_edges, 'I': detect_edges_better, 'V': flip_vertical, 'H': flip_horizontal, } if command == 'E' or command == 'I': image = filter_functions[command](image, prompt_threshold()) else: image = filter_functions[command](image) Cimpl.show(image) return image
def load_image() -> Cimpl.Image: """ Author: Ibrahim Kasim, Himanshu Singh RETURNS a Cimpl.Image object. Prompts the user to select an image file to load, and displays the loaded image >>> load_image() """ print("Select an image file to load") image = Cimpl.load_image(Cimpl.choose_file()) Cimpl.show(image) return image
gameBoard, updatedStateList = create_empty_board(res, width, height) else: print("\nINFO: Settings unchanged.") clearLoop = False clearLoop = False else: input("\nERROR: No such selection exists. Press enter:") else: lscLoop = False elif selection == '3': Cimpl.show(gameBoard) elif selection == '4': print("INFO: This may take a while, please be patient. Running simulation....") wildcardFrames = "images/frame*.png" count, check = 0, 0 check_directory() remove_old_frames(wildcardFrames) originalUpdatedStateList = deepcopy(updatedStateList) # SIMULATION BEGINS --------------------------------------------------- simLoop = True while simLoop == True and count <= maxFrames: pixelStateList = deepcopy(updatedStateList) refresh_board(gameBoard, res, blockColor, updatedStateList)
if errors == 0: print( "SUCCESS: expected and outcome are of the same type and have identical pixels." ) else: print("{} ERRORS detected.".format(errors)) else: print("ERROR: Different types detected.\n" "Expected: Type {}\n" "Outcome: Type {}".format(type(expected), type(outcome))) print("---TESTING FUNCTION green_channel()---") expected = Cimpl.load_image(input("Select expected image filename: ")) print("DISPLAYING EXPECTED IMAGE: ") Cimpl.show(expected) testfile = Cimpl.load_image( input( "Input filename of image to be passed through FUNCTION green_channel: " )) print("DISPLAYING TEST IMAGE: ") Cimpl.show(testfile) print("PASSING TEST IMAGE INTO function green_channel: ") outcome = green_channel(testfile) print("DISPLAYING OUTCOME: ") Cimpl.show(outcome) print("COMPARING EXPECTED AND OUTCOME") #check_equal(expected, outcome)
RETURNS the sum of three numbers PASSED. If sum exceeds 255, then the sum is 255. >>> compute_sum(5,6,7) 18 """ if r + g + b <= 255: return r + g + b else: return 255 original = Cimpl.load_image(input("Input image filename: ")) print("DISPLAYING IMAGE: ") Cimpl.show(original) print("COMPUTING RED FILTERED IMAGE") red = red_channel(original) print("DISPLAYING RED FILTERED IMAGE: ") Cimpl.show(red) print("COMPUTING GREEN FILTERED IMAGE") green = green_channel(original) print("DISPLAYING GREEN FILTERED IMAGE: ") Cimpl.show(green) print("COMPUTING BLUE FILTERED IMAGE") blue = blue_channel(original) print("DISPLAYING BLUE FILTERED IMAGE: ") Cimpl.show(blue)
errors += 1 if errors == 0: print( "SUCCESS: expected and outcome are of the same type and have identical pixels." ) else: print("{} ERRORS detected.".format(errors)) else: print("ERROR: Different types detected.\n" "Expected: Type {}\n" "Outcome: Type {}".format(type(expected), type(outcome))) expected = Cimpl.load_image(input('Input EXPECTED image filename: ')) print("DISPLAYING EXPECTED IMAGE") Cimpl.show(expected) red = Cimpl.load_image( input("Input red image filename: ")) # choose_file does not work for me. print("DISPLAYING RED IMAGE") Cimpl.show(red) green = Cimpl.load_image(input("Input green image filename: ")) print("DISPLAYING GREEN IMAGE") Cimpl.show(green) blue = Cimpl.load_image(input("Select blue image filename: ")) print("DISPLAYING BLUE IMAGE") Cimpl.show(blue) print("COMBINING IMAGES") outcome = combine(red, green, blue)