ThreadTone icon indicating copy to clipboard operation
ThreadTone copied to clipboard

Square shape

Open simixmc opened this issue 2 years ago • 1 comments

How can I rework the script to get a square image?

simixmc avatar Oct 23 '23 08:10 simixmc

I might be a bit late 😄 However, this is pretty simple.

Try these steps.

  1. Avoid masking to a circular image.
  2. Update the finding pin coordinates function to find pins in the rectangular perimeter.
  3. Update the main loop to go through all pins(this depends on how the pin coordinates are calculated).
  4. (optional) Update minLoop to a higher value.
Code changes
    # Mask image
-    imgMasked = maskImage(imgInverted, imgRadius)
+   imgMasked = imgInverted
    cv2.imwrite('./masked.png', imgMasked)

  1. Add new pin coordinates function
def pinCoordsRectangular(width, height, horizontalPins=200, verticalPins=200,):
    coords = []
    # Calculate spacing
    x_spacing = width / (horizontalPins - 1)
    y_spacing = height / (verticalPins - 1)

    # Top edge (left to right)
    for j in range(horizontalPins):
        coords.append((int(j * x_spacing), 0))

    for i in range(1, verticalPins):
        coords.append((width, int(i * y_spacing)))

    for j in range(horizontalPins - 1, -1, -1):
        coords.append((int(j * x_spacing), height))

    for i in range(verticalPins - 1, 0, -1):
        coords.append((0, int(i * y_spacing)))

    return coords

then

    # Define pin coordinates
-    coords = pinCoords(imgRadius, numPins)
+   coords = pinCoordsRectangular(width, height, horizontalPins=numPins, verticalPins=numPins)
    height, width = imgMasked.shape[0:2]
        # Loop over possible lines
+        numPins = len(coords)
        for index in range(1, numPins):
            pin = (oldPin + index) % numPins
- minLoop = 3         # Disallow loops of less than minLoop lines
+ minLoop = 3         # Disallow loops of less than minLoop lines

jkmathew avatar Jan 19 '25 20:01 jkmathew