의미 분할 데이터 집합 이미지 강화 코드
9490 단어 어의 분할
# coding=utf-8
import os
from PIL import Image
from skimage import transform
from numpy import *
import numpy as np
import cv2
#
#
# 180
def Enhancement(file_path):
for fileName in os.listdir(file_path):
print(fileName)
im = Image.open(file_path + "\\"+fileName)
#
mirror_lr = im.transpose(Image.FLIP_LEFT_RIGHT)
mirror_lr.save(file_path + "\\" + 'mirror_lr' + fileName)
#
mirror_tb = im.transpose(Image.FLIP_TOP_BOTTOM)
mirror_tb.save(file_path + "\\" + 'mirror_tb' + fileName)
# 180
rotate = im.transpose(Image.ROTATE_180)
rotate.save(file_path + "\\" + 'rotate' + fileName)
# : cv2.imread
def resize(file_path):
for fileName in os.listdir(file_path):
img = cv2.imread(file_path+"\\"+fileName)
dst = cv2.resize(img, (256, 256), interpolation=cv2.INTER_CUBIC)
cv2.imwrite(file_path + "\\" + fileName, dst)
def cropped(file_path):
for fileName in os.listdir(file_path):
img = cv2.imread(file_path + "\\" + fileName)
# [y0:y1, x0:x1]
cropped = img[8:248, 0:200]
cv2.imwrite(file_path + "\\" + fileName, cropped)
def gray(file_path):
for fileName in os.listdir(file_path):
img = Image.open(file_path + "\\" + fileName)
rgb = img.convert("L")
rgb.save(file_path + "\\" + 'gray' + fileName)
def main():
file_path = './test'
#resize(file_path)
Enhancement(file_path)
#gray(file_path)
#file_list = os.listdir(file_path)
# deleteImages(file_path, file_list)
#cropped(file_path)
if __name__ == '__main__':
main()