示例#1
0
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()
示例#2
0
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()
示例#3
0
def test_dish_2(array):
    pierogi = Pierogi(pixels=array)
    pierogi2 = Pierogi(pixels=np.rot90(array))

    dish = Dish(pierogis=[pierogi, pierogi2])

    assert np.all(dish.pierogis[1] == pierogi2)
示例#4
0
def cook_file(path, output, parsed_vars):
    """
    handle a single file

    can be a gif/video or a single image
    """
    # if the path is an image, it should be cooked solo
    # if it is a gif, it should be
    dish = Dish(file=path)

    # get default handler parameter attached to subparsers
    # function for handling a command's options
    add_dish_desc = parsed_vars.pop('add_dish_desc')

    # input file is a video
    if len(dish.pierogis) > 1:
        if parsed_vars.get('plate'):
            frames_path = "cooked"
        elif output is None:
            frames_path = "cooked"
        else:
            frames_path = output

        if not os.path.isdir(frames_path):
            os.makedirs(frames_path)

        digits = math.floor(math.log(len(dish.pierogis), 10)) + 1

        frames_count = len(dish.pierogis)
        i = 1
        for pierogi in dish.pierogis:
            # make frame file names like 0001.png
            frame_path = os.path.join(frames_path, str(i).zfill(digits) + '.png')

            print("cooking frame {}/{} to '{}'".format(i, frames_count, frame_path), end='\r')
            pierogi.save(frame_path)
            cooked_dish = cook_dish(frame_path, add_dish_desc, parsed_vars)
            cooked_dish.save(frame_path)

            i += 1

        if parsed_vars.get('plate'):
            plate(frames_path, output, parsed_vars)

    else:
        if output is None:
            output = "cooked.png"

        print("cooking '{}' to '{}'".format(path, output))

        cooked_dish = cook_dish(path, add_dish_desc, parsed_vars)

        cooked_dish.pierogis[0].file = path
        cooked_dish.save(output)

    return output
示例#5
0
def quantize_example(self):
    palette = [
        [100, 210, 69],
        [45, 23, 180],
        [62, 31, 70],
        [10, 210, 240],
        [45, 10, 244],
        [38, 31, 10],
        [255, 255, 255],
        [99, 94, 124]
    ]
    quantize = Quantize(palette=palette)

    # pass in lists to be mixed
    quantize_recipe = Recipe(ingredients=[pierogi, quantize])

    quantize_dish = Dish(
        recipe=quantize_recipe
    )

    quantize_dish.serve()
示例#6
0
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()
示例#7
0
def plate(path, output, parsed_vars):
    duration = parsed_vars.pop('duration')
    if duration is not None:
        duration /= 1000

    fps = parsed_vars.pop('fps')
    optimize = parsed_vars.pop('optimize')

    if os.path.isdir(path):
        frames = os.listdir(path)
        # sort so we can gif in order
        frames.sort()

        pierogis = []

        for frame in frames:
            try:
                pierogis.append(Pierogi(file=os.path.join(path, frame)))

            except UnidentifiedImageError:
                print("{} is not an image".format(frame))

            except ValueError:
                print("{} is not an image".format(frame))

            except IsADirectoryError:
                print("{} is a directory".format(path))

        dish = Dish(pierogis=pierogis)

        if output is None:
            output = "cooked.gif"

    else:
        dish = Dish(file=path)

        if output is None:
            output = "cooked.png"

    print()
    print("plating '{}' to '{}'".format(path, output))

    dish.save(output, optimize, duration=duration, fps=fps)
示例#8
0
def test_dish_1(array):
    pierogi = Pierogi(pixels=array)

    dish = Dish(pierogis=[pierogi])

    assert np.all(dish.pierogis[0] == pierogi)