然后将所有这些目标图像相加。
具有0的区域将被覆盖,1覆盖和2 to n将意味着被2 to n图像覆盖。
当使用numpy的广播工具时,这是非常简单和有效的。
import cv2
import numpy as np
#our target area (the black background)
dst = np.zeros((100,100),dtype=np.int)
src1 = dst.copy()
src2 = dst.copy()
src1[50:,50:] = 1 #fake of first translated image (row/col 50-end)
src2[:70,:70] = 1 #fake of second translated image (row/col 0-70)
overlap = src1+src2 #sum of both *element-wise*
cv2.imwrite('a.png', src1*255) #opencv likes it's grey images span from 0-255
cv2.imwrite('b.png', src2*255) #...
cv2.imwrite('c.png', overlap*127) #here vals 0-2, *127 gives (almost) 255 again
np.where(overlap==2) #gives you a mask with all pixels that have value 2
如何创建两者的掩码/二进制图像并使用逻辑和?
您还可以将每个图像(图像内容均为1)的灰度副本转换为每个图像的目标(初始化为0)的新副本。
然后将所有这些目标图像相加。 具有
0
的区域将被覆盖,1
覆盖和2 to n
将意味着被2 to n
图像覆盖。当使用numpy的广播工具时,这是非常简单和有效的。
src2(b)
+
src1(a)=
重叠(c)希望能有所帮助。
相关问题 更多 >
编程相关推荐