def plotImages(images_arr):
fig, axes = plt.subplots(1, 10, figsize=(20,20))
axes = axes.flatten()
for img, ax in zip( images_arr, axes):
ax.imshow(img)
ax.axis("off")
plt.tight_layout()
plt.show()
data_augmentation = True
datagen = ImageDataGenerator(
rotation_range=10, #randomly rotate images in the range(degrees, 0 to 180)
width_shift_range=0.2, #randomly shift images horizontally (fraction of total width)
height_shift_range=0.2, #randomly shift images vertically (fraction of total height)
horizontal_flip=True, #randomly flip images
shear_range=0.15,
)
chosen_image= random.choice(os.listdir(r"C:\Users\COSH.spyder-py3\train"))
image_path=r"C:\Users\COSH.spyder-py3\train/"+chosen_image
assert os.path.isfile(image_path)
image=np.expand_dims(plt.imread(image_path), 0)
print(plt.imshow(image[0]))
aug_iter=datagen.flow(image)
aug_images=[next(aug_iter)[0].astype('float32')for i in range(10)]
for i in range(10):
aug_images[i] = aug_images[i]*255
cv2.imwrite(r"C:\Users\COSH.spyder-py3\train\aug/test"+str(i)+".png",aug_images[i])
想請問各位大大 我存的圖片都會變GRB的顏色
要如何改顏色通道才能變RGB 再麻煩各位大大高手解惑
感謝感謝
你用 plt 讀圖
可是用 opencv 存圖
因為 opencv 是 BGR 的,不是 RGB
可以改用 opencv 讀圖,或是轉通道
RGB -> BGR
img_bgr = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
BGR->RGB
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)