Compare commits

...

6 Commits
master ... main

Author SHA1 Message Date
lan daiqing
187aabe4f0 Upload New File 2022-07-28 01:03:32 +00:00
lan daiqing
298633d90f Delete .gitlab-ci.yml 2022-07-28 01:03:14 +00:00
lan daiqing
0157fe648c Upload New File 2022-07-27 13:15:05 +00:00
lan daiqing
160f8e1e21 Delete .gitlab-ci.yml 2022-07-27 13:14:53 +00:00
lan daiqing
d14e398739 Upload New File 2022-07-27 13:06:20 +00:00
lan daiqing
3d78b6edb3 Fourth commit 2022-07-27 20:41:38 +08:00
12 changed files with 630 additions and 105 deletions

7
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,7 @@
stages:
- test
sonarqube_master_job:
stage: test
script:
- export ENCRYPT_KEY=`echo $CI_PROJECT_URL.git | md5sum | cut -d' ' -f1`
- /opt/sonar-scanner-4.7.0/bin/sonar-scanner -Dsonar.sources=. -Dsonar.projectKey=p$ENCRYPT_KEY

View File

@ -5,46 +5,55 @@
# @File : Blue_noise_sampling.py
# @Software: PyCharm
'''
计算新图形放大后或缩小后的坐标点像素值对应于原图像中哪一个像素点填充的
src是原图dst是新图原来的图像宽度/高度除以新图像的宽度/高度可以得到缩放比例假如是缩小图片括号内的数字小于1放大则大于1相当于系数再乘以新图片的宽度/高度就实现了缩放
'''
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import math
# # 最近邻插值算法
# # dstH为新图的高;dstW为新图的宽
# def blueNoiseSampl(img, dstH, dstW):
# scrH, scrW, t = img.shape # src原图的长宽
# retimg = np.zeros((dstH, dstW, 3), dtype=np.uint8)
# for i in range(dstH - 1):
# for j in range(dstW - 1):
# scrx = round(i * (scrH / dstH))
# scry = round(j * (scrW / dstW))
# retimg[i, j] = img[scrx, scry]
#
# return retimg
#
#
# im_path = './data/th.png'
# image = np.array(Image.open(im_path))
#
# plt.figure(figsize=(16, 8))
#
# plt.subplot(1, 2, 1)
# plt.imshow(image)
#
# image1 = blueNoiseSampl(image, image.shape[0] * 2, image.shape[1] * 2)
# # 从array转换成image
# image1 = Image.fromarray(image1.astype('uint8')).convert('RGB')
# image1.save('./data/picture13.png')
# plt.subplot(1, 2, 2)
# plt.imshow(image1)
# plt.show()
from PIL import Image
'''
srcX=newX*(srcW/newW)
srcY=newY*(srcH/newH)
src是原图dst是新图原来的图像宽度/高度除以新图像的宽度/高度可以得到缩放比例
假如是缩小图片括号内的数字小于1放大则大于1相当于系数再乘以新图片的宽度/高度就实现了缩放
'''
def blueNoiseSampl(img, newH, newW):
'''
:param img: 图片
:param newH: 新图的高
:param newW: 新图的宽
:return: 新图
'''
scrH, scrW, t = img.shape # 原图的长宽
retimg = np.zeros((newH, newW, 3), dtype=np.uint8) # 生成 newH* newW *3 的零矩阵
for i in range(newH - 1):
for j in range(newW - 1):
scrx = round(i * (scrH / newH)) # round对其四舍五入
scry = round(j * (scrW / newW))
retimg[i, j] = img[scrx, scry] # new image
return retimg
# 图片展示函数
def showImage(picPath):
'''
:param picPath: 图片地址
:return: 样图
'''
# 获取图片矩阵
image = np.array(Image.open(picPath))
# 设置画布
plt.figure(figsize=(16, 8))
# 合并
plt.subplot(121)
plt.imshow(image)
# 调用采样函数
image1 = blueNoiseSampl(image, image.shape[0] * 2, image.shape[1] * 2)
# 图片保存
Image.fromarray(np.uint8(image1)).save("./data/picture13.png")
plt.subplot(122)
plt.imshow(image1)
plt.show()
return image1

