Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import the necessary packages
- from tkinter import *
- from PIL import Image
- from PIL import ImageTk
- from PIL import ImageFilter
- from tkinter import filedialog
- from matplotlib import pyplot as plt
- from scipy import ndimage
- #import tkFileDialog
- import cv2
- import time
- import numpy
- global gray
- global image
- global panelA
- def select_image():
- # grab a reference to the image panels
- global image
- # open a file chooser dialog and allow the user to select an input
- # image
- #path = tkFileDialog.askopenfilename()
- #root = Tk()
- #root.
- filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
- print (filename)
- # ensure a file path was selected
- if len(filename) > 0:
- # load the image from disk, convert it to grayscale, and detect
- # edges in it
- image = cv2.imread(filename)
- # check()
- # time.sleep(5)
- hpf()
- return image
- # edged = cv2.Canny(gray, 50, 100)
- # # OpenCV represents images in BGR order; however PIL represents
- # # images in RGB order, so we need to swap the channels
- # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- # convert the images to PIL format...
- # image = Image.fromarray(image)
- # edged = Image.fromarray(edged)
- # # ...and then to ImageTk format
- # image = ImageTk.PhotoImage(image)
- # edged = ImageTk.PhotoImage(edged)
- # # if the panels are None, initialize them
- # if panelA is None: #or panelB is None:
- # # the first panel will store our original image
- # panelA = Label(image=image)
- # panelA.image = image
- # panelA.pack(side="left", padx=10, pady=10)
- # # while the second panel will store the edge map
- # # panelB = Label(image=edged)
- # # panelB.image = edged
- # # panelB.pack(side="right", padx=10, pady=10)
- # # otherwise, update the image panels
- # else:
- # # update the pannels
- # panelA.configure(image=image)
- # #panelB.configure(image=edged)
- # panelA.image = image
- # #panelB.image = edged
- # initialize the window toolkit along with the two image pane
- def check():
- global panelA, gray, image
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- #image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- image = Image.fromarray(gray)
- image = ImageTk.PhotoImage(image)
- if panelA is None:
- panelA = Label(image=image)
- panelA.image = image
- panelA.pack(side="left", padx=10, pady=10)
- else:
- panelA.configure(image=image)
- panelA.image = image
- def hpf():
- global panelA, image, filtered
- gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
- #image2 = Image.fromarray(gray)
- #dane = numpy.array(image, dtype=float)
- #low = ndimage.gaussian_filter(dane, 5)
- #hp = dane - low
- #blur = image2.filter(ImageFilter.GaussianBlur(radius = 20))
- blur = cv2.GaussianBlur(gray,(5,5),0)
- hp = gray - blur
- image2 = Image.fromarray(hp)
- image2 = ImageTk.PhotoImage(image2)
- #laplacian = cv2.Laplacian(gray,cv2.CV_64F)
- #filtered = cv2.subtract(img, blur)
- #filtered = filtered + 127*numpy.ones(neg_frame.shape, numpy.uint8)
- if panelA is None:
- panelA = Label(image=image2)
- panelA.image = image2
- panelA.pack(side="left", padx=10, pady=10)
- else:
- panelA.configure(image=image2)
- panelA.image = image2
- root = Tk()
- panelA = None
- #panelB = None
- # create a button, then when pressed, will trigger a file chooser
- # dialog and allow the user to select an input image; then add the
- # button the GUI
- btn = Button(root, text="Select an image", command=select_image)
- btn.pack(side="bottom", fill="both", expand="yes", padx="10", pady="10")
- # btn = Button(root, text="Check", command=check)
- # btn.pack(side="bottom", fill="both", expand="yes", padx="10", pady="30")
- # kick off the GUI
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement