超分、复原方面paper画结果图的代码

本博文为本人mark下如何割子图的代码:

from PIL import Image, ImageDraw
import glob, os
 

dir = '/home/guanwp/zhangwenlong/OPNet/'  # the direction of the result
 

# the(x, y), and the width
x = 80
y = 60
width = 400
scale=1
 
# capture an image
pyFile = glob.glob(os.path.join(dir, "*.png"))
pyFile += glob.glob(os.path.join(dir, "*.jpg"))
pyFile += glob.glob(os.path.join(dir, "*.bmp"))
result_path = os.path.join(dir,"result")
 
# if the in result
if not os.path.exists(result_path) :
        os.mkdir(result_path)
 
# Traverse the picture
for img_path in pyFile:
    im = Image.open(img_path)
    draw = ImageDraw.Draw(im)
 
    aspect_ratio = 1#im.size[0]/im.size[1] # Aspect ratio
    # Intercepting a selection image
    im_ = im.crop((x, y, x+width, (y+width)//aspect_ratio))
    # Box out of the selection
    draw.rectangle((x, y, x+width, (y+width)//aspect_ratio), outline='blue', width=3) # width is the width of the line
 
    #im_ = im_.resize(im.size) # Call the resize function to enlarge the submap to the original image size
    width1=int(im_.size[0]*scale)
    height1=int(im_.size[1]*scale)
    im_=im_.resize((width1, height1), Image.ANTIALIAS)
 
    # Get the file name
    _, img_name = os.path.split(img_path)
    img_name, _ = os.path.splitext(img_name)
 
    # Save submap and original image with marquee
    im_.save(os.path.join(result_path , img_name + '_sub_image.png'))
    im.save(os.path.join(result_path , img_name + '_ori_image.png'))

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值