from PIL import Image
im=Image.open('C:/Users/xpp/Desktop/Lena.png ')
#寬高各除3,獲取裁剪后的單張圖片大小
width=im.size[0]//3
height=im.size[1]//3
#width=im.size[0]//4

#height=im.size[1]//4
#裁剪圖片的左上角坐標(biāo)
start_x=0
start_y=0

#圖像重命名
im_name = 1
#圖像裁剪
for i in range(3):

for j in range(3):
#for i in range(4:
#for j in range(4):
#圖像裁剪并保存

crop=im.crop((start_x,start_y,start_x+width,start_y+height))
crop.save('C:/Users/xpp/Desktop/imgs/'+str(im_name)+'.jpg')
#將左上角坐標(biāo)的 x 軸向右移動(dòng)
start_x+=width

im_name+=1
#當(dāng)?shù)谝恍胁眉敉旰髕繼續(xù)從0開始裁剪
start_x=0
#裁剪第二行
start_y+=height
復(fù)制
算法:圖像任意裁剪是將圖像裁剪成若干任意大小圖像。文獻(xiàn):LHL圖片裁剪為指定大小, 李紅林. (2011). 基于投影法實(shí)現(xiàn)矩形窗口的任意曲線裁剪 of in based on the . 云南民族大學(xué)學(xué)報(bào):自然科學(xué)版, 20(2).Kurtz, B. D. ,&圖片裁剪為指定大小, S. J. . (1999). for an path. US.鏈接: