There are multiple ways to approach this problem using Python, but one possible solution is:
import numpy as np import cv2 from itertools import cycle
image = cv2.imread('image.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
shapes = ['square', 'triangle']
size = 20 spacing = 5
tessellated_image = np.zeros_like(gray) for i, row in enumerate(range(0, gray.shape[0], size + spacing)): shape_cycle = cycle(shapes) for j, col in enumerate(range(0, gray.shape[1], size + spacing)): shape = next(shape_cycle) if shape == 'square': tessellated_image[row:row+size, col:col+size] = gray[row:row+size, col:col+size] elif shape == 'triangle': if i % 2 == 0: pts = np.array([(col, row), (col+size, row), (col+size//2, row+size)]) else: pts = np.array([(col, row+size), (col+size, row+size), (col+size//2, row)]) mask = np.zeros_like(gray) cv2.fillPoly(mask, [pts], 255) tessellated_image += cv2.bitwise_and(mask, gray)
cv2.imwrite('tessellated_image.png', tessellated_image)
Note that this code only implements a very basic tessellation pattern, and more complex patterns can be achieved by modifying the shape list and the shape drawing code in step 6. Additionally, this code does not optimize the tessellation for efficiency or visual quality, and further adjustments may be required depending on the specific use case.
Asked: 2022-05-11 11:00:00 +0000
Seen: 11 times
Last updated: Jun 27 '21