MCPcopy
hub / github.com/kohya-ss/sd-scripts / _synthetic_image

Function _synthetic_image

tools/dev/visualize_masks.py:75–91  ·  view source on GitHub ↗

Simple synthetic image used as fallback when no real images are available.

(width: int, height: int, seed: int)

Source from the content-addressed store, hash-verified

73
74
75def _synthetic_image(width: int, height: int, seed: int) -> Image.Image:
76 """Simple synthetic image used as fallback when no real images are available."""
77 rng = random.Random(seed)
78 bg = tuple(rng.randint(40, 200) for _ in range(3))
79 img = Image.new("RGB", (width, height), bg)
80 draw = ImageDraw.Draw(img)
81 for _ in range(rng.randint(5, 12)):
82 x1 = rng.randint(0, width - 60)
83 y1 = rng.randint(0, height - 60)
84 x2 = min(x1 + rng.randint(50, 200), width)
85 y2 = min(y1 + rng.randint(50, 200), height)
86 color = tuple(rng.randint(0, 255) for _ in range(3))
87 if rng.random() < 0.5:
88 draw.rectangle([x1, y1, x2, y2], fill=color)
89 else:
90 draw.ellipse([x1, y1, x2, y2], fill=color)
91 return img
92
93
94class ImageSource:

Callers 1

getMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected