效果:
import cv2
import numpy as np
foldpath='D:/project/Results/expand_img/c/'
suanfa = 'PVT' # fixed moving VM2 nnFormer PVT TM ICN
image = cv2.imread(foldpath + suanfa + '.png')
# 第一个局部放大图
a=78
b=19
c=a+30
d=b+30
pt1 = (a, b) # 长方形框左上角坐标
pt2 = (c, d) # 长方形框右下角坐标
cv2.rectangle(image, pt1, pt2, (0, 0, 255), 2)
patch1 = image[b:d, a:c, :]
patch1resize = cv2.resize(patch1, (80, 80))
# 第二个局部放大图
a=63
b=115
c=a+30
d=b+30
pt1 = (a, b) # 长方形框左上角坐标
pt2 = (c, d) # 长方形框右下角坐标
cv2.rectangle(image, pt1, pt2, (0, 255, 0), 2)
patch2 = image[b:d, a:c, :]
patch2resize = cv2.resize(patch2, (80, 80))
# 拼接
patch = np.hstack((patch1resize, patch2resize))
image = np.vstack((image, patch))
cv2.imshow('demo', image)
cv2.waitKey(0)
cv2.imwrite(foldpath + suanfa + '_combine.png', image)