Several ways to record, read and save images
1. Read pictures
1.1. Use to cv2
read pictures, note: there can be no Chinese in the opencv opening path! ! !
img = cv2.imread(img_path+'/'+name)
1.2. Use rasterio
to read remote sensing images
img = rasterio.open(img_path+'/images/'+name).read()
1.3. Use Image
to read images
image = Image.open(os.path.join(img_path, name))
2. Save the picture
2.1. Use to cv2
save pictures
cv2.imwrite(os.path.join(save_dir,name.replace('tif','png')),img)
2.2, use numpy to save
img = rasterio.open(img_path+'/images/'+name).read()
img.save(save_path+'/'+filename +'.tif')
2.3. Use plt to save
image = Image.open(os.path.join(img_path, name))
plt.imshow(image)
plt.show()
plt.savefig('001.png')
reference:
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