用零填充3通道图像

时间:2019-03-28 20:27:50

标签: python numpy

我正在从多个文件夹中读取图像,然后填充每个文件夹

具有预定义数字零的图像,以便所有文件夹都将

具有相同数量的图像。每个图像的形状为(127,227,3),

 for file in allfiles:
            files.append(file) if ('.jpg' in file) else None
            samples = np.empty((127, 227,3))

    for file in files:
            img = cv2.imread(os.path.join(pth_upd,file))
            img=img.astype(np.float32)
            samples = np.append(samples, img, axis=0)
    print(samples.shape)

   pad_size=half_len-len(samples)       

   samples = np.pad(samples,(( pad_size,0),(0,0),(0,0)),mode='constant', constant_values=0) 

   f_name=format(folder)

  full_path ='C:/Users/sarmad/Documents/dev_test_of' + f_name

我收到此错误:

ValueError Traceback (most recent call last)
  <ipython-input-14-da54323f81ce> in <module>
 58     pad_size=half_len-len(samples)
 59 
  samples = np.pad(samples,(( pad_size,0),(0,0), 
   (0,0)),mode='constant', constant_values=0)
   61 
   62     f_name=format(folder)

 ValueError: ((-44812, 0), (0, 0), (0, 0)) cannot contain negative values.

0 个答案:

没有答案