Coverage for collectra/displays/image_segmentation.py: 100.00%
12 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 09:56 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 09:56 +0000
1"""GUI mask descriptors; extraction continues to use transparent cropped images."""
3from PIL import Image
6def display_bounds(item):
7 """Keep the full source available for expanding a segmentation mask."""
8 from collectra.types.images import ImageSegmentation
10 if isinstance(item, ImageSegmentation):
11 return (0, 0, item.raw_width, item.raw_height)
12 return item.display_bounds()
15def segmentation(context, item):
16 alpha = item._mask_image().rotate(item.orientation.to_degree(), expand=True)
17 mask = Image.new("RGBA", alpha.size, "white")
18 mask.putalpha(alpha)
19 left, top, right, bottom = alpha.getbbox()
20 return {
21 "mask_source": context.publish_image(mask),
22 "width": alpha.width,
23 "height": alpha.height,
24 "orientation": item.orientation.to_string(),
25 "bounds": {"x": left, "y": top, "w": right - left, "h": bottom - top},
26 }