对2048*1000图像进行裁剪,并且根据patch进行命名
其中输入大小图像和输出图像大小均可自定义
import cv2 as cv
import numpy as np
img = cv.imread(r'E:/CondaFile/crop_slide/demo.jpg')
side = 200 # 裁剪大小200*200
num_h = h//side
num_w = w//side
img = np.array(img)
img_gt = np.array(img_gt)
img_crop = np.zeros((200,200,3))
image = []
for h in range(0,num_h):
for w in range(0,num_w):
img_crop = img[h*200:(h+1)*200,w*200:(w+1)*200]
image.append(img_crop)
pass
pass
path_img = r'E:/CondaFile/crop_slide/img/' # 保存路径
for i in range(0,len(image)):
image_i = image[i]
path_image_i = r'E:/CondaFile/crop_slide/img/' + str(i+1)+str('.jpg')
cv.imwrite(path_image_i,image_i)
使用opencv库进行图像滑窗裁剪图像
opencv版本4.5+
python版本3.9 +
欢迎批评指正!