Python保存图像的几种方式

记录读取和保存图像的几种方式

1、读取图片

1.1、使用cv2读取图片,注意:opencv打开路径中不能有中文!!!

img = cv2.imread(img_path+'/'+name)

1.2、使用rasterio读取遥感影像

img = rasterio.open(img_path+'/images/'+name).read()

1.3、使用Image读取图像

image = Image.open(os.path.join(img_path, name))

2、保存图片

2.1、使用cv2保存图片

cv2.imwrite(os.path.join(save_dir,name.replace('tif','png')),img)

2.2、使用numpy保存

img = rasterio.open(img_path+'/images/'+name).read()
img.save(save_path+'/'+filename +'.tif')

2.3、使用plt保存

image = Image.open(os.path.join(img_path, name))
plt.imshow(image)
plt.show()
plt.savefig('001.png')

参考:

https://blog.csdn.net/xzm961226xzm/article/details/120951317

https://blog.csdn.net/weixin_50727642/article/details/119743762

https://www.cnblogs.com/cgmcoding/p/14244735.html

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年9月6日
下一篇 2023年9月6日

相关推荐