Format Tugas PCD
Format Tugas PCD
KELAS : B
import os
import tkinter as tk
import numpy as np
class ImageApp:
path1 = ''
self.root = root
self.root.title("Operasi")
self.main_frame = tk.Frame(root)
self.main_frame.pack()
self.top_frame = tk.Frame(self.main_frame)
self.top_frame.pack(side=tk.TOP)
self.frame1 = tk.Frame(self.top_frame)
self.axes1 = self.figure1.add_subplot(111)
self.canvas1 = FigureCanvasTkAgg(self.figure1,
master=self.frame1)
self.canvas1.get_tk_widget().pack(side=tk.TOP)
self.open_button1 = tk.Button(self.frame1,
text="Open", command=self.open_image1)
self.open_button1.pack(side=tk.TOP)
self.frame2 = tk.Frame(self.top_frame)
self.axes2 = self.figure2.add_subplot(111)
self.canvas2 = FigureCanvasTkAgg(self.figure2,
master=self.frame2)
self.canvas2.get_tk_widget().pack(side=tk.TOP)
self.open_button2 = tk.Button(self.frame2,
text="Translasi", command=self.translasi)
self.open_button2.pack(side=tk.TOP)
self.frame3 = tk.Frame(self.top_frame)
self.axes3 = self.figure3.add_subplot(111)
self.canvas3 = FigureCanvasTkAgg(self.figure3,
master=self.frame3)
self.canvas3.get_tk_widget().pack(side=tk.TOP)
self.open_button3 = tk.Button(self.frame3,
text="Cropping", command=self.cropping)
self.open_button3.pack(side=tk.TOP)
self.bottom_frame = tk.Frame(self.main_frame)
self.bottom_frame.pack(side=tk.BOTTOM)
self.frame4 = tk.Frame(self.bottom_frame)
self.frame4.pack(side=tk.LEFT, padx=5, pady=5)
self.axes4 = self.figure4.add_subplot(111)
self.canvas4 = FigureCanvasTkAgg(self.figure4,
master=self.frame4)
self.canvas4.get_tk_widget().pack(side=tk.TOP)
self.open_button4 = tk.Button(self.frame4,
text="Flipping", command=self.flipping)
self.open_button4.pack(side=tk.TOP)
self.frame5 = tk.Frame(self.bottom_frame)
self.axes5 = self.figure5.add_subplot(111)
self.canvas5 = FigureCanvasTkAgg(self.figure5,
master=self.frame5)
self.canvas5.get_tk_widget().pack(side=tk.TOP)
self.open_button5 = tk.Button(self.frame5,
text="Rotasi", command=self.rotasi)
self.open_button5.pack(side=tk.TOP)
self.frame6 = tk.Frame(self.bottom_frame)
self.axes6 = self.figure6.add_subplot(111)
self.canvas6 = FigureCanvasTkAgg(self.figure6,
master=self.frame6)
self.canvas6.get_tk_widget().pack(side=tk.TOP)
self.open_button6 = tk.Button(self.frame6,
text="Scalling", command=self.scalling)
self.open_button6.pack(side=tk.TOP)
def open_image1(self):
self.path1 =
filedialog.askopenfilename(filetypes=[("Image files",
"*.jpg *.bmp *.tif")])
self.img = cv2.imread(self.path1,
cv2.IMREAD_GRAYSCALE)
if self.path1:
self.image_data = Image.open(self.path1)
self.image_data =
self.image_data.convert('L')
self.axes1.imshow(self.image_data,
cmap='gray')
self.canvas1.draw()
def translasi(self):
if self.path1:
Tx = 20
Ty = 50
r, c = self.img.shape
for x in range(r):
for y in range(c):
self.axes2.imshow(result, cmap='gray')
self.canvas2.draw()
def cropping(self):
if self.path1:
self.axes3.imshow(result, cmap='gray')
self.canvas3.draw()
def flipping(self):
if self.path1:
r, c = self.img.shape
for x in range(r):
for y in range(c):
result[x, y] = self.img[x, c - y - 1]
self.axes4.imshow(result, cmap='gray')
self.canvas4.draw()
def rotasi(self):
if self.path1:
angle=45
(h, w) = self.img.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle,
1.0)
self.axes5.imshow(result, cmap='gray')
self.canvas5.draw()
def scalling(self):
if self.path1:
ShX = 2
ShY = 1
m, n = self.img.shape
r = m * ShX
c = n * ShY
for x in range(m):
for y in range(n):
self.axes6.imshow(result, cmap='gray')
self.canvas6.draw()
if __name__ == "__main__":
root = tk.Tk()
app = ImageApp(root)
root.mainloop()
Tampilan Hasil