diff --git a/assets/_fine.py b/assets/_fine.py index e1b636f..ba378ba 100644 --- a/assets/_fine.py +++ b/assets/_fine.py @@ -17,7 +17,7 @@ KEY_D2 = 60 * 60 MIN_GAP = 12 MIN_BLOB = 60 -def key(im): +def key(im, defringe=2): a = np.array(im.convert('RGBA')) bg = a[0, 0, :3].astype(int) d = ((a[..., :3].astype(int) - bg) ** 2).sum(2) @@ -26,7 +26,10 @@ def key(im): # De-fringe. The generator does not always give you a pure key colour, and whatever it does give # bleeds a halo one pixel into the sprite — which survives as a magenta rim once the sprite is on # a green court. Anything on the EDGE that is still leaning towards the background goes too. - for _ in range(2): + # ...but each pass also eats a 1-pixel line, and a racket frame IS a 1-pixel line: two passes + # removed the rackets from a whole serve sheet and left men holding a grip. --defringe 1 (or 0) + # is for sheets whose art is that thin. + for _ in range(defringe): solid = a[..., 3] > 0 edge = solid & ~(np.roll(solid, 1, 0) & np.roll(solid, -1, 0) & np.roll(solid, 1, 1) & np.roll(solid, -1, 1)) near = ((a[..., :3].astype(int) - bg) ** 2).sum(2) < KEY_D2 * 9 @@ -67,8 +70,8 @@ def frames(a, cuts): if x0 < c < x1: out[i:i+1] = [(x0, c), (c, x1)]; break return out -def main(sheet, outs, target_h, cuts, anchor): - a = key(Image.open(sheet)) +def main(sheet, outs, target_h, cuts, anchor, defringe=2): + a = key(Image.open(sheet), defringe) b = block_size(a) crops = [] for x0, x1 in frames(a, cuts): @@ -104,5 +107,7 @@ if __name__ == '__main__': th, cuts, anchor = TARGET_H, [], -1 if '--h' in args: i = args.index('--h'); th = int(args[i+1]); del args[i:i+2] if '--cut' in args: i = args.index('--cut'); cuts = [int(v) for v in args[i+1].split(',')]; del args[i:i+2] + de = 2 + if '--defringe' in args: i = args.index('--defringe'); de = int(args[i+1]); del args[i:i+2] if '--anchor' in args: i = args.index('--anchor'); anchor = int(args[i+1]); del args[i:i+2] - main(args[0], args[1:], th, cuts, anchor) + main(args[0], args[1:], th, cuts, anchor, de) diff --git a/assets/p_pull1.png b/assets/p_pull1.png index ee8f34f..6f3c672 100644 Binary files a/assets/p_pull1.png and b/assets/p_pull1.png differ diff --git a/assets/p_pull2.png b/assets/p_pull2.png index 2986d32..bdee77a 100644 Binary files a/assets/p_pull2.png and b/assets/p_pull2.png differ diff --git a/assets/p_pull3.png b/assets/p_pull3.png index 1dc5df4..8469502 100644 Binary files a/assets/p_pull3.png and b/assets/p_pull3.png differ diff --git a/assets/p_pull4.png b/assets/p_pull4.png index 1f3259e..bd3e0ac 100644 Binary files a/assets/p_pull4.png and b/assets/p_pull4.png differ diff --git a/index.html b/index.html index 232a7b9..8b61e18 100644 --- a/index.html +++ b/index.html @@ -97,6 +97,6 @@
- +