import numpy as np
def divide_image(image, num_vertical_divides, num_horizontal_divides):
"""
Divides a white-black image into subimages based on the number of vertical and horizontal divides.
Args:
image: A numpy array representing the white-black image.
num_vertical_divides: The number of vertical divides.
num_horizontal_divides: The number of horizontal divides.
Returns:
A list of tuples, where each tuple represents a cutting line with its start and end points.
"""
height, width = image.shape
vertical_lines = []
horizontal_lines = []
# Calculate vertical cutting lines
for i in range(1, num_vertical_divides + 1):
x = int(width * (i / (num_vertical_divides + 1)))
vertical_lines.append(((x, 0), (x, height - 1)))
# Calculate horizontal cutting lines
for i in range(1, num_horizontal_divides + 1):
y = int(height * (i / (num_horizontal_divides + 1)))
horizontal_lines.append(((0, y), (width - 1, y)))
return vertical_lines + horizontal_lines
# Example usage:
# Assuming you have a 256x256 image and want to divide it into 4x4 grid (3 vertical and 3 horizontal divides)
image = np.zeros((256, 256)) # Example black image
cutting_lines = divide_image(image, 3, 3)
# Print the start and end points of each cutting line
for line in cutting_lines:
print(f"Start: {line[0]}, End: {line[1]}")
aW1wb3J0IG51bXB5IGFzIG5wCgpkZWYgZGl2aWRlX2ltYWdlKGltYWdlLCBudW1fdmVydGljYWxfZGl2aWRlcywgbnVtX2hvcml6b250YWxfZGl2aWRlcyk6CiAgIiIiCiAgRGl2aWRlcyBhIHdoaXRlLWJsYWNrIGltYWdlIGludG8gc3ViaW1hZ2VzIGJhc2VkIG9uIHRoZSBudW1iZXIgb2YgdmVydGljYWwgYW5kIGhvcml6b250YWwgZGl2aWRlcy4KCiAgQXJnczoKICAgIGltYWdlOiBBIG51bXB5IGFycmF5IHJlcHJlc2VudGluZyB0aGUgd2hpdGUtYmxhY2sgaW1hZ2UuCiAgICBudW1fdmVydGljYWxfZGl2aWRlczogVGhlIG51bWJlciBvZiB2ZXJ0aWNhbCBkaXZpZGVzLgogICAgbnVtX2hvcml6b250YWxfZGl2aWRlczogVGhlIG51bWJlciBvZiBob3Jpem9udGFsIGRpdmlkZXMuCgogIFJldHVybnM6CiAgICBBIGxpc3Qg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WdlLCAzLCAzKQoKIyBQcmludCB0aGUgc3RhcnQgYW5kIGVuZCBwb2ludHMgb2YgZWFjaCBjdXR0aW5nIGxpbmUKZm9yIGxpbmUgaW4gY3V0dGluZ19saW5lczoKICBwcmludChmIlN0YXJ0OiB7bGluZVswXX0sIEVuZDoge2xpbmVbMV19Iikg
Start: (64, 0), End: (64, 255)
Start: (128, 0), End: (128, 255)
Start: (192, 0), End: (192, 255)
Start: (0, 64), End: (255, 64)
Start: (0, 128), End: (255, 128)
Start: (0, 192), End: (255, 192)