for _, _, colour1, coords in segments:
if colour1 == colour:
- x, y = coords[-1]
- move_to(x, y)
- for x, y in coords:
+ # there may be a bug with repeated first coordinate in some versions?
+ assert segments[1] != segments[0]
+ # track first coordinate of outline (repeats to close and start new)
+ coord0 = None
+ for coord in coords:
+ x, y = coord
+ if coord0 is None:
+ coord0 = coord
+ move_to(x, y)
+ else:
+ if coord == coord0:
+ coord = None
+ line_to(x, y)
+ # if first coordinate was not repeated then close outline implicitly
+ if coord0 is not None:
+ x, y = coord0
line_to(x, y)
flush_edges()
PIL.Image.fromarray(image).save(f'{colour:d}.png')
for segment in nets[net]:
_, _, colour, coords = segments[segment]
if colour in colours:
- x, y = coords[-1]
- move_to(x, y)
- for x, y in coords:
+ # there may be a bug with repeated first coordinate in some versions?
+ assert segments[1] != segments[0]
+ # track first coordinate of outline (repeats to close and start new)
+ coord0 = None
+ for coord in coords:
+ x, y = coord
+ if coord0 is None:
+ coord0 = coord
+ move_to(x, y)
+ else:
+ if coord == coord0:
+ coord = None
+ line_to(x, y)
+ # if first coordinate was not repeated then close outline implicitly
+ if coord0 is not None:
+ x, y = coord0
line_to(x, y)
flush_edges()
images.append(image)
#print('dtype', image.dtype)
assert len(image.shape) == 3 and image.dtype == numpy.uint8
-image = image != 0
+image = image >= 0x80
if image.shape[2] == 2 or image.shape[2] == 4:
image = image[:, :, :-1] & image[:, :, -1:]
PIL.Image.fromarray(numpy.any(image, 2)).save(image_out)