carakter
This commit is contained in:
52
tools/remove_checkerboard.py
Normal file
52
tools/remove_checkerboard.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from PIL import Image
|
||||
|
||||
def remove_checkerboard(input_path, output_path):
|
||||
"""Remove gray/white checkerboard pattern and make background transparent"""
|
||||
|
||||
img = Image.open(input_path).convert('RGBA')
|
||||
pixels = img.load()
|
||||
width, height = img.size
|
||||
|
||||
print(f"Image size: {width}x{height}")
|
||||
|
||||
modified = 0
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
r, g, b, a = pixels[x, y]
|
||||
|
||||
# Skip if already transparent
|
||||
if a == 0:
|
||||
continue
|
||||
|
||||
# Check if pixel is grayscale (R ≈ G ≈ B)
|
||||
is_grayscale = abs(r - g) < 20 and abs(g - b) < 20 and abs(r - b) < 20
|
||||
brightness = (r + g + b) / 3
|
||||
|
||||
should_remove = False
|
||||
|
||||
# Remove checkerboard grays (common values: 204, 153, 192, 128, 255)
|
||||
if is_grayscale and brightness > 100:
|
||||
should_remove = True
|
||||
|
||||
# Remove very bright pixels
|
||||
if brightness > 200:
|
||||
should_remove = True
|
||||
|
||||
# Remove pure white
|
||||
if r > 240 and g > 240 and b > 240:
|
||||
should_remove = True
|
||||
|
||||
if should_remove:
|
||||
pixels[x, y] = (r, g, b, 0) # Make transparent
|
||||
modified += 1
|
||||
|
||||
img.save(output_path, 'PNG')
|
||||
print(f"✅ Processed! Removed {modified} background pixels")
|
||||
print(f"📁 Saved to: {output_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Use the ORIGINAL image you uploaded
|
||||
input_file = r"C:\Users\hipod\.gemini\antigravity\brain\70050185-4972-4413-9765-559b6f2ad1cc\uploaded_image_1765710182006.jpg"
|
||||
output_file = r"c:\novafarma\assets\sprites\player_walking_clean.png"
|
||||
|
||||
remove_checkerboard(input_file, output_file)
|
||||
Reference in New Issue
Block a user