pytorch 预处理图片--Resize

pytorch 预处理图片–Resize


文章目录

  • pytorch 预处理图片--Resize


def resizeImg():
      for x in range(1 ,100):
       # 读取图片
        img = cv2.imread("E:\\{}.png".format(str(x)))
        img = Image.fromarray(img)
        img = F.resize(img, (512,512))
        img=np.array(img)

        #img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        cv2.imwrite("E:\\{}.png".format(str(x)), img)
        plt.imshow(img ,cmap='gray')
        plt.show()
resizeImg()

注意open-cv的读取图像格式为numpy,而pytorch中的resize方法需要Image格式,因此需要转换

你可能感兴趣的:(计算机视觉与深度学习,pytorch,深度学习,计算机视觉)