Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 通过整个目录将RGB值重新排列为GRB、GBR、BRG、BGR和RBG_Image_Python 2.7_Numpy_Cv2 - Fatal编程技术网

Image 通过整个目录将RGB值重新排列为GRB、GBR、BRG、BGR和RBG

Image 通过整个目录将RGB值重新排列为GRB、GBR、BRG、BGR和RBG,image,python-2.7,numpy,cv2,Image,Python 2.7,Numpy,Cv2,我有CNN的图片目录。我希望能够以不同的顺序重新排列每个波段,以帮助更好地训练我的模型,使其能够识别我的对象。到目前为止,我有一些与cv2有关的代码。这是分离乐队,但我有麻烦重新安排乐队 import cv2 import numpy img = cv2.imread("IMG_4540.jpg") g,b,r = cv2.split(img) cv2.imwrite('green_channel.jpg', g) 如果可能的话,我想从一张单张图像中获得6张具有不同波段组合的单独图像。您可以

我有CNN的图片目录。我希望能够以不同的顺序重新排列每个波段,以帮助更好地训练我的模型,使其能够识别我的对象。到目前为止,我有一些与cv2有关的代码。这是分离乐队,但我有麻烦重新安排乐队

import cv2
import numpy

img = cv2.imread("IMG_4540.jpg")
g,b,r = cv2.split(img)
cv2.imwrite('green_channel.jpg', g)

如果可能的话,我想从一张单张图像中获得6张具有不同波段组合的单独图像。

您可以使用numpy的索引功能形成所有重新排序

import numpy as np 
from itertools import permutations
# first generate all sets of rearrangements you'd like to make.. 
orderings = [p for p in permutations(np.arange(3)) if p!=(0,1,2)]
# [(0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
# rbg, brg, and so on. 

# then reorder along axis=-1 using these. (0,1,2) --> (0,2,1) and so on. 
for order in orderings:
    reordered = im[...,order]
    # then save each an appropriate filename 
    cv2.imsave('filename.jpg', reordered)
del reordered, order