🐍 Python Implementation
import numpy as np
from PIL import Image
import math
def analyze_image(image_path):
img = Image.open(image_path).convert('L')
img = img.resize((100, 100))
data = np.array(img)
w, h = data.shape
center_x, center_y = w // 2, h // 2
diag_score = 0
for i in range(15, 85, 3):
x1 = int((i / 100) * w)
y1 = int((i / 100) * h)
x2 = int(((100 - i) / 100) * w)
y2 = int((i / 100) * h)
if is_dark(data[y1, x1]):
diag_score += 1
if is_dark(data[y2, x2]):
diag_score += 1
center_crossing = 0
for offset in range(-8, 9, 2):
x1, y1 = center_x + offset, center_y + offset
x2, y2 = center_x - offset, center_y + offset
if 0 <= x1 < w and 0 <= y1 < h and is_dark(data[y1, x1]):
center_crossing += 1
if 0 <= x2 < w and 0 <= y2 < h and is_dark(data[y2, x2]):
center_crossing += 1
circle_score = 0
radiuses = [15, 20, 25, 30]
for radius in radiuses:
for angle in range(0, 360, 15):
x = int(center_x + radius * math.cos(math.radians(angle)))
y = int(center_y + radius * math.sin(math.radians(angle)))
if 0 <= x < w and 0 <= y < h and is_dark(data[y, x]):
circle_score += 1
center_hollow = 0
center_total = 0
for x in range(center_x - 10, center_x + 11, 2):
for y in range(center_y - 10, center_y + 11, 2):
if 0 <= x < w and 0 <= y < h:
center_total += 1
if not is_dark(data[y, x]):
center_hollow += 1
x_score = diag_score + center_crossing * 2
o_score = circle_score + (20 if center_hollow > center_total * 0.6 else 0)
if x_score > o_score * 1.2:
return "X", "High"
elif o_score > x_score * 1.2:
return "O", "High"
else:
return ("X" if x_score > o_score else "O"), "Low"
def is_dark(pixel_value):
return pixel_value < 100