我有一个带有质心的图像,需要将其分成4个,如下面的代码所示... 在python中将图像分成4个相等帧并进行比较的最佳方法是什么? 例如:A与B; A与C; A与D
要使用哪个库?
lesao = cv2.imread("entrada.jpg")
threshold = 127
img = cv2.cvtColor(lesao, cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(img,threshold,255,cv2.THRESH_BINARY_INV)
height, width = thresh.shape[:4]
thresh2 = cv2.bitwise_and(lesao, lesao, mask = thresh)
mass = 0
Xcm = 0.0
Ycm = 0.0
for i in range(width) :
for j in range(height) :
if not thresh[j][i] :
mass += 1
Xcm += i
Ycm += j
Xcm = Xcm/mass
Ycm = Ycm/mass
x = np.round(Xcm).astype("int")
y = np.round(Ycm).astype("int")
verde = (255, 255, 255)
cv2.line(thresh2, (x,0), (x, y), verde, 3)
cv2.line(thresh2, (x,0), (x, y+y), verde, 3)
cv2.line(thresh2, (0,y), (x, y), verde, 3)
cv2.line(thresh2, (x+x,y), (x, y), verde, 3)
fig = plt.figure()
fig.clear()
plot = fig.add_subplot(111)
plot.imshow(thresh2)
plot.scatter([Xcm], [Ycm], s=50, c='yellow', edgecolors='red')
plt.show()