Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 processing 我想将每个图像的大小调整为(32128,1),并将其规格化以将其提供给我的CNN_Image Processing - Fatal编程技术网

Image processing 我想将每个图像的大小调整为(32128,1),并将其规格化以将其提供给我的CNN

Image processing 我想将每个图像的大小调整为(32128,1),并将其规格化以将其提供给我的CNN,image-processing,Image Processing,这是我现有的代码,它给了我一个错误,没有返回4D输入。这是代码。有什么方法可以更改它吗 img=cv2.cvtColor(cv2.imread(os.path.join(root,f_name)),cv2.COLOR\u bgr2灰色) #转换形状的每个图像(32、128、1) w、 h=img.shape 如果h>128或w>32: 持续 如果w

这是我现有的代码,它给了我一个错误,没有返回4D输入。这是代码。有什么方法可以更改它吗

img=cv2.cvtColor(cv2.imread(os.path.join(root,f_name)),cv2.COLOR\u bgr2灰色)
#转换形状的每个图像(32、128、1)
w、 h=img.shape
如果h>128或w>32:
持续
如果w<32:
加上0=np.one((32-w,h))*255
img=np.连接((img,加零))
如果h<128:
加0=np.one((32128-h))*255
img=np.连接((img,加零),轴=1)
img=np.展开尺寸(img,轴=2)
#标准化每个图像
img=img/255。

我希望能够通过使用填充来生成大小为(128,32)的每个图像,将图像尺寸扩展为(128,32,1),使其与体系结构的输入形状兼容。通过将图像像素值除以255来规范化图像像素值。我得到的错误可能是“预期输入为4维,而不是形状数组”(0,1)“将边框添加到我的图像中可以解决问题吗?
    img = cv2.cvtColor(cv2.imread(os.path.join(root, f_name)), cv2.COLOR_BGR2GRAY)   

    # convert each image of shape (32, 128, 1)
    w, h = img.shape
    if h > 128 or w > 32:
        continue
    if w < 32:
        add_zeros = np.ones((32-w, h))*255
        img = np.concatenate((img, add_zeros))

    if h < 128:
        add_zeros = np.ones((32, 128-h))*255
        img = np.concatenate((img, add_zeros), axis=1)
    img = np.expand_dims(img , axis = 2)

    # Normalize each image
    img = img/255.