357
GUI.py
View File

@ -1,12 +1,363 @@
# -*- coding: utf-8 -*-
# @Time : 2022-7-25 0025 15:03
# @Time : 2022-7-27 0027 15:21
# @Author : Qing
# @Email : derighoid@gmail.com
# @File : GUI.py
# @Software: PyCharm
import os
import tkinter
import tkinter.filedialog
import tkinter.messagebox # 弹窗库
# git checkout -b "main"
import PIL
import numpy as np
import requests
from PIL import Image, ImageTk
import tkinter
root = tkinter.Tk()
root.title = 'new'
root.geometry('640x500')
# 文件选择
def choose_fiel():
selectFileName = tkinter.filedialog.askopenfilename(title='选择文件') # 选择文件
e.set(selectFileName)
label1 = tkinter.Label(root, text="文件路径:")
label1.place(x=40, y=0)
e = tkinter.StringVar()
e_entry = tkinter.Entry(root, width=60, textvariable=e)
e_entry.place(x=100, y=0)
lable2 = tkinter.Label(root, text="URL:")
lable2.place(x=40, y=30)
# 设置输入框
entry = tkinter.Entry(root, width=60)
entry.insert(0,
"https://tse2-mm.cn.bing.net/th/id/OIP-C.fT7uKiT7V7YO2PPINFeOdQHaJ4?w=186&h=248&c=7&r=0&o=5&dpr=1.25&pid=1.7")
entry.place(x=100, y=30)
# 选择文件按钮
submit_button = tkinter.Button(root, text="选择文件", command=choose_fiel)
submit_button.place(x=520, y=0)
# 爬取函数
def pictureCrawl(url):
# 文件保存地址
root = "E://桌面//Python_Picture_Analysis//data//"
# 文件的保存地址以及格式
path = root + url.split('/')[-3] + '.png'
try:
if not os.path.exists(root): # 判断是否存在文件夹
os.mkdir(root)
if not os.path.exists(path): # 判断是否存在该文件
r = requests.get(url)
# 文件写入
with open(path, 'wb') as fp:
fp.write(r.content)
print("OK")
else:
print("File already exists")
except:
print("Crawl successful")
# 爬取按钮
imgCrawling_button = tkinter.Button(root, text="开始爬取", command=lambda: pictureCrawl(entry.get()))
imgCrawling_button.place(x=520, y=30)
# 图片变灰
def grayPic(e_entry):
img = Image.open(e_entry.get())
img = img.convert('L')
showPic = ImageTk.PhotoImage(img)
img = tkinter.Label(image=showPic)
img.image = showPic
img.place(x=350, y=150)
# 灰色图按钮
grayPic_button = tkinter.Button(root, text="灰色图", command=lambda: grayPic(e_entry))
grayPic_button.place(x=110, y=75)
# 图像水平镜面对称
def mirrorSymmetry(e_entry):
img = Image.open(e_entry.get())
img = np.asarray(img)
img1 = np.flipud(img)
img2 = Image.fromarray(img1)
pic = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=pic)
img.image = pic
img.place(x=350, y=150)
# 镜面按钮
mirrorSymmetry_button = tkinter.Button(root, text="镜面对称", command=lambda: mirrorSymmetry(e_entry))
mirrorSymmetry_button.place(x=170, y=75)
# 右旋转
def verticalSummetry_right(e_tery):
img = Image.open(e_entry.get())
img = np.array(img)
img1 = img.swapaxes(1, 0)
img2 = img1[:, ::-1]
img2 = Image.fromarray(img2)
pic = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=pic)
img.image = pic
img.place(x=300, y=150)
# 右旋转按钮
verticalSummetry_right_button = tkinter.Button(root, text="右旋转", command=lambda: verticalSummetry_right(e_entry))
verticalSummetry_right_button.place(x=240, y=75)
# 左旋转
def verticalSummetry_lift(e_entry):
img = Image.open(e_entry.get())
img = np.array(img)
img1 = img.transpose(1, 0, 2) # x,y轴转置
img2 = img1[::-1]
img2 = Image.fromarray(img2)
pic = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=pic)
img.image = pic
img.place(x=300, y=150)
# 左旋转按钮
verticalSummetry_lift_button = tkinter.Button(root, text="左旋转", command=lambda: verticalSummetry_lift(e_entry))
verticalSummetry_lift_button.place(x=300, y=75)
# 像素反转函数
def pixInversion(e_entry):
img = Image.open(e_entry.get())
img2 = 255 - np.array(img)
img2 = Image.fromarray(img2)
img3 = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 像素反转
pixInversion_button = tkinter.Button(root, text="像素反转", command=lambda: pixInversion(e_entry))
pixInversion_button.place(x=360, y=75)
def redImage(e_entry):
img = Image.open(e_entry.get())
img = np.array(img)
img[:, :, 1:3] = 0
img2 = Image.fromarray(img)
img3 = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 红色图按钮
red_button = tkinter.Button(root, text="红色图", command=lambda: redImage(e_entry))
red_button.place(x=430, y=75)
def blueImage(e_entry):
img = Image.open(e_entry.get())
img = np.array(img)
img[:, :, :2] = 0
img2 = Image.fromarray(img)
img3 = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 蓝色图按钮
blue_button = tkinter.Button(root, text="蓝色图", command=lambda: blueImage(e_entry))
blue_button.place(x=490, y=75)
#绿色图函数
def greenImage(e_entry):
img = Image.open(e_entry.get())
img = np.array(img)
img[:, :, ::2] = 0
img2 = Image.fromarray(img)
img3 = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 绿色按钮
green_button = tkinter.Button(root, text='绿色图', command=lambda: greenImage(e_entry))
green_button.place(x=550, y=75)
# 图像混合函数
def imageMix(e_entry):
img1 = Image.open("./data/picture.png")
img2 = Image.open(e_entry.get())
img3 = PIL.Image.blend(img1, img2, 0.5)
img4 = ImageTk.PhotoImage(img3)
img = tkinter.Label(image=img4)
img.image = img4
img.place(x=350, y=150)
# 图像混合按钮
imageMix_button = tkinter.Button(root, text="图像混合", command=lambda: imageMix(e_entry))
imageMix_button.place(x=40, y=105)
# 图像剪切函数
def imageCut(e_entry):
img1 = Image.open(e_entry.get())
part = (20, 10, 190, 190)
img2 = img1.crop(part)
img3 = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 剪切按钮
cut_button = tkinter.Button(root, text="剪 切", command=lambda: imageCut(e_entry))
cut_button.place(x=110, y=105)
# 部分替换函数
def imgReplace(e_entry):
part = (10, 50, 250, 250)
img1 = Image.open(e_entry.get())
img2 = Image.open("./data/picture.png")
img3 = img2.crop(part)
img1.paste(img3, (10, 50, 250, 250))
img4 = ImageTk.PhotoImage(img1)
img = tkinter.Label(image=img4)
img.image = img4
img.place(x=350, y=150)
# 部分替换按钮
imgReplace_button = tkinter.Button(root, text="部分替换", command=lambda: imgReplace(e_entry))
imgReplace_button.place(x=170, y=105)
# 输入框
Entrybutton = tkinter.Entry(root, width=15)
Entrybutton.insert(0, 2)
Entrybutton.place(x=490, y=110)
lab5 = tkinter.Label(root, text="Gamma:")
lab5.place(x=430, y=110)
# 伽马矫正函数(默认1/1,5)
def gammaCorrect(e_entry, Entrybutton):
img = Image.open(e_entry.get())
img = np.array(img)
img1 = np.power(img / float(np.max(img)), int(Entrybutton.get()))
img2 = Image.fromarray(np.uint8(img1 * 255))
img3 = ImageTk.PhotoImage(img2)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 伽马矫正按钮
gammaCorrect_button = tkinter.Button(root, text="伽马矫正", command=lambda: gammaCorrect(e_entry, Entrybutton))
gammaCorrect_button.place(x=240, y=105)
def decrease_color(e_entry):
img = Image.open(e_entry.get())
img = np.array(img)
H = img.shape[0] # 获取图片的高
W = img.shape[1] # 获取图片的宽
newImg = np.zeros((H, W, 3), np.uint8)
for i in range(H):
for j in range(W):
for k in range(3): # RGB三分量
if img[i, j][k] < 128:
gray = 0
else:
gray = 128
newImg[i, j][k] = np.uint8(gray) # 传给新图片
newImg = Image.fromarray(newImg)
img3 = ImageTk.PhotoImage(newImg)
img = tkinter.Label(image=img3)
img.image = img3
img.place(x=350, y=150)
# 减色按钮
decrease_color_button = tkinter.Button(root, text="减色", command=lambda: decrease_color(e_entry))
decrease_color_button.place(x=310, y=105)
# 采样函数
def picSampl(img, newH, newW):
scrH, scrW, t = img.shape # 原图的长宽
retimg = np.zeros((newH, newW, 3), dtype=np.uint8) # 生成 newH* newW *3 的零矩阵
for i in range(newH - 1):
for j in range(newW - 1):
scrx = round(i * (scrH / newH)) # round对其四舍五入
scry = round(j * (scrW / newW))
retimg[i, j] = img[scrx, scry] # new image
return retimg
# 采样展示
def showImage(e_entry):
img = np.array(Image.open(e_entry.get()))
img1 = picSampl(img, img.shape[0] * 2, img.shape[1] * 2)
img1 = Image.fromarray(img1)
img2 = ImageTk.PhotoImage(img1)
img = tkinter.Label(image=img2)
img.image = img2
img.place(x=350, y=150)
# 采样按钮
picSampl_button = tkinter.Button(root, text='图片采样', command=lambda: showImage(e_entry))
picSampl_button.place(x=360, y=105)
# 图片展示
def showImg(e_entry):
load = Image.open(e_entry.get())
render = ImageTk.PhotoImage(load)
img = tkinter.Label(image=render)
img.image = render
img.place(x=50, y=150)
# 图片展示按钮
submit_button = tkinter.Button(root, text="显示原图", command=lambda: showImg(e_entry))
submit_button.place(x=40, y=75)
lable3 = tkinter.Label(root, text='原图', bg='red')
lable3.place(x=140, y=460)
lable4 = tkinter.Label(root, text='处理后', bg='red')
lable4.place(x=450, y=460)
root.mainloop()

