Hi, I am trying to use flood fill algorithm to cut out sprites from spritesheet not aligned to grid. But it keeps going and going.

func separate(image: Image) -> void:
		var images := 0
		image.lock()
		var start := {"position": Vector2(0, 0), "previous_blank": true}
		var checked_pixels := []
		var pixels := [start]
		while not pixels.empty():
			var dict: Dictionary = pixels.pop_back()
			var pixel: Vector2 = dict.position
			checked_pixels.append(dict)
			var blank: bool = image.get_pixelv(pixel).a == 0
			if not blank and dict.previous_blank:
				images += 1
			var neighbors := []
			if not pixel.x == image.get_width() - 1:
				neighbors.append({"position": Vector2(pixel.x + 1, pixel.y), "previous_blank": blank})
			if not pixel.y == image.get_height() - 1:
				neighbors.append({"position": Vector2(pixel.x, pixel.y + 1), "previous_blank": blank})
			for n in neighbors:
				var found_match := false
				for p in pixels:
					if p.position == n.position:
						found_match = true
						break
				if found_match:
					continue
				for c in checked_pixels:
					if c.position == n.position:
						found_match = true
						break
				if found_match:
					continue
				pixels.append(n)
		image.unlock()
		print(images)
``