欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

医学影像离线数据增强——水平翻转

程序员文章站 2022-06-15 12:47:26
医学影像数据增强——水平翻转from PIL import Imageimport numpy as npimport osimport os.pathimport cv2### 水平翻转 ===rootdir = r'1' # 指明被遍历的文件夹,取文件名1下面的全部图片for parent, dirnames, filenames in os.walk(rootdir):for filename in filenames:print('parent is :' + paren...
from PIL import Image
import numpy as np
import os
import os.path
import cv2
### 水平翻转 ===
rootdir = r'1'  # 指明被遍历的文件夹,取文件名1下面的全部图片
for parent, dirnames, filenames in os.walk(rootdir):
	for filename in filenames:
		print('parent is :' + parent)
		print('filename is :' + filename)
		currentPath = os.path.join(parent, filename)
		print('the fulll name of the file is :' + currentPath)
		im = Image.open(currentPath)
		out = im.transpose(Image.FLIP_LEFT_RIGHT)
		newname = r"1pre" + '/' + filename + "_sym.jpg" #保存为"1pre/原文件名__sym.jpg" 
		out.save(newname)

本文地址:https://blog.csdn.net/oneday0821/article/details/107643732