如何解决如何水平和垂直连接两个 alpha 图像?
我使用 alpha 蒙版创建了直角三角形图像。我想垂直和水平地加入它们。 面具:An alpha mask for right angle triangles
Another alpha mask for right angle triangles
切片后的图像是: Right Angle Triangles using the first alpha mask
Right Angle Triangles using the second alpha mask
我想通过以下方式合并两个直角三角形:
但是,我一直输出不正确: Incorrect output
连接三角形的代码: 我使用了以下示例:Masking two images and merge into one image
def mirror_triangles_one():
x=first_array[0] #The first array contains right angle triangles sliced using alpha mask one
y=second_array[2] #The second array contains right angle triangles sliced using alpha mask two
x_im=x
x_im.paste(y,(-4,0),y)
x_im.save('mirror_five.png')
return x_im
解决方法
这是我在 Python/OpenCV/Numpy 中的做法。但我不得不裁剪你的图像,所以结果不会准确。假设您已将三角形图像填充为带有白色的矩形,则只需 hstack 的两个图像。请注意,它们必须具有相同的高度。
左:
对:
import cv2
import numpy as np
# read right image
right = cv2.imread('right.png')
rhh,rww = right.shape[:2]
# read left image
left = cv2.imread('left.png')
lhh,lww = left.shape[:2]
# compute min height and crop images to same height
minh = min(rhh,lhh)
right = right[0:minh,0:rww]
left = left[0:minh,0:lww]
# stack horizontally
result = np.hstack([left,right])
# save result
cv2.imwrite('left_right_result.jpg',result)
# display result
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destroyAllWindows()
结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。