问题描述
我想将图像分割成三角形瓷砖(等边)。我尝试使用 https://alexwlchan.net/2016/10/tiling-the-plane-with-pillow/ 中的函数生成三角形的坐标。 我的代码:
#import opencv
import math
image_path="/content/newspaper-icon-in-transparent-style-news-on-vector-25591681.jpg"
#Create Triangles
# https://alexwlchan.net/2016/10/tiling-the-plane-with-pillow/
#A horrizontal offset is added to ensure that images line up
#https://stackoverflow.com/questions/22588074/polygon-crop-clip-using-python-pil
def generate_coordinates_for_unit_triangles(image_width,image_height):
image_width=50;
image_height=50;
h=math.sin(math.pi/3)
for x in range(image_width):
for y in range(int(image_height / h)):
first_c,second_c,third_c=(x,y * h),(x+1,((x+0.5,(y+1) * h))
first_sc,second_sc,third_sc=(x+1,(x+1.5,(y+1) * h),(x+0.5,(y+1) * h)
return first_c,third_c,first_sc,third_sc
#return [(x,(y+1) * h)],[(x+1,(y+1) * h)]
##Generates the two triangles coordinates
first_c,third_sc=generate_coordinates_for_unit_triangles(50,50)
#convert image into numpy array
image_read=Image.open(image_path)
image_to_numpy=np.asarray(image_read)
shape_of_array=image_to_numpy.shape
print(shape_of_array)
mask_image=[first_c,third_sc]
我意识到这可能没有给出我想要的输出。
预期的输入和输出如下: [预期输入和输出][1]
有关如何解决问题的任何指导将不胜感激。 [1]:https://i.stack.imgur.com/vr7rV.jpg
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)