深度学习 常用python操作(1)

1:python遍历文件夹

import os
# get .txt document
rootdir=os.path.join('要读取的txt文件的绝对路径')
# read
write_path=open('要写入的txt文件的绝对路径/write.txt','w')
for (dirpath,dirnames,filenames) in os.walk(rootdir):
    for filename in filenames:
        if os.path.splitext(filename)[1]=='.txt':
            write_path.write('要写的绝对路径'+filename+'\n')

2:PIL获取图片尺寸

  • https://blog.csdn.net/weixin_42305378/article/details/106785502
img = Image.open("beibei.jps")
print(img.size)

3:Image.new()

  • https://blog.csdn.net/m0_38027013/article/details/90379971
img = Image.new('RGB',(125,125),'white')

4:两张图显示在一张图片上

from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
 
 
# 1. 将两张icon图标显示在同一张图上面并保存;
def combine_photo(arr):
    #arr是一个列表,里面是两个图片的路径,例如["p1.png", 'p2.png']
    toImage = Image.new('RGB', (128, 64))
    img1 = Image.open(arr[0])
    img12 = Image.open(arr[1])
    toImage.paste(img1, (0, 0))
    toImage.paste(img12, (64, 0, 64 + img1.size[0], 0 + img1.size[1]))
    #函数描述:toImage:背景图片,paste()函数四个变量分别为:起始横轴坐标,起始纵轴坐标,横轴结束坐标,纵轴结束坐标;
    toImage.save( + "merged.png")
    plt.imshow(toImage)
    plt.title(level)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值