1. torch tensor 格式
from torchvision.utils import save_image
img_train_list = torch.cat([image_s,image_r,im_G[0],fake_A,mask_s[:, :, 0],mask_r[:, :, 0]])
result_path = self.save_path_dir+'/image'
if not os.path.exists(result_path):
os.makedirs(result_path)
save_image(self.de_norm(img_train_list),os.path.join(result_path,f'{self.e}_{self.i}_fake.jpg'))
2. Image 格式
图片维Image格式
w = image_real.width
h = image_real.height
new_img = Image.new('RGB',(w*4,h))
loc = [ (i) * w for i in range(4)]
new_img.paste(source,(loc[0],0))
new_img.paste(reference,(loc[1],0))
new_img.paste(image_real,(loc[2],0))
new_img.paste(image_fake,(loc[3],0))
new_img.save(save_path+'{}_{}_source.jpg'.format(source_path.name.split('.')[0],reference_path.name.split('.')[0]))
3. img图片 格式
import cv2
from pylab import *
img1 = cv2.imread('logo.jpg',cv2.IMREAD_COLOR)
img2 = cv2.imread('logo.jpg',cv2.IMREAD_GRAYSCALE)
img3 = cv2.imread('logo.jpg',cv2.IMREAD_UNCHANGED)
img4 = cv2.imread('logo.jpg')
htitch= np.hstack((img1, img3,img4)) # 横向排列
vtitch = np.vstack((img1, img3)) # 纵向排列
cv2.imshow("test1",htitch)
cv2.imshow("test2",vtitch)
cv2.waitKey(0)
cv2.destroyAllWindows()