action
All checks were successful
Deploy WebSocket Server / deploy (push) Successful in 18s

This commit is contained in:
jeremygan2021
2026-03-05 20:56:21 +08:00
parent 6a64c54cae
commit a784c88c60
5 changed files with 108 additions and 10 deletions

27
debug_dither.py Normal file
View File

@@ -0,0 +1,27 @@
from PIL import Image, ImageDraw
# Create a test image with gray lines
img = Image.new('L', (100, 100), color=255)
d = ImageDraw.Draw(img)
d.line([10, 10, 90, 90], fill=128, width=2) # Gray line
d.line([10, 90, 90, 10], fill=0, width=2) # Black line
# Convert with default dithering
img1 = img.convert('1')
zeros1 = 0
for y in range(100):
for x in range(100):
if img1.getpixel((x, y)) == 0: zeros1 += 1
print(f"Default dither zeros: {zeros1}")
# Convert with NO dithering (Threshold)
# Note: convert('1', dither=Image.Dither.NONE) might still do dithering in some versions?
# The reliable way to threshold is point operation or custom threshold.
# But let's check convert('1', dither=0)
img2 = img.convert('1', dither=Image.Dither.NONE)
zeros2 = 0
for y in range(100):
for x in range(100):
if img2.getpixel((x, y)) == 0: zeros2 += 1
print(f"No dither zeros: {zeros2}")