python 图像的旋转+翻转操作+PIL读取图像 +对比度,锐度,色度,亮度增强

#coding=utf-8
import cv2
import numpy as np
from numpy import *
#**************旋转操作***************
img=cv2.imread('21_manual1.png')
rows,cols,channel=img.shape
for j in range(0, 71):
    M=cv2.getRotationMatrix2D(((cols-1)/2.0,(rows-1)/2.0),((j+1)*5),1)
    #cv2.getRotationMarix2D(point2f center,double angle,double scale)
    #参数分别为:旋转中心,旋转角度,图像缩放因子
    dst=cv2.warpAffine(img,M,(cols,rows))
    #仿射变换其三个参数分别为:输入图像,变换矩阵,输出图像大小

    #print(j,(j+1)*5)
    #保存图像
    cv2.imwrite(str((j+1)*5)+'_21_manual1.png',dst)

#**************旋转操作***************




以上代码为每隔5度旋转一次,一共是旋转72次,一共360度(不含)....

2. 图像的水平和垂直翻转

#coding=utf-8
from PIL import Image
import os
import os.path
#图片的水平翻转

#创建文件夹
#os.mkdir(r'./38f')
#删除文件
#os.remove('./38/rotation.py')
#os.remove('./38/rotation.py~')

rootdir = r'/home/qxq/Desktop/eyedata/train/label/21/'  # 指明被遍历的文件夹
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)
        newname1 = r"/home/qxq/Desktop/eyedata/train/label/21f/" + 'L_' + filename
        out.save(newname1)
	out1 = im.transpose(Image.FLIP_TOP_BOTTOM)
	newname2 = r"/home/qxq/Desktop/eyedata/train/label/21f/" + 't_' + filename
        out1.save(newname2)

3.使用PIL读取保存图像, 对比度,锐度,色度,亮度增强

# coding=utf-8
from PIL import Image
from PIL import ImageEnhance

# 读取图像
image = Image.open('timg.jpg')
# image.show()

# 增强亮度
enh_bri = ImageEnhance.Brightness(image)
brightness = 1.5
image_brightened = enh_bri.enhance(brightness)
# image_brightened.show()
image_brightened.save("Bri_test.jpg")  # 保存

# 色度增强
enh_col = ImageEnhance.Color(image)
color = 1.5
image_colored = enh_col.enhance(color)
# image_colored.show()
image_colored.save("color_test.jpg")

# 对比度增强
enh_con = ImageEnhance.Contrast(image)
contrast = 1.5
image_contrasted = enh_con.enhance(contrast)
# image_contrasted.show()
image_contrasted.save("contrast_test.jpg")

# 锐度增强
enh_sha = ImageEnhance.Sharpness(image)
sharpness = 3.0
image_sharped = enh_sha.enhance(sharpness)
# image_sharped.show()
image_sharped.save("sharpness_test.jpg")

 

  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值