Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image as IMG, ImageDraw,ImageTk
- from tkinter.filedialog import askopenfilename
- from tkinter import *
- import random, math, copy
- import win32com.client, pythoncom, time
- def Laplassian(image, c, mode, mode2):
- im = copy.copy(image)
- draw = ImageDraw.Draw(im)
- pix = image.load()
- for i in range(1, width-1):
- for j in range(1, height-1):
- f = pix[i, j][0]
- # if (f<135 and not mode):
- # print('yeah')
- xn = pix[i+1, j][0]
- xp = pix[i-1, j][0]
- yn = pix[i, j+1][0]
- yp = pix[i, j-1][0]
- xnd = pix[i+1, j-1][0]
- xpd = pix[i-1, j+1][0]
- ynd = pix[i+1, j+1][0]
- ypd = pix[i-1, j-1][0]
- if (mode):
- lap = -(xn + xp + yn + yp )+(4 * f)
- else:
- lap = -(xn + xp + yn + yp + xnd + ynd + xpd + ypd) + (8 * f)
- if (lap<0):
- lap = 0
- if ( lap>255):
- lap = 255
- g = int(f + (c * lap))
- if (g < 0):
- g = 0
- if (g > 255):
- g = 255
- draw.point((i, j), (lap,lap,lap) if mode2 else (g,g,g))
- return im
- image = IMG.open(askopenfilename())
- split = image.filename.split("/")
- imagename = split[len(split)-1]
- width = image.size[0]
- height = image.size[1]
- pix = image.load()
- # make grey image
- draw = ImageDraw.Draw(image)
- for i in range(width):
- for j in range(height):
- a,b,c = pix[i, j][:3]
- # S = int(0.7*a + 0.2*b + 0.1*c)
- S = int((0.2989 * a + 0.5870 * b + 0.1140 * c))
- #S = int(a + b + c)//3
- draw.point((i, j), (S, S, S))
- # mask 4
- mask4 = Laplassian(image, 0, 1, 1)
- # mask 8
- mask8 = Laplassian(image, 0, 0, 1)
- # c = 0.5 mask 4
- mask4half = Laplassian(image, 0.5, 1, 0)
- # c = 0.5 mask 8
- mask8half = Laplassian(image, 0.5, 0, 0)
- # c = 1 mask 8
- mask8one = Laplassian(image, 1, 0, 0)
- images = [image,mask4,mask8,mask4half,mask8half,mask8one]
- root = Tk()
- #root.bind("<Button>", button_click_exit_mainloop)
- canvas = Canvas(root,width=999,height=999)
- canvas.pack()
- shape = (2,3)
- xlen,ylen = 0,0
- imgs = [x.resize((530,300)) for x in images]
- xsize = sum(im.size[0] for im in imgs)
- ysize = sum(im.size[1] for im in imgs)
- root.geometry('%dx%d' % (xsize,ysize))
- tkpi = [ImageTk.PhotoImage(im,master=canvas) for im in imgs]
- lbl = Label(root,text='Вторая лаба Задание №1', justify=LEFT)
- lbl.place(relx=.4, rely=.75)
- lbl.config(font=('times', 20, 'bold'))
- for i in range(shape[0]):
- for j in range(shape[1]):
- index = i*shape[1]+j
- label_image = Label(root, image=tkpi[index])
- label_image.place(x=xlen,y=ylen,width=imgs[index].size[0],height=imgs[index].size[1])
- if j == shape[1]-1:
- ylen = ylen + imgs[index].size[1]
- xlen = 0
- else:
- xlen = xlen + imgs[index].size[0]
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement