def horizontal_flip(imgs, labels):
if imgs.ndim != 2:
print("Image dimension must be 2")
raise Exception
if imgs.shape[0] != labels.shape[0]:
print("Images num and labels num must be equal")
raise Exception
#flip the img horizontally
imgs = imgs.reshape(-1, 96, 96)
imgs = np.flip(imgs, axis=2)
imgs = imgs.reshape(-1, 96*96)
#when flip the image horizontally, img's ypos does not change but xpos reflect on img's center pos
result = np.copy(labels)
for idx in range(labels.shape[0]):
result[idx][::2] = 96 - result[idx][::2]
return imgs, labels
评论列表
文章目录