import numpy as np from PIL import Image import segmentation_utils as utils def test_resize_for_output_preserves_aspect_ratio(): image = Image.new("RGB", (4000, 2000), "white") resized = utils.resize_for_output(image, max_side=1000) assert resized.size == (1000, 500) def test_class_table_is_sorted_and_thresholded(): class_map = np.array([[0, 0], [0, 1]], dtype=np.uint8) rows = utils.build_class_table( class_map, {0: "road", 1: "sidewalk"}, min_share_percent=30.0, ) assert rows == [[0, "road", 3, 75.0, "#804080"]] def test_render_segmentation_matches_input_size(): image = Image.new("RGB", (3, 2), "black") class_map = np.array([[0, 0, 1], [0, 1, 1]], dtype=np.uint8) overlay, mask = utils.render_segmentation( image, class_map, {0: "road", 1: "sidewalk"}, opacity=0.5, ) assert overlay.size == image.size assert mask.size == image.size