python+cv2批量读取图片并保存

    import numpy as np
    import cv2
    import SimpleITK as sitk
    file_root = './'#当前文件夹下的所有图片
    file_list = os.listdir(file_root)
    save_out = "../****/"#保存图片的文件夹名称
    for img_name in file_list:
        if img_name.endswith('.tif'):
            img_path = file_root + img_name
            I = cv2.imread(img_path, -1)
            # image = sitk.ReadImage(".dcm")#读dcm
            # inputImg = np.squeeze(sitk.GetArrayFromImage(image))#读dcm
            M, N = I.shape
            out_name = img_name.split('.')[0]
            save_path = save_out + out_name + '.png'
            cv2.imwrite(save_path,"*****" )

你可能感兴趣的:(深度学习,opencv,python)