import os
import sys
import string
import math
from os import getcwd
from PIL import Image
Fix_X = 400
Fix_Y = 400
def ProcessFile(aFile):
mTuple = os.path.split(aFile)
curdir = mTuple[0];
fileName = mTuple[1];
extendName = fileName.split('.').pop()
if extendName == "gif" or extendName == "bmp" or extendName == "jpg" :
im = Image.open(aFile)
xsize, ysize = im.size
#print xsize,ysize
V_SPLITE = int(math.ceil((xsize * 1.00)/(Fix_X * 1.00)))
H_SPLITE = int(math.ceil((ysize * 1.00)/(Fix_Y * 1.00)))
#print V_SPLITE,H_SPLITE
for i in range (0, H_SPLITE ):
for j in range ( 0 , V_SPLITE ):
pointX=j*Fix_X
pointY=i*Fix_Y
if (pointX+Fix_X)>xsize :
width=xsize-pointX
else:
width=Fix_X
if (pointY+Fix_Y)>ysize:
height=ysize-pointY
else:
height=Fix_Y
im_temp = Image.new('RGB',(width,height))
box = (pointX,pointY
,pointX+width,pointY+height)
#print box
region = im.crop(box)
im_temp.paste(region,(0,0))
im_temp.save(curdir+"_"+"%s"%(V_SPLITE*i + j) + ".jpg")
def TraverseDir(aPath):
mList = os.listdir(aPath)
for mPath in mList:
python影像分割 python图像分割代码
转载文章标签 python影像分割 python图像分割 Image 文章分类 Python 后端开发
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章