Python 增强图像由空数组组成,而原始图像由带值的数组组成。为什么会这样?

Python 增强图像由空数组组成,而原始图像由带值的数组组成。为什么会这样?,python,opencv,image-processing,deep-learning,data-augmentation,Python,Opencv,Image Processing,Deep Learning,Data Augmentation,我将文件夹中所有.png图像的扩展名更改为.jpeg,并将其重命名为使用此代码 # Define directories INPUT = 'input dir' OUTPUT = 'output dir' for count, filename in enumerate(os.listdir(INPUT)): dst = "OTHERS_IMG_" + str(count) + ".jpeg" src = INPUT + filename dst = OUTPUT

我将文件夹中所有.png图像的扩展名更改为.jpeg,并将其重命名为使用此代码

# Define directories

INPUT = 'input dir'
OUTPUT = 'output dir'

for count, filename in enumerate(os.listdir(INPUT)):
    dst = "OTHERS_IMG_" + str(count) + ".jpeg"
    src = INPUT + filename 
    dst = OUTPUT + dst 
    os.rename(src, dst) 
image = cv2.imread('NORMAL/NORMAL_IMG_0.jpeg')
rotate = iaa.Affine(rotate=(-25, 25))
image_rotated = rotate.augment_images([image])[0]
cv2.imwrite("image.jpeg", image_rotated)
我成功地在一个单独的文件夹中获得了正确格式的图像。 正常\u IMG\u 0 正常图像1 正常图像2 . .

但是在使用OpenCV和imgauge扩充和读取图像后,我使用这段代码得到了像这样的空数组

# Define directories

INPUT = 'input dir'
OUTPUT = 'output dir'

for count, filename in enumerate(os.listdir(INPUT)):
    dst = "OTHERS_IMG_" + str(count) + ".jpeg"
    src = INPUT + filename 
    dst = OUTPUT + dst 
    os.rename(src, dst) 
image = cv2.imread('NORMAL/NORMAL_IMG_0.jpeg')
rotate = iaa.Affine(rotate=(-25, 25))
image_rotated = rotate.augment_images([image])[0]
cv2.imwrite("image.jpeg", image_rotated)
我知道了

[[[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 ...

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  ...
  [0 0 0]
  [0 0 0]
  [0 0 0]]]
原图是这样的,

[[[ 55  33  21]
  [ 47  25  13]
  [ 52  30  18]
  ...
  [ 27  18  28]
  [ 29  20  30]
  [ 29  21  28]]

 [[ 81  58  43]
  [ 77  54  39]
  [ 82  59  44]
  ...
  [ 25  18  25]
  [ 26  19  26]
  [ 26  19  26]]

 [[100  74  57]
  [100  74  57]
  [101  75  58]
  ...
  [ 24  18  23]
  [ 24  18  23]
  [ 24  18  23]]

 ...

 [[ 32  29  31]
  [ 30  25  27]
  [ 31  25  26]
  ...
  [ 61  37  31]
  [ 61  37  31]
  [ 61  37  31]]

 [[ 30  27  29]
  [ 29  26  28]
  [ 30  25  27]
  ...
  [ 49  28  26]
  [ 48  27  25]
  [ 48  27  25]]

 [[ 28  27  29]
  [ 29  26  28]
  [ 28  25  27]
  ...
  [ 40  22  21]
  [ 39  21  20]
  [ 39  21  20]]]

有人能帮我解释为什么会发生这种事吗?我还想增加我所有的图片。我没有注意到这一点,直到我尝试在目录中增加JPEG格式的图像。

与其更改扩展名,不如尝试将其作为JPEG格式并使用JPEG扩展名写入。JPEG不是PNG。您可以使用
cv2.imread
后跟
cv2.imwrite
,或imagemagick的转换实用程序。然后重试。

为什么要为PNG文件提供“.jpeg”扩展名?您知道更改扩展名不会更改文件中存储的图像格式,对吗?试图将PNG数据流解释为JPEG数据流只会让图像阅读器感到困惑。