此函数为Python版本的棋盘格镶嵌图,用于评价图像配准结果
参数I1和I2为输入的图像,n为分块的个数为整数
def checkboard(I1, I2, n):
assert I1.shape == I2.shape
height, width, channels = I1.shape
hi, wi = height/n, width/n
outshape = (int(hin), int(win), channels)
out_image = np.zeros(outshape, dtype=‘uint8’)
for i in range(n):
h = int(round(hi * i))
h1 = int(round(h + hi))
for j in range(n):
w = int(round(wi * j))
w1 =int(round( w + wi))
if (i-j)%2 == 0:
out_image[h:h1, w:w1, :] = I1[h:h1, w:w1, :]
else:
out_image[h:h1, w:w1, :] = I2[h:h1, w:w1, :]
return out_image
有问题的小伙伴+Q:1399212294