|
@@ -0,0 +1,22 @@
|
|
|
+from PIL import Image
|
|
|
+import numpy as np
|
|
|
+
|
|
|
+# 读取两个黑白mask图片
|
|
|
+image1 = Image.open("mask1.png").convert("L")
|
|
|
+image2 = Image.open("mask2.png").convert("L")
|
|
|
+
|
|
|
+# 转化为numpy数组
|
|
|
+image1_array = np.array(image1)
|
|
|
+image2_array = np.array(image2)
|
|
|
+
|
|
|
+# 使用逻辑或运算,如果有一个像素是白色,则此处为白色
|
|
|
+result_array = np.maximum(image1_array, image2_array)
|
|
|
+
|
|
|
+# 将numpy数组转化为图像
|
|
|
+result_image = Image.fromarray(result_array)
|
|
|
+
|
|
|
+# 显示图像
|
|
|
+result_image.show()
|
|
|
+
|
|
|
+# 保存图像
|
|
|
+result_image.save("result.png")
|