I have this map of Europe and I need to grab each province individually and make a Province object of them, with the list of points stored within each object. Currently I have a script that can get all points that are neighboring different colors. But I don't know how to go from here.
def getNeighboringPixels(x, y, width, height):
neighbors = []
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
nx, ny = x + dx, y + dy
if 0 <= nx < width and 0 <= ny < height and (dx, dy) != (0, 0):
neighbors.append((nx, ny))
return neighbors
def generatePoints(image_path):
points = []
image = p.image.load(image_path)
width = image.get_width()
height = image.get_height()
for y in range(height):
for x in range(width):
pixel = image.get_at((x, y))
neighboring_pixels = [image.get_at(pos) for pos in getNeighboringPixels(x, y, width, height)]
if any(pixel != neighbor for neighbor in neighboring_pixels):
points.append([x, y])
return points
I am using pygame