def _prepare_image(I):
assert isinstance(I, np.ndarray), 'plugin error, should pass numpy array here'
assert I.ndim == 2 or I.ndim == 3 or I.ndim == 4
if I.ndim == 4: # NCHW
if I.shape[1] == 1: # N1HW
I = np.concatenate((I, I, I), 1) # N3HW
assert I.shape[1] == 3
I = make_grid(I) # 3xHxW
if I.ndim == 3 and I.shape[0] == 1: # 1xHxW
I = np.concatenate((I, I, I), 0) # 3xHxW
if I.ndim == 2: # HxW
I = np.expand_dims(I, 0) # 1xHxW
I = np.concatenate((I, I, I), 0) # 3xHxW
I = I.transpose(1, 2, 0)
return I
评论列表
文章目录