图像识别数据集处理(一)

图像识别数据集处理(一)

  • 单通道转三通道
  • 缩放到合适大小

单通道转三通道

import cv2
import os
def rddc(directory_name):
    for filename in os.listdir(directory_name):
        img = cv2.imread(directory_name + "/" + filename)
        cv2.waitKey(0)
        cv2.imwrite("C:/Users/Administrator/Desktop/4" + "/" + filename, img)
rddc("C:/Users/Administrator/Desktop/D")

缩放到合适大小

import PIL.Image as Image
import os
import sys
import numpy as np
import matplotlib.pyplot as plt

//图片存放地址
folder = r'C:/Users/Administrator/Desktop/1'
//图片保存地址
outfile = r'C:/Users/Administrator/Desktop/a'
path = os.listdir(folder)
for parent, dirnames, filenames in os.walk(folder):
    for filename in filenames:
        each_bmp = os.path.join(parent, filename)
        img = Image.open(each_bmp)
        out = img.resize((224, 224), Image.ANTIALIAS)
        newname = outfile + '\\' + filename[:-4] + "0.jpg"
        out.save(newname)

你可能感兴趣的:(图像识别数据集处理(一))