裁剪遥感影像--制作数据集
import os from PIL import Image import cv2 import time file_dir = '.' files = os.listdir(file_dir) na = 0 for file in files: if os.path.isfile(file): # img = Image.open(file) img = cv2.imread(file) long = img.shape[0] width = img.shape[1] upper = 0 lower = 0 kj = 0 while lower + 16 < width: left = 0 upper = (16*kj) right = 16 lower = 16*(kj+1) kj +=1 print(left, upper, right, lower) ki = 0 while right + 16 <long: left = ki * 16 right = 16 + ki * 16 ki +=1 newImg = img[upper:lower-1,left:right-1] na = str(na) # newImg.save("/home/ly/Documents/program/RGB-Water/Edata/"+na+".jpg") cv2.imwrite("