zoukankan      html  css  js  c++  java
  • python+图像对的合并和分离

     

    1、图像对的合并,即将trainA0中图像1_aa.jpg,trainB0中图像0_aa.jpg,合并到all中,图像对按着,即str(num)_1_aa.jpg,str(num)_0_aa.jpg

    import os
    import shutil
    Adir = './trainA0/'
    Bdir = './trainB0/'
    alldir = './all/'
    if not os.path.exists(Adir):
          print ("The source path trainA0 is not exist")
    if not os.path.exists(Bdir):
          print ("The source path trainB0 is not exist")
    if not os.path.exists(alldir):
          os.mkdir(alldir)
    
    num=0
    for fi in os.listdir(Adir):
          im_name = '0' + fi[1:]
          shutil.copyfile(Adir+fi,alldir+str(num)+'_'+fi) #把文件夹Adir中的文件fi,复制到文件夹alldir中,并重新命名为str(num)+'_'+fi
          shutil.copyfile(Bdir+im_name,alldir+str(num)+'_'+im_name)
          num = num + 1
          print (num)

     2、图像对的分离,all中,图像对按着,即str(num)_1_aa.jpg,str(num)_0_aa.jpg,分离到trainA0中图像1_aa.jpg,trainB0中图像0_aa.jpg

    import os
    import shutil
    alldir = './all/'
    
    Adir = './A/'
    Bdir = './B/'
    if not os.path.exists(alldir):
          print ("The source path alldir is not exist")
    if not os.path.exists(Adir):
          os.mkdir(Adir)
    if not os.path.exists(Bdir):
          os.mkdir(Bdir)
    
    num=0
    for fi in os.listdir(alldir):
          num_str = fi.split('_')[0]
          im_name = fi[len(num_str)+1:]
          if fi.split('_')[1]=='1':
              shutil.copyfile(alldir+fi,Adir+im_name)
          else:
              shutil.copyfile(alldir+fi,Bdir+im_name)
          num = num + 1
          print (num)

    3、图像对的挑选,A中图像1_aa.jpg,B中图像0_aa.jpg,B中图像被混合到了trainB0中,现在从trainB0中挑选出正确的图像到B中。

    import os
    import shutil
    Adir = './A/'
    Bdir = './trainB0/'
    alldir = './B/'
    if not os.path.exists(Adir):
          print ("The source path trainA0 is not exist")
    if not os.path.exists(Bdir):
          print ("The source path trainB0 is not exist")
    if not os.path.exists(alldir):
          os.mkdir(alldir)
    
    num=0
    for fi in os.listdir(Adir):
          im_name = '0' + fi[1:]
          shutil.copyfile(Bdir+im_name,alldir+im_name)
          num = num + 1
          print (num)
  • 相关阅读:
    Nginx编译安装第三方模块http_substitutions_filter_module
    房产网站网址收藏
    nginx图片过滤处理模块http_image_filter_module安装配置笔记
    Lua顺序 执行顺序
    Dig HOWTO 中文手册--dig命令使用大全
    没有局域网环境,全是公网IP可以做LVS吗,该如何做了!请大家赐教!
    Nginx HttpSubModule sub_filter模块的过滤功能
    NGINX扩展
    oracle中导出sql的几个常见词语的意思
    int型变量,不使用中间变量完成互换
  • 原文地址:https://www.cnblogs.com/wjjcjj/p/12307095.html
Copyright © 2011-2022 走看看