View File

@ -6,34 +6,45 @@
# @Software: PyCharm
'''
gamma矫正公式
f(x)=xγ
f(x)=x^γ
即输出是输入的幂函数指数为γ
'''
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
# 文件保存的地址及文件夹
root = "E:\\桌面\\Python_Picture_Analysis\\data\\"
# 定义伽马矫正函数
def gammaCorrect(filePath, val):
'''
:param filePath: 图片路径
:param val: 伽马值
:return: 图片
'''
# 获取图片
im = Image.open(filePath)
img = np.array(im)
img = np.array(im) # 图片转矩阵
img1 = np.power(img / float(np.max(img)), 1 / 1.5)
img2 = np.power(img / float(np.max(img)), val)
# 伽马函数使用
img1 = np.power(img / float(np.max(img)), 1 / 1.5) # gamma值为1/1.5
img2 = np.power(img / float(np.max(img)), val) # 自定义gamma值
# 多图合并
plt.subplot(131)
plt.imshow(img)
plt.title("origin")
plt.title("origin") # 展示原图
plt.subplot(132)
plt.imshow(img1)
plt.title("gammar=1/1.5")
plt.title("gammar=1/1.5") # 展示gamma =1/1.5
plt.subplot(133)
plt.imshow(img2)
plt.title("user-defined")
plt.title("user-defined") # 展示自定义 gammat Image
plt.show()
# 图片保存
Image.fromarray(np.uint8(img2)).save(root + 'picture10' + '.jpg')
return img2

