fork download
  1. import numpy as np
  2.  
  3.  
  4. def divide_image(image_path, vertical_divides, horizontal_divides):
  5. # Load the image in grayscale
  6. # image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
  7. # if image is None:
  8. # raise ValueError("Image not found or unable to load.")
  9. image = np.zeros((256, 256), dtype=np.uint8)
  10.  
  11. # Get image dimensions
  12. height, width = image.shape
  13.  
  14. # Calculate the step size for vertical and horizontal cuts
  15. vertical_step = width // (vertical_divides + 1)
  16. horizontal_step = height // (horizontal_divides + 1)
  17.  
  18. # Initialize lists to store the cutting lines
  19. vertical_lines = []
  20. horizontal_lines = []
  21.  
  22. # Calculate vertical cutting lines
  23. for i in range(1, vertical_divides + 1):
  24. x = i * vertical_step
  25. vertical_lines.append(((x, 0), (x, height)))
  26.  
  27. # Calculate horizontal cutting lines
  28. for i in range(1, horizontal_divides + 1):
  29. y = i * horizontal_step
  30. horizontal_lines.append(((0, y), (width, y)))
  31.  
  32. return vertical_lines, horizontal_lines
  33.  
  34.  
  35. # Example usage
  36. image_path = 'path_to_your_image.png'
  37. vertical_divides = 3
  38. horizontal_divides = 3
  39.  
  40. vertical_lines, horizontal_lines = divide_image(
  41. image_path, vertical_divides, horizontal_divides)
  42.  
  43. print("Vertical Lines:")
  44. for line in vertical_lines:
  45. print(f"Start: {line[0]}, End: {line[1]}")
  46.  
  47. print("\nHorizontal Lines:")
  48. for line in horizontal_lines:
  49. print(f"Start: {line[0]}, End: {line[1]}")
  50.  
Success #stdin #stdout 0.18s 28836KB
stdin
Standard input is empty
stdout
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)