You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.8 KiB
134 lines
4.8 KiB
import tkinter as tk
|
|
from tkinter import filedialog
|
|
from PIL import Image, ImageTk
|
|
import cv2
|
|
import numpy as np
|
|
import os
|
|
import tempfile
|
|
|
|
from flip_image_horizontal import horizontal
|
|
from flip_image_cross import cross
|
|
from flip_image_vertical import vertical
|
|
from image_enhancement import enhancement
|
|
from histogram_equalization import h_e
|
|
from edge_detection_Roberts import roberts
|
|
from edge_detection_Sobel import sobel
|
|
from edge_detection_Laplacian import laplacian
|
|
from edge_detection_Canny import canny
|
|
from houghlinesp import hlp
|
|
from open_operation import open
|
|
from close_operation import close
|
|
from affine_transformation import at
|
|
from odw_bi import odwbi
|
|
from salt_and_pepper_noise import add_salt_pepper
|
|
from odwpanning import odwp
|
|
from odw_rotation import odwr
|
|
from odw_linear_t import odwlt
|
|
from mean_filter import mf
|
|
from odw_selective_filter import odwsf
|
|
from sort_statistical_class_filter import sscf
|
|
from style_migration_candy import candy
|
|
from style_migration_composition_vii import composition_vii
|
|
from style_migration_feathers import feathers
|
|
from style_migration_la_muse import la_muse
|
|
from style_migration_mosaic import mosaic
|
|
from style_migration_starry_night import starry_night
|
|
from style_migration_the_scream import the_scream
|
|
from style_migration_the_wave import the_wave
|
|
from style_migration_udnie import udnie
|
|
from open_dialog_windows import open_dialog_window
|
|
from odw_erosion import odwe
|
|
from odw_erosion import odwd
|
|
class ImageProcessingApp:
|
|
def __init__(self, master):
|
|
self.master = master
|
|
self.master.title("图像处理应用")
|
|
|
|
self.upload_button = tk.Button(self.master, text="上传图片", command=self.upload_image)
|
|
self.upload_button.pack()
|
|
|
|
self.original_image_label = tk.Label(self.master)
|
|
self.original_image_label.pack()
|
|
|
|
self.processed_image_label = tk.Label(self.master)
|
|
self.processed_image_label.pack()
|
|
|
|
self.process_buttons_frame = tk.Frame(self.master)
|
|
self.process_buttons_frame.pack()
|
|
|
|
self.create_process_buttons()
|
|
|
|
self.original_image = None
|
|
self.processed_image = None
|
|
self.temp_dir = tempfile.TemporaryDirectory()
|
|
|
|
def upload_image(self):
|
|
file_path = filedialog.askopenfilename()
|
|
if file_path:
|
|
self.original_image = Image.open(file_path)
|
|
self.display_image(self.original_image, self.original_image_label)
|
|
|
|
def display_image(self, image, label):
|
|
image.thumbnail((300, 300))
|
|
img = ImageTk.PhotoImage(image)
|
|
label.config(image=img)
|
|
label.image = img
|
|
|
|
def create_process_buttons(self):
|
|
functions = [
|
|
('水平翻转', horizontal),
|
|
('十字翻转', cross),
|
|
('垂直翻转', vertical),
|
|
('图像增强', enhancement),
|
|
('直方图均衡化', h_e),
|
|
('Roberts边缘检测', roberts),
|
|
('Sobel边缘检测', sobel),
|
|
('Laplacian边缘检测', laplacian),
|
|
('Canny边缘检测', canny),
|
|
('直线检测', hlp),
|
|
('开操作', open),
|
|
('闭操作', close),
|
|
('腐蚀', odwe),
|
|
('膨胀', odwd),
|
|
('仿射变换', at),
|
|
('双线性插值', odwbi),
|
|
('添加椒盐噪声', add_salt_pepper),
|
|
('平移', odwp),
|
|
('旋转', odwr),
|
|
('线性变换', odwlt),
|
|
('均值滤波', mf),
|
|
('选择性滤波', odwsf),
|
|
('排序统计滤波', sscf),
|
|
('糖果风格迁移', candy),
|
|
('抽象油画风格迁移', composition_vii),
|
|
('羽毛风格迁移', feathers),
|
|
('缪斯风格迁移', la_muse),
|
|
('马赛克风格迁移', mosaic),
|
|
('星夜风格迁移', starry_night),
|
|
('呐喊风格迁移', the_scream),
|
|
('波浪风格迁移', the_wave),
|
|
('udnie风格迁移', udnie),
|
|
('证件照背景色替换', open_dialog_window)
|
|
]
|
|
|
|
for index, (text, func) in enumerate(functions):
|
|
button = tk.Button(self.process_buttons_frame, text=text, command=lambda f=func: self.process_image(f))
|
|
button.grid(row=index // 5, column=index % 5, padx=10, pady=10)
|
|
|
|
def process_image(self, func):
|
|
if self.original_image:
|
|
with tempfile.NamedTemporaryFile(dir=self.temp_dir.name, suffix='.png', delete=False) as temp_file:
|
|
self.original_image.save(temp_file.name)
|
|
temp_file_path = temp_file.name
|
|
func(temp_file_path)
|
|
processed_image = Image.open(temp_file_path)
|
|
|
|
def __del__(self):
|
|
self.temp_dir.cleanup()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
app = ImageProcessingApp(root)
|
|
root.mainloop()
|