• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python将8位的图片转为24位的图片实现方法

python 搞代码 4年前 (2022-01-08) 40次浏览 已收录 0个评论

这篇文章主要介绍了Python将8位的图片转为24位的图片的实现代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

用的pytorch来训练deeplabv3+

在做deeplabv3+的过程中,我的训练图片是8位的,如下图:

8位的:

24位的:

这样虽然在训练过程中能够正常训练。但是在评估过程中会出错,所以决定将训练图片转成24位图,重新训练。最后结果也表明了,只要将训练图片转成24位后之后的评估可视化等都没有问题。

由于RGB的图片就为24位,则简单将图片利用PIL转为RGB格式即可

 #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Tue Oct 24 10:47:36 2018 @author: yxh """ import numpy as np from PIL import Image import matplotlib.pyplot as plt import os import sys import shutil path='/home/yxh/caffe/examples/fcn/<strong style="color:transparent">来源gaodai#ma#com搞@@代~&码网</strong>IMAGES/IMAGES/' newpath='/home/yxh/caffe/examples/fcn/IMAGES/output/' def turnto24(path): fileList = [] files = os.listdir(path) i=0 for f in files: imgpath = path + '/' +f img=Image.open(f).convert('RGB') dirpath = newpath file_name, file_extend = os.path.splitext(f) dst = os.path.join(os.path.abspath(dirpath), file_name + '.jpg-600') img.save(dst) turnto24(path)

总结

以上就是Python将8位的图片转为24位的图片实现方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python将8位的图片转为24位的图片实现方法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址