如何在CNN网络中处理不同大小的图像

时间:2019-04-04 17:34:39

标签: image-processing deep-learning computer-vision image-segmentation

我正在做图像以解决难题并确定完美的配对。 这是我的数据

solution.head()
id  pair
0   1   686
1   2   540
2   3   971
3   4   910
4   5   616

我的图像形状如下:

    png = []
    for image_path in glob.glob("training/training/*.png"):
        png.append(misc.imread(image_path))    

    im = np.asarray(png)

    print ('Importing done...', im.shape)

Importing done... (1000,)

array([array([[[247, 255, 102],
        [247, 255, 102],
        [247, 255, 102],
        ...,
        [247, 255, 102],
        [247, 255, 102],
        [247, 255, 102]],

       [[247, 255, 102],
        [247, 255, 102],
        [247, 255, 102],
        ...,
        [247, 255, 102],
        [247, 255, 102],
        [247, 255, 102]],

       [[247, 255, 102],
        [247, 255, 102],
        [247, 255, 102],
        ...,
        [247, 255, 102],
        [247, 255, 102],
        [247, 255, 102]],

       ...,

       [[247, 255, 102],
        [247, 255, 102],
        [247, 255, 102],
        ...,
        [247, 255, 102],
        [247, 255, 102],
        [247, 255, 102]],

       [[247, 255, 102],
        [247, 255, 102],
        [247, 255, 102],
        ...,
        [247, 255, 102],
        [247, 255, 102],
        [247, 255, 102]],

       [[247, 255, 102],
        [247, 255, 102],
        [247, 255, 102],
        ...,
        [247, 255, 102],
        [247, 255, 102],
        [247, 255, 102]]], dtype=uint8),
       array([[[165, 255, 102],
        [165, 255, 102],
        [165, 255, 102],
        ...,
        [165, 255, 102],
        [165, 255, 102],
        [165, 255, 102]],

       [[165, 255, 102],
        [165, 255, 102],
        [165, 255, 102],
        ...,
        [165, 255, 102],
        [165, 255, 102],
        [165, 255, 102]],

       [[165, 255, 102],
        [165, 255, 102],
        [165, 255, 102],
        ...,
        [165, 255, 102],
        [165, 255, 102],
        [165, 255, 102]],

       ...,

       [[165, 255, 102],
        [165, 255, 102],
        [165, 255, 102],
        ...,

我不知道如何找到理想的配对图像。我正在尝试调整它们的大小并转换为grey,但是它得到了错误。请帮助我找到可以成对放置的图像。 这是我的colab链接: https://colab.research.google.com/drive/1bCQUHrXNjdWX8-WKSq6LK01XpR4D52J_

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

   import numpy as np
    import cv2
    import os
    df=pd.read_csv(os.path.join(file_path,'solution.csv'))
    training_data = []
    IMG_SIZE = 100
    for img in  os.listdir('training/training') :  
      path = 'training/training/'+img
      id = img.split('.')[0]
      img = cv2.imread(path,1)
      img = cv2.resize(img, (IMG_SIZE,IMG_SIZE),3)     
      img = np.array(img)
      target = df['pair][int(id)]
      training_data.append([img ,target  ])