python将处理好的图像保存到指定目录下

原始图像绝对路径的图像名存储在一个txt文件中,下面的程序实现的功能是按照txt文件的顺序,依次将图片读取然后进行处理,最后将处理之后的图像保存在指定的路径下:

# Read in the image to be detected
# 原始图像均保存在binaries.txt文件中,将包含绝对目录的图像名提取出来并写到txt文件的程序见上一篇博客
f = open("/home/shenruixue/image_test/binaries.txt")
line = f.readline()

while line:
    count_times += 1
    line = line[:-1]    # 除去末尾的换行符
    print line
    print '***********************************************************'
    image = caffe.io.load_image(line)
    

    # start time
    start = time.clock()

# 此处做一系列的处理
# 。。。。。。
# 。。。。。。
# 此处做一系列的处理

    # end time
    end = time.clock()
    sum_time += (end - start)

    # draw the image
    plt.imshow(image)

 
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
# 指定处理之后的图像的保存目录
    pre_savename = '/home/shenruixue/image_test_result/'
    print (str(count_times))
# 将从txt中读取的一行字符串(包含绝对路径的图像名)进行处理,只留存最后的图像名的字符串部分,去掉绝对路径部分的字符串
# 并将自己指定的目录与原始的图像名这两个字符串连接起来,然后进行保存
    savename = os.path.join(pre_savename, line[28:])
    print 'line is '
    print line
    print 'savename is '
    print savename
    savefig(savename)
    #io.imsave(savename, image)
# 继续读取下一行的图像名称
    line = f.readline()
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'


    plt.pause(1)
    plt.close()

print('Running time: %s s' %sum_time)
print('Deal with images: %s 张' %count_times)
print('mean time: %s s' %(sum_time / count_times))
  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值