def task_4_15_2(): test_point = Vec({"x", "y", "u"}, {"x": 2, "y": 1.5, "u": 1}) against_point = identity() * test_point assert (against_point == test_point) image_mat_location, image_mat_colors = image_mat_util.file2mat( 'matrix/meme_avatar.png') ident_location = (identity() * image_mat_location) assert (ident_location == image_mat_location)
def task_4_15_4(): test_point = Vec({"x", "y", "u"}, {"x": 2, "y": 1.5, "u": 1}) against_point = scale(2, 2) * test_point expected = Vec({"x", "y", "u"}, { "x": test_point["x"] * 2, "y": test_point["y"] * 2, "u": 1 }) assert (against_point == expected) image_mat_location, image_mat_colors = image_mat_util.file2mat( 'matrix/meme_avatar.png') scaled_location = (scale(2, 2) * image_mat_location) image_mat_util.mat2display(scaled_location, image_mat_colors)
def task_4_15_3(): test_point = Vec({"x", "y", "u"}, {"x": 2, "y": 1.5, "u": 1}) against_point = translation(1, 2) * test_point expected = Vec({"x", "y", "u"}, { "x": test_point["x"] + 1, "y": test_point["y"] + 2, "u": 1 }) assert (against_point == expected) image_mat_location, image_mat_colors = image_mat_util.file2mat( 'matrix/meme_avatar.png') translated_location = (translation(20, 20) * image_mat_location) image_mat_util.mat2display(translated_location, image_mat_colors)
def task_4_15_5(): theta = math.pi / 4 test_point = Vec({"x", "y", "u"}, { "x": math.cos(theta), "y": math.sin(theta), "u": 1 }) rotated_point = rotation(theta) * test_point expected = Vec({"x", "y", "u"}, {"x": 0, "y": 1, "u": 1}) print(rotated_point, expected) assert (round(rotated_point["x"]) == expected["x"]) assert (round(rotated_point["y"]) == expected["y"]) image_mat_location, image_mat_colors = image_mat_util.file2mat( 'matrix/meme_avatar.png') rotated_location = (translation(100, 100) * rotation(math.pi / 4) * image_mat_location) image_mat_util.mat2display(rotated_location, image_mat_colors)
def task_4_15_1(): image_mat_location, image_mat_colors = image_mat_util.file2mat( 'matrix/meme_avatar.png') image_mat_util.mat2display(image_mat_location, image_mat_colors)
def test_grayscale(): image_mat_location, image_mat_colors = image_mat_util.file2mat( 'matrix/meme_avatar.png') gray_colors = grayscale() * image_mat_colors image_mat_util.mat2display(image_mat_location, gray_colors)