View File

@ -9,9 +9,11 @@ import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
# 图片保存的地址文件夹
root = "E:\\桌面\\Python_Picture_Analysis\\data\\"
# 定义图片剪切函数
def imgCut(path, left, upper, right, lower):
"""
:param path: 图片路径
@ -21,27 +23,34 @@ def imgCut(path, left, upper, right, lower):
:param lower:与底部边界的距离
:return:
"""
# 获取图片
img = Image.open(path)
print(img.size)
part = (left, upper, right, lower)
# print(img.size) Picture Size
part = (left, upper, right, lower) # 设置剪切的大小
# 剪切函数的调用
cut_img = img.crop(part)
# 展示图片
# 展示原图
plt.figure("image Cut")
plt.subplot(121)
plt.title("origin")
plt.imshow(img)
# 展示剪切后的图片
plt.subplot(122)
plt.title("CUT part")
plt.imshow(cut_img)
plt.show()
# 图片保存
Image.fromarray(np.uint8(cut_img)).save(root + "picture11.jpg")
return cut_img
#定义图片部分替换函数
def imgReplace(path1, path2, left2, upper2, right2, lower2):
"""
:param path1: 被替换图片的路径
@ -49,21 +58,27 @@ def imgReplace(path1, path2, left2, upper2, right2, lower2):
:param left2, upper2, right2, lower2:替换图片的大小
:return:
"""
img1 = Image.open(path1)
img2 = Image.open(path2)
#图片的获取
img1 = Image.open(path1) # 被替换图
img2 = Image.open(path2) #替换图
part2 = (left2, upper2, right2, lower2)
cut_img2 = img2.crop(part2)
#调用替换函数
img1.paste(cut_img2, (10, 50, 250, 250))
#定义画布
plt.figure("picture replace")
plt.subplot(121)
plt.imshow(img2)
plt.title("Origin") # 展示原图
plt.subplot(122)
plt.imshow(img1)
plt.title("replaced picture") #展示替换后的图
plt.show()
# 保存 替换后的图片
Image.fromarray(np.uint8(img1)).save(root + 'picture12.jpg')
return img1

View File

@ -4,22 +4,36 @@
# @Email : derighoid@gmail.com
# @File : Image_Mix.py
# @Software: PyCharm
from PIL import Image
import PIL
import matplotlib.pyplot as plt
import numpy as np
import cv2
from PIL import Image
'''
img1图片对象1
img2图片对象2
alpha透明度 取值范围为 0 1当取值为 0 输出图像相当于 image1 的拷贝而取值为 1
则是 image2 的拷贝只有当取值为 0.5 才为两个图像的中合因此改值的大小决定了两个图像的混合程度'''
# 阿尔法图像混合
def imageMix(imagePath1, imagePath2):
'''
:param imagePath1: 混合图片1的地址
:param imagePath2: 混合图像2的地址
:return: 混合后的图像
'''
# 获取两张图片
img1 = Image.open(imagePath1)
im1 = np.array(img1)
img2 = Image.open(imagePath2)
im2 = np.array(img2)
img3 = cv2.addWeighted(im1, 0.8, im2, 0.3, 0)
# 调用图片混合函数
img3 = PIL.Image.blend(img1, img2, 0.5) # 0.5 为gamma 值
# 展示混合后的图片
plt.imshow(img3)
# 保存图片
Image.fromarray(np.uint8(img3)).save("./data/picture14.png")
plt.show()

View File

@ -41,12 +41,13 @@ class modfifyImage():
# 显示图像三通道颜色
def img_RGB(self):
root="E:\\桌面\\Python_Picture_Analysis\\data\\" # 图片保存地址
red = self.imageMatrix().copy()
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())

View File

@ -11,7 +11,7 @@ import os
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
#定义 图片方向改变类
class directionChanges():
def __init__(self, filePath):
self.filePath = filePath
@ -64,10 +64,11 @@ class directionChanges():
# 保存图片
def img_Save(self):
root = "E:\\桌面\\Python_Picture_Analysis\\data\\"
if not os.path.exists(root):
os.mkdir(root)
root = "E:\\桌面\\Python_Picture_Analysis\\data\\" # 图片保存地址
if not os.path.exists(root): # 判断是否已经存在该文件
os.mkdir(root) #没有就创建
else:
#图片保存
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')

