资源简介
输入原始图片所在文件夹,原始图片标签,输出增强后的图片文件夹名及输出标签名,运行即可。
代码片段和文件信息
from PIL import Image
from PIL import ImageEnhance
import os
import cv2
import numpy as np
OriImgsPath = “taxiCodeNumber945“
OriLabelPath = “taxiCodeNumber945.txt“
OutputAugData = “AugtaxiCodeNumber945“
OutputAugLabel = “AugtaxiCodeNumber945.txt“
def colorEnhancement(img_name):#颜色增强
image = Image.open(os.path.join(OriImgsPath img_name))
# image = imgInfo
enh_col = ImageEnhance.Color(image)
color = 0.5
image_colored = enh_col.enhance(color)
return image_colored
def contrastEnhancement(img_name): # 对比度增强
image = Image.open(os.path.join(OriImgsPath img_name))
enh_con = ImageEnhance.Contrast(image)
contrast = 1.5
image_contrasted = enh_con.enhance(contrast)
return image_contrasted
def rotation(image angle):
(h w) = image.shape[:2]
(cX cY) = (w // 2 h // 2)
M = cv2.getRotationMatrix2D((cX cY) -angle 1.0)
cos = np.abs(M[0 0])
sin = np.abs(M[0 1])
nW = int((h * sin) + (w * cos))
nH = int((h * cos) + (w * sin))
M[0 2] += (nW / 2) - cX
M[1 2] += (nH / 2) - cY
return cv2.warpAffine(image M (nW nH) borderValue=(255 255 255))
def process(defNameimgInfoAugLabel):
if defName == “colorEnhancement“:
enhanImg = colorEnhancement(imgname) ##颜色增强后的图片信息
tail = “ColorEnhan.jpg“
img = enhanImg
if defName == “contrastEnhancement“:
enhanImg = contrastEnhancement(imgname) ##颜色增强后的图片信息
tail = “ContrastEnhan.jpg“
img = enhanImg
if defName == “rotationRight“:
enhanImg = r
评论
共有 条评论