python 对图像进行裁剪或扩充并进行保存:
全部代码如下:
import os
import shutil
import cv2
import numpy as np
image_path = "H:\\5-NLSPN_ECCV20-master\\KITTI_DC\\depth_selection\\yueye_test_depth_completion_anonymous\\image\\"
save_path = "H:\\5-NLSPN_ECCV20-master\\KITTI_DC\\depth_selection\\test_depth_completion_anonymous\\image\\"
image_list = os.listdir(image_path)
for i in image_list:
img = cv2.imread(image_path+i, -1) #在cv2.imread参数中加入-1,表示不改变读取图像的类型直接读取
print(img.shape)
print(img.dtype)
#print(img)
# 对图像进行扩充
#j = 1200 - 928
#B = np.pad(img, ((j, 0), (0, 0)), 'constant', constant_values = (0.0,0.0))
#裁剪后的图像大小为:高 608 像素,宽 1920 像素。
j = 368
B = img[j:j+608, 0:1920]
print(B.shape)
print(B.dtype)
#print(B)
print("*"*20)
cv2.imwrite(save_path+i, B)