View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# @Time : 2022-7-24 0024 11:18
# @Author : Qing
# @Email : derighoid@gmail.com
# @File : Picture _Crawling.py
# @Software: PyCharm
# 导入库
import os
import requests
# path = '(?<=<img(?:.*)\s+src=")[^"]+(\.png|jpg|jpeg)'
# 定义函数
def pictureCrawl(url):
# 文件保存地址
root = "E://桌面//Python_Picture_Analysis//data//"
# 文件的保存地址以及格式
path = root + url.split('/')[-3] + '.png'
try:
if not os.path.exists(root): # 判断是否存在文件夹
os.mkdir(root)
if not os.path.exists(path): # 判断是否存在该文件
r = requests.get(url)
# 文件写入
with open(path, 'wb') as fp:
fp.write(r.content)
print("OK")
else:
print("File already exists")
except:
print("Crawl successful")
#图片URL
url = "https://tse2-mm.cn.bing.net/th/id/OIP-C.fT7uKiT7V7YO2PPINFeOdQHaJ4?w=186&h=248&c=7&r=0&o=5&dpr=1.25&pid=1.7"
pictureCrawl(url)

View File

@ -50,9 +50,10 @@ class pictureRead(object):
# 图片plt展示
def plt_image(self):
plt.subplot(121)
# 原图片显示
plt.imshow(self.imageMatrix())
plt.show()
plt.subplot(122)
# 灰色图片显示
plt.imshow(self.imageGrey())
plt.show()

View File

@ -6,11 +6,11 @@
# @Software: PyCharm
import os.path
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from Picture_Reading import *
class ReduceColor(pictureRead):
def __init__(self, filePath):
self.filePath = filePath
@ -25,16 +25,86 @@ class ReduceColor(pictureRead):
# 减色算法
def decrease_color(self):
out=self.imageMatrix().copy()
out=out//64*64+32
Image.fromarray((np.uint8(out))).save("E:\\桌面\\Python_Picture_Analysis\\data\\picture8.jpg")
return out
'''
val=|32 (0<=var<64)
|96 (64<=var<128)
|160 (128<=var<192)
|224 (192<=var<256)
:return:
'''
img = self.imageMatrix().copy()
# img=img//64*64+32
H = img.shape[0] # 获取图片的高
W = img.shape[1] # 获取图片的宽
# 展示图片
def plt_Img(self):
plt.imshow(self.decrease_color())
# 创建新的图
newImg = np.zeros((H, W, 3), np.uint8)
newImg2 = np.zeros((H, W, 3), np.uint8)
newImg3 = np.zeros((H, W, 3), np.uint8)
# 量化操作
for i in range(H):
for j in range(W):
for k in range(3): # RGB三分量
if img[i, j][k] < 128:
gray = 0
else:
gray = 128
newImg[i, j][k] = np.uint8(gray) # 传给新图片
for i in range(H):
for j in range(W):
for k in range(3):
if img[i, j][k] < 64:
gray = 0
elif img[i, j][k] < 128:
gray = 64
elif img[i, j][k] < 192:
gray = 128
else:
gray = 192
newImg2[i, j][k] = np.uint8(gray)
for i in range(H):
for j in range(W):
for k in range(3):
if newImg3[i, j][k] < 32:
gray = 0
elif newImg3[i, j][k] < 96:
gray = 32
elif newImg3[i, j][k] < 96:
gray = 96
elif newImg3[i, j][k] < 128:
gray = 96
elif newImg3[i,j][k]<160:
gray=128
elif newImg3[i,j][k]<192:
gray=160
elif newImg3[i,j][k]<244:
gray=192
else:
gray = 224
newImg3[i, j][k] = np.uint8(gray)
#定义画布
plt.figure(figsize=(16,8))
plt.subplot(141)
plt.imshow(img)
plt.title("origin")
plt.subplot(142)
plt.imshow(newImg)
plt.title("1")
plt.subplot(143)
plt.imshow(newImg2)
plt.title("2")
plt.subplot(144)
plt.imshow(newImg3)
plt.title("3")
plt.show()
return newImg,newImg2,newImg3
# 图像二值化(以128为阈值进行二值化)
def imgBinarization(self):
@ -54,7 +124,6 @@ class ReduceColor(pictureRead):
if not os.path.exists(root):
os.mkdir(root)
else:
Image.fromarray(np.uint8(self.decrease_color())).save(root + 'picture8'+'.jpg')
Image.fromarray(np.uint8(self.decrease_color)).save(root + 'picture8' + '.jpg')
Image.fromarray(np.uint8(self.imgBinarization())).save(root + 'picture9' + '.jpg')
print("Picture Save successfully")

