欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

乱七八糟:图像滤波小demo

程序员文章站 2022-03-16 17:44:53
...
import tkinter
from tkinter import filedialog
from tkinter import *
import matplotlib.pyplot as plt
import cv2
top = tkinter.Tk()
top.title("图片滤波")
top.geometry('300x300+500+300')
def blur0():
   pic0 = tkinter.filedialog.askopenfilename()
   img = cv2.imread(pic0)
   blu = cv2.blur(img, (5, 5))
   plt.subplot(1, 2, 1)
   plt.imshow(img)
   plt.title('src')
   plt.subplot(1, 2, 2)
   plt.imshow(blu)
   plt.title('blur')
   plt.show()
def meanblur0():
    pic0 = tkinter.filedialog.askopenfilename()
    img = cv2.imread(pic0)
    median = cv2.medianBlur(img, 5)
    plt.subplot(1, 2, 1)
    plt.imshow(img)
    plt.title('src')
    plt.subplot(1, 2, 2)
    plt.imshow(median)
    plt.title('medianblur')
    plt.show()
def Laplacian0():
    pic0 =tkinter.filedialog.askopenfilename()
    img = cv2.imread(pic0)
    lap = cv2.Laplacian(img,-1)
    plt.subplot(1, 2, 1)
    plt.imshow(img)
    plt.title('src')
    plt.subplot(1, 2, 2)
    plt.imshow(lap)
    plt.title('Laplacian')
    plt.show()
def Sobel0():
    pic0 = tkinter.filedialog.askopenfilename()
    img = cv2.imread(pic0)
    sobx = cv2.Sobel(img, cv2.CV_64F, 1, 0)
    soby = cv2.Sobel(img, cv2.CV_64F, 0, 1)
    sobxy = cv2.Sobel(img,cv2.CV_64F,1,1)
    plt.subplot(2, 2, 1)
    plt.imshow(img)
    plt.title('src')
    plt.subplot(2, 2, 2)
    plt.imshow(sobx)
    plt.title('sobelX')
    plt.subplot(2, 2, 3)
    plt.imshow(soby)
    plt.title('sobelY')
    plt.subplot(2, 2, 4)
    plt.imshow(sobxy)
    plt.title('sobelXY')
    plt.show()
b1 = tkinter.Button(top,text='   选择图片均值滤波   ',command=blur0)
b1.pack()
b2 = tkinter.Button(top,text='   选择图片中值滤波   ',command=meanblur0)
b2.pack()
b3 = tkinter.Button(top,text='选择图片拉普拉斯滤波',command=Laplacian0)
b3.pack()
b4 = tkinter.Button(top,text='  选择图片sobel滤波  ',command=Sobel0)
b4.pack()
top.mainloop()






相关标签: 计算机视觉