2022-07-26 21:27:11 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
# @Time : 2022-7-25 0025 10:46
|
|
|
|
|
# @Author : Qing
|
|
|
|
|
# @Email : derighoid@gmail.com
|
|
|
|
|
# @File : Orientation_Modification.py
|
|
|
|
|
# @Software: PyCharm
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
# 导入库
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
import numpy as np
|
|
|
|
|
from PIL import Image
|
2022-07-27 20:41:38 +08:00
|
|
|
|
#定义 图片方向改变类
|
2022-07-26 21:27:11 +08:00
|
|
|
|
class directionChanges():
|
|
|
|
|
def __init__(self, filePath):
|
|
|
|
|
self.filePath = filePath
|
|
|
|
|
|
|
|
|
|
# 图片读取
|
|
|
|
|
def imageRead(self):
|
|
|
|
|
face3 = Image.open(self.filePath)
|
|
|
|
|
return face3
|
|
|
|
|
|
|
|
|
|
# 图片上矩阵化
|
|
|
|
|
def imageMatrix(self):
|
|
|
|
|
im3 = np.array(self.imageRead())
|
|
|
|
|
return im3
|
|
|
|
|
|
|
|
|
|
def imageRepetition(self):
|
|
|
|
|
# 图像重复
|
|
|
|
|
# 先水平方向两次,再垂直方向3次
|
|
|
|
|
plt1 = np.concatenate((self.imageMatrix(), self.imageMatrix()), axis=1)
|
|
|
|
|
plt2 = np.concatenate((plt1, plt1, plt1), axis=0)
|
|
|
|
|
plt.imshow(plt2)
|
|
|
|
|
plt.show()
|
|
|
|
|
# # 先垂直方向转3次,再水平方向转4次
|
|
|
|
|
plt3 = np.concatenate((self.imageMatrix(), self.imageMatrix(), self.imageMatrix()), axis=0)
|
|
|
|
|
plt4 = np.concatenate((plt3, plt3, plt3, plt3), axis=1)
|
|
|
|
|
plt.imshow(plt4)
|
|
|
|
|
plt.show()
|
|
|
|
|
return plt2
|
|
|
|
|
|
|
|
|
|
# 图像水平镜面对称
|
|
|
|
|
def mirrorSymmetry(self):
|
2022-07-28 21:35:42 +08:00
|
|
|
|
# plt6 = self.imageMatrix()[::-1]
|
|
|
|
|
plt6=self.imageRead().transpose(Image.ROTATE_180)
|
2022-07-26 21:27:11 +08:00
|
|
|
|
plt.imshow(plt6)
|
|
|
|
|
plt.show()
|
|
|
|
|
return plt6
|
|
|
|
|
# 垂直对称(右旋转)
|
|
|
|
|
def verticalSummetry_right(self):
|
2022-07-28 21:35:42 +08:00
|
|
|
|
|
|
|
|
|
plt5=self.imageRead().transpose(Image.ROTATE_270)
|
|
|
|
|
|
|
|
|
|
plt.imshow(plt5)
|
2022-07-26 21:27:11 +08:00
|
|
|
|
plt.show()
|
|
|
|
|
return plt5
|
|
|
|
|
# 垂直镜面(左旋转)
|
|
|
|
|
def verticalSummetry_lift(self):
|
2022-07-28 21:35:42 +08:00
|
|
|
|
plt7 = self.imageRead().transpose(Image.ROTATE_90)
|
|
|
|
|
plt.imshow(plt7)
|
2022-07-26 21:27:11 +08:00
|
|
|
|
plt.show()
|
|
|
|
|
return plt7
|
|
|
|
|
# 保存图片
|
|
|
|
|
def img_Save(self):
|
2022-07-27 20:41:38 +08:00
|
|
|
|
root = "E:\\桌面\\Python_Picture_Analysis\\data\\" # 图片保存地址
|
|
|
|
|
if not os.path.exists(root): # 判断是否已经存在该文件
|
|
|
|
|
os.mkdir(root) #没有就创建
|
2022-07-26 21:27:11 +08:00
|
|
|
|
else:
|
2022-07-27 20:41:38 +08:00
|
|
|
|
#图片保存
|
2022-07-26 21:27:11 +08:00
|
|
|
|
Image.fromarray(np.uint8(self.imageRepetition())).save(root+'picture4'+'.jpg')
|
|
|
|
|
Image.fromarray(np.uint8(self.mirrorSymmetry())).save(root+'picture5'+'.jpg')
|
|
|
|
|
Image.fromarray(np.uint8(self.verticalSummetry_right())).save(root+'picture6'+'.jpg')
|
|
|
|
|
Image.fromarray(np.uint8(self.verticalSummetry_lift())).save(root+'picture7'+'.jpg')
|
|
|
|
|
|
|
|
|
|
|