import numpy as np
def divide_image(image_path, vertical_divides, horizontal_divides):
# Load the image in grayscale
# image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# if image is None:
# raise ValueError("Image not found or unable to load.")
image = np.zeros((256, 256), dtype=np.uint8)
# Get image dimensions
height, width = image.shape
# Calculate the step size for vertical and horizontal cuts
vertical_step = width // (vertical_divides + 1)
horizontal_step = height // (horizontal_divides + 1)
# Initialize lists to store the cutting lines
vertical_lines = []
horizontal_lines = []
# Calculate vertical cutting lines
for i in range(1, vertical_divides + 1):
x = i * vertical_step
vertical_lines.append(((x, 0), (x, height)))
# Calculate horizontal cutting lines
for i in range(1, horizontal_divides + 1):
y = i * horizontal_step
horizontal_lines.append(((0, y), (width, y)))
return vertical_lines, horizontal_lines
# Example usage
image_path = 'path_to_your_image.png'
vertical_divides = 3
horizontal_divides = 3
vertical_lines, horizontal_lines = divide_image(
image_path, vertical_divides, horizontal_divides)
print("Vertical Lines:")
for line in vertical_lines:
print(f"Start: {line[0]}, End: {line[1]}")
print("\nHorizontal Lines:")
for line in horizontal_lines:
print(f"Start: {line[0]}, End: {line[1]}")
aW1wb3J0IG51bXB5IGFzIG5wCgoKZGVmIGRpdmlkZV9pbWFnZShpbWFnZV9wYXRoLCB2ZXJ0aWNhbF9kaXZpZGVzLCBob3Jpem9udGFsX2RpdmlkZXMpOgogICAgIyBMb2FkIHRoZSBpbWFnZSBpbiBncmF5c2NhbGUKICAgICMgaW1hZ2UgPSBjdjIuaW1yZWFkKGltYWdlX3BhdGgsIGN2Mi5JTVJFQURfR1JBWVNDQUxFKQogICAgIyBpZiBpbWFnZSBpcyBOb25lOgogICAgIyAgICAgcmFpc2UgVmFsdWVFcnJvcigiSW1hZ2Ugbm90IGZvdW5kIG9yIHVuYWJsZSB0byBsb2FkLiIpCiAgICBpbWFnZSA9IG5wLnplcm9zKCgyNTYsIDI1NiksIGR0eXBlPW5wLnVpbnQ4KQoKICAgICMgR2V0IGltYWdlIGRpbWVuc2lvbnMKICAgI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XMgPSBkaXZpZGVfaW1hZ2UoCiAgICBpbWFnZV9wYXRoLCB2ZXJ0aWNhbF9kaXZpZGVzLCBob3Jpem9udGFsX2RpdmlkZXMpCgpwcmludCgiVmVydGljYWwgTGluZXM6IikKZm9yIGxpbmUgaW4gdmVydGljYWxfbGluZXM6CiAgICBwcmludChmIlN0YXJ0OiB7bGluZVswXX0sIEVuZDoge2xpbmVbMV19IikKCnByaW50KCJcbkhvcml6b250YWwgTGluZXM6IikKZm9yIGxpbmUgaW4gaG9yaXpvbnRhbF9saW5lczoKICAgIHByaW50KGYiU3RhcnQ6IHtsaW5lWzBdfSwgRW5kOiB7bGluZVsxXX0iKQo=
Vertical Lines:
Start: (64, 0), End: (64, 256)
Start: (128, 0), End: (128, 256)
Start: (192, 0), End: (192, 256)
Horizontal Lines:
Start: (0, 64), End: (256, 64)
Start: (0, 128), End: (256, 128)
Start: (0, 192), End: (256, 192)