python作函数图像_在Python中作为函数的图像下采样

我试图重新采样一些tiff文件从2000*2000到500*500。

我创建了一个函数,我尝试了一个文件,它工作得很好。现在我想把它应用到所有可用的文件中。在

我想写函数的输出,我已经根据我的知识编写了代码,我收到了关于写出_文件的错误。我已经复制了函数和主代码供您考虑。主代码只是根据文件名读取tif文件并应用函数。如果有人能指点我的错误在哪里,我将不胜感激。在#*********function********************

def ResampleImage(infile):

fp = open(infile, "rb")

p = ImageFile.Parser()

while 1:

s = fp.read()

if not s:

break

p.feed(s)

img = p.close()

basewidth = 500

wpercent = (basewidth / float(img.size[0]))

hsize = int((float(img.size[1]) * float(wpercent)))

outfile=img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)

return outfile

#********* main code********

import os,sys

import ImageResizeF

import PIL

from PIL import Image

from PIL import Image,ImageFile

tpath = 'e:/.../resampling_test/all_tiles/'

tifext = '.tif'

east_start = 32511616

north_start = 5400756

ilist = range (0,14)

jlist = range (0,11)

north = north_start

ee = ',4_'

en = ',2'

for i in ilist:

east = east_start

north = north_start + i * 400

snorth = str (north)

for j in jlist:

east = east_start + j * 400

seast = str (east)

infile = tpath + seast + ee + snorth + en + tifext

output = tpath + seast + ee + snorth + en + '_res'+tifext

out_file = ImageResizeF.ResampleImage(infile)

out_file.write (output)

out_file.close ()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值