Third commit
This commit is contained in:
65
Modify_Pixels.py
Normal file
65
Modify_Pixels.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022-7-24 0024 16:42
|
||||
# @Author : Qing
|
||||
# @Email : derighoid@gmail.com
|
||||
# @File : Modify_Pixels.py
|
||||
# @Software: PyCharm
|
||||
|
||||
import os
|
||||
|
||||
# 导入库
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class modfifyImage():
|
||||
def __init__(self, filePath):
|
||||
self.filePath = filePath
|
||||
|
||||
# 图片读取
|
||||
def imageRead(self):
|
||||
if self.filePath == " ":
|
||||
print("Please full in the file path")
|
||||
else:
|
||||
face = Image.open(self.filePath)
|
||||
return face
|
||||
|
||||
# 图片转矩阵
|
||||
def imageMatrix(self):
|
||||
im = np.array(self.imageRead())
|
||||
return im
|
||||
|
||||
# 图片像素反转
|
||||
def pixInversion(self):
|
||||
im2 = 255 - self.imageMatrix()
|
||||
plt.figure()
|
||||
plt.imshow(im2)
|
||||
plt.show()
|
||||
return im2
|
||||
|
||||
# 显示图像三通道颜色
|
||||
def img_RGB(self):
|
||||
root="E:\\桌面\\Python_Picture_Analysis\\data\\" # 图片保存地址
|
||||
red = self.imageMatrix().copy()
|
||||
red[:, :, 1:3] = 0
|
||||
green = self.imageMatrix().copy()
|
||||
green[:, :, ::2] = 0
|
||||
blue = self.imageMatrix().copy()
|
||||
blue[:, :, :2] = 0
|
||||
x, y = plt.subplots(2, 2)
|
||||
x.set_size_inches(10, 10)
|
||||
y[0, 0].imshow(self.imageMatrix())
|
||||
y[0, 1].imshow(red)
|
||||
y[1, 0].imshow(green)
|
||||
y[1, 1].imshow(blue)
|
||||
# 图片保存
|
||||
Image.fromarray(np.uint8(red)).save(root + 'picture1' + '.jpg')
|
||||
Image.fromarray(np.uint8(blue)).save(root + 'picture2' + '.jpg')
|
||||
Image.fromarray(np.uint8(green)).save(root + 'picture3' + '.jpg')
|
||||
plt.show()
|
||||
return red,green,blue
|
||||
|
||||
# 获得该点的类型
|
||||
def get_imgType(self, x, y):
|
||||
return type(self.imageMatrix()[x, y])
|
Reference in New Issue
Block a user