32
main.py
View File

@ -10,17 +10,22 @@ from Modify_Pixels import *
from Orientation_Modification import *
from Subtractive_Algorithm import *
from Image_Mix import *
from Blue_noise_sampling import *
from Image_Capture import *
if __name__ == '__main__':
# 图片读取
picture_read = pictureRead('E:\\桌面\\Python_Picture_Analysis\\data\\th.jpg')
# picture_read.plt_image()
picture_read = pictureRead('E:\\桌面\\Python_Picture_Analysis\\data\\th.png')
#图片展示
picture_read.plt_image()
# 图片修改
modif_image = modfifyImage('E:\\桌面\\Python_Picture_Analysis\\data\\th.jpg')
modif_image = modfifyImage('E:\\桌面\\Python_Picture_Analysis\\data\\th.png')
# print(modif_image.img_RGB())
# 图片方向修改
direction_Changes = directionChanges('E:\\桌面\\Python_Picture_Analysis\\data\\th.jpg')
direction_Changes = directionChanges('E:\\桌面\\Python_Picture_Analysis\\data\\th.png')
# direction_Changes.verticalSummetry_right()
# direction_Changes.verticalSummetry_lift()
# direction_Changes.mirrorSymmetry()
@ -28,8 +33,8 @@ if __name__ == '__main__':
# direction_Changes.img_Save()
# 减色算法
reduce_color = ReduceColor('E:\\桌面\\Python_Picture_Analysis\\data\\th.jpg')
# reduce_color.plt_Img()
reduce_color = ReduceColor('E:\\桌面\\Python_Picture_Analysis\\data\\th.png')
# reduce_color.decrease_color()
# reduce_color.img_Save()
# reduce_color.imgBinarization()
@ -38,12 +43,17 @@ if __name__ == '__main__':
# 图片截取
# left, upper, right, lower
# imgCut('E:\\桌面\\Python_Picture_Analysis\\data\\th.jpg',20,10,190,190)
# imgCut('E:\\桌面\\Python_Picture_Analysis\\data\\picture.jpg',30,70,230,230)
imgCut('E:\\桌面\\Python_Picture_Analysis\\data\\th.png',20,10,190,190)
imgCut('E:\\桌面\\Python_Picture_Analysis\\data\\picture.png',30,70,230,230)
# 图片替换
# imgReplace('E:\\桌面\\Python_Picture_Analysis\\data\\th.jpg', "E:\\桌面\\Python_Picture_Analysis\\data\\picture.jpg",
# 10, 50, 250, 250)
imgReplace('E:\\桌面\\Python_Picture_Analysis\\data\\th.png', "E:\\桌面\\Python_Picture_Analysis\\data\\picture.png",
10, 50, 250, 250)
# 阿尔法混合
# imageMix('E:\\桌面\\Python_Picture_Analysis\\data\\th.png','E:\\桌面\\Python_Picture_Analysis\\data\\picture.png')
imageMix('E:\\桌面\\Python_Picture_Analysis\\data\\th.png','E:\\桌面\\Python_Picture_Analysis\\data\\picture.png')
#蓝噪
showImage("./data/th.png")