def test_threshold_both(array): """ both thresholds provided """ threshold = Threshold(upper_threshold=100, lower_threshold=40) cooked_array = threshold.cook(array) assert np.all(cooked_array[0, 0] == 255) assert np.all(cooked_array[0, 1] == 255) assert np.all(cooked_array[1, 0] == 255) assert np.all(cooked_array[1, 1] == 0)
def test_threshold_1(array): """ default """ threshold = Threshold() cooked_array = threshold.cook(array) assert np.all(cooked_array[0, 0] == 255) assert np.all(cooked_array[0, 1] == 255) assert np.all(cooked_array[1, 0] == 0) assert np.all(cooked_array[1, 1] == 255)
def test_threshold_lower(array): """ upper threshold provided lower threshold should be 0 """ threshold = Threshold(lower_threshold=100) cooked_array = threshold.cook(array) assert np.all(cooked_array[0, 0] == 0) assert np.all(cooked_array[0, 1] == 255) assert np.all(cooked_array[1, 0] == 0) assert np.all(cooked_array[1, 1] == 255)
def swap_example(self): threshold = Threshold(target=pierogi, upper_threshold=200) swap_pixels = np.random.randint(0, 1, (10, 10, 3)) swap = Ingredient(swap_pixels) threshold.season(swap) swap_recipe = Recipe(ingredients=[pierogi, swap]) swap_dish = Dish( recipe=swap_recipe ) swap_dish.serve()
def test_threshold_include_exclude(array): """ using different pixels for replace """ include_pixel = np.asarray([100, 100, 100]) exclude_pixel = np.asarray([0, 0, 0]) threshold = Threshold(include=include_pixel, exclude=exclude_pixel) cooked_array = threshold.cook(array) assert np.all(cooked_array[0, 0] == 100) assert np.all(cooked_array[0, 1] == 100) assert np.all(cooked_array[1, 0] == 0) assert np.all(cooked_array[1, 1] == 100)
def sort_example(self): # threshold is a seasoning, which means it can be # used to add a mask to another Ingredient threshold = Threshold(target=pierogi, upper_threshold=80) sort = Sort() # apply a threshold mask to the sort threshold.season(sort) sort_recipe = Recipe(ingredients=[pierogi, sort]) sort_dish = Dish( height=pierogi.height, width=pierogi.width, recipe=sort_recipe ) sort_dish.serve() sort_dish.show()
def threshold_example(self): threshold = Threshold(upper_threshold=100) # pass in lists to be mixed threshold_recipe = Recipe(ingredients=[pierogi, threshold]) # recipe = Recipe(recipe) threshold_dish = Dish( height=pierogi.height, width=pierogi.width, recipe=threshold_recipe ) threshold_dish.serve()