from PIL import Image as Im
from PIL import ImageTk
import tkinter as tk # 导入 Tkinter 库
from tkinter.filedialog import askopenfilename
import tkinter.messagebox
import tkinter.ttk
import tkinter.messagebox
from PIL import ImageDraw
from PIL import ImageFont
from PIL import ImageEnhance
from Pic import *
from wlw import wlw
import numpy as np
class Win(tk.Tk):
def __init__(self):
super().__init__()
self.title('王灵婉的图像处理工具')
self.geometry('1080x720')
self.picture = None # self.picture将作为picture类的实例化对象
self.img = None # self.img将作为窗口类中一直变动的PIL对象图片
self.setupUI()
def setupUI(self):
# 右边菜单栏
right_f = tk.Frame(self, height=720, width=360,bg="#F8F8FF")
right_f.pack(side=tk.RIGHT)
# 各种功能按钮名称及位置
btn1 = tk.Button(right_f, text='打开图像', bg="#F3E5F5",command=self.openToshow)
btn1.place(y=25, x=30, width=300, height=40)
btn2 = tk.Button(right_f, text='截图', bg="#F3E5F5", command=self.window_cut)
btn2.place(y=85, x=30, width=144, height=40)
btn3 = tk.Button(right_f, text='大小', bg="#F3E5F5", command=self.window_size)
btn3.place(y=85, x=186, width=144,height=40)
btn4 = tk.Button(right_f, text='旋转', bg='#E1BEE7', command=self.window_rotate)
btn4.place(y=145, x=30, width=144, height=40)
btn5 = tk.Button(right_f, text='镜像', bg='#E1BEE7',command=self.window_mirror)
btn5.place(y=145, x=186, width=144, height=40)
btn6 = tk.Button(right_f, text='灰度变换', bg='#E1BEE7',command=self.window_word)
btn6.place(y=205, x=30, width=144, height=40)
btn7 = tk.Button(right_f, text='滤镜', bg='#E1BEE7',command=self.window_style)
btn7.place(y=205, x=186, width=144, height=40)
btn8 = tk.Button(right_f, text='显示直方图', bg='#CE93D8',command=self.toshowhist)
btn8.place(y=265, x=30, width=144, height=40)
btn9 = tk.Button(right_f, text='图像相加', bg='#CE93D8',command=self.openToshow2)
btn9.place(y=265, x=186, width=144, height=40)
btn10 = tk.Button(right_f, text='滤波', bg='#CE93D8',command=self.openfilter)
btn10.place(y=325, x=30, width=144, height=40)
btn11 = tk.Button(right_f, text='Sobel锐化', bg='#CE93D8',command=self.opensharpen)
btn11.place(y=325, x=186, width=144, height=40)
# 各种调整名称及位置
lb1 = tk.Label(right_f, text='亮 度:',bg="#F8F8FF")
lb1.place(y=395, x=55, width=60, height=30)
self.inp1 = tk.Entry(right_f)
self.inp1.place(y=395, x=105, width=90, height=30)
lb2 = tk.Label(right_f, text='%',bg="#F8F8FF")
lb2.place(y=395, x=205, width=13, height=30)
b1 = tk.Button(right_f, text='确定',fg='#F8F8FF', width=8, command=self.brightnessPic,bg="#CE93D8")
b1.place(y=395, x=240)
lb3 = tk.Label(right_f, text='色彩度:',bg="#F8F8FF")
lb3.place(y=440, x=55, width=60, height=30)
self.inp2 = tk.Entry(right_f)
self.inp2.place(y=440, x=105, width=90, height=30)
lb4 = tk.Label(right_f, text='%',bg="#F8F8FF")
lb4.place(y=440, x=205, width=13, height=30)
b2 = tk.Button(right_f, text='确定',fg='#F8F8FF', width=8, command=self.coolorPic,bg="#CE93D8")
b2.place(y=444, x=240)
lb5 = tk.Label(right_f, text='对比度:',bg="#F8F8FF")
lb5.place(y=485, x=55, width=60, height=30)
self.inp3 = tk.Entry(right_f)
self.inp3.place(y=485, x=105, width=90, height=30)
lb6 = tk.Label(right_f, text='%',bg="#F8F8FF")
lb6.place(y=485, x=205, width=13, height=30)
b3 = tk.Button(right_f, text='确定',fg='#F8F8FF', width=8, command=self.contrastPic,bg="#AB478C")
b3.place(y=489, x=240)
lb7 = tk.Label(right_f, text='锐 度:',bg="#F8F8FF")
lb7.place(y=530, x=55, width=60, height=30)
self.inp4 = tk.Entry(right_f)
self.inp4.place(y=530, x=105, width=90, height=30)
lb8 = tk.Label(right_f, text='%',bg="#F8F8FF")
lb8.place(y=530, x=205, width=13, height=30)
b4 = tk.Button(right_f, text='确定',fg='#F8F8FF', width=8, command=self.sharpnessPic,bg="#AB478C")
b4.place(y=534, x=240)
# 底部恢复、保存、对比
btn18 = tk.Button(right_f, text='保存图像',fg='#F8F8FF', command=self.save_pic,bg="#9C27B0")
btn18.place(y=640, x=150, width=180, height=30)
btn19 = tk.Button(right_f, text='恢复图像',fg='#F8F8FF', command=self.replay,bg="#9C27B0")
btn19.place(y=590, x=90)
btn20 = tk.Button(right_f, text='对比图像',fg='#F8F8FF', command=self.compare,bg="#9C27B0")
btn20.place(y=590, x=170)
btn21 = tk.Button(right_f, text='人脸检测',fg='#F8F8FF', command=self.facedetection,bg="#9C27B0")
btn21.place(y=590, x=250)
# 右侧图像显示栏
right_f = tk.Frame(self, height=720, width=720)
right_f.pack(side=tk.RIGHT)
self.image_l = tk.Label(right_f, relief='ridge')
self.image_l.place(x=0, y=0, width=720, height=720)
def facedetection(self):
detect_pic = self.img
detect_pic = wlw.facedetection(detect_pic)
self.show_img(detect_pic)
def openfilter(self):
filter_win = tk.Toplevel()
filter_win.title('滤波选择')
filter_win.geometry('150x150')
b1 = tk.Button(filter_win, text='均值滤波', command=self.filter1)
b1.place(y=30, x=35, width=75)
b2 = tk.Button(filter_win, text='中值滤波', command=self.filter2)
b2.place(y=60, x=35, width=75)
b3 = tk.Button(filter_win, text='完成', command=filter_win.destroy)
b3.place(y=110, x=80, width=40)
def opensharpen(self):
sharpen_pic = self.img
sharpen_pic = wlw.sharpen(sharpen_pic)
self.show_img(sharpen_pic)
# 打开图片时使用,传值(图)给展示函数
def openToshow(self):
address = self.getAddress()
self.open_picToimg = self.picture.open_pic(address)
self.firstPic(self.open_picToimg)
self.show_img(self.open_picToimg)
# 打开图片时使用,传值(图)给展示函数
def openToshow2(self):
address2 = self.getAddress2()
self.open_picToimg2 = self.picture.open_pic(address2)
self.firstPic2(self.open_picToimg2)
self.show_img2(self.open_picToimg2)
def filter1(self):
img_show = wlw.filter1(self.img)
self.image_l.config(image=img_show)
self.image_l.image = img_show
return self.img
def filter2(self):
img_show = wlw.filter2(self.img)
self.image_l.config(image=img_show)
self.image_l.image = img_show
return self.img
# 打开图片时使用,获得地址
def getAddress(self):
path = tk.StringVar()
file_entry = tk.Entry(self, state='readonly', text=path)
path_ = askopenfilename()
path.set(path_)
self.picture = picture()
return file_entry.get()
# 打开图片时使用,获得地址
def getAddress2(self):
path2 = tk.StringVar()
file_entry2 = tk.Entry(self, state='readonly', text=path2)
path_2 = askopenfilename()
path2.set(path_2)
self.picture2 = picture()
return file_entry2.get()
# 展示函数
def show_img(self, n_img):
self.img = n_img # self.img PIL对象方便传值给picture类以及本类中其他需要使用PIL图像的地方
img_show = ImageTk.PhotoImage(self.img)
self.image_l.config(image=img_show)
self.image_l.image = img_show
return self.img
wlwwlk
- 粉丝: 9
- 资源: 1
最新资源
- Linux nacos2.4.3压缩包
- C++20 规范,v s 2019 function 源码分析精简版
- html+css+js的宠物领养网站(响应式)
- go实现通过命令访问Kafka
- 数据中台(大数据平台)资源目录编制标准规范.pdf
- 极速浏览器(超快速运行)
- uniapp vue3 下拉菜单组件(dropdownMenu)
- 《全面解析图像平滑处理:多种滤波方法及应用实例》
- Kafka客户端producer/consumer样例
- OneOS是中国移动针对物联网领域推出的轻量级操作系统,具有可裁剪、跨平台、低功耗、高安全等特点,支持ARM Cortex-M/R/A、MIPS、RISC-V等主流CPU架构
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