0% found this document useful (0 votes)
22 views11 pages

Format Tugas PCD

Uploaded by

Evaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

Format Tugas PCD

Uploaded by

Evaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

TUGAS BAB 4

OPERASI BOOLEAN & OPERASI GEOMETRIK


PENGOLAHAN CITRA
NIM : 2318016

NAMA : Eva Ristiyanti

KELAS : B

PENGAJAR : Nayaka Apta Nayottama (2218102

MATERI : Pengenalan Citra dan Python

TUGAS : 1. Perhitungan Operasi Translasi dan Scalling


2. Membuat GUI

4.1 Alat dan Bahan


1. Laptop
2. Visual Studio Code
3. Modul Pengolahan Citra Digital 2024
4.2 Tujuan
1. Praktikan dapat memahami Operasi Translasi dan Scalling
2. Praktikan dapat mengimplementasikan GUI
4.3 Langkah-langkah Tugas
A. Tugas perhitungan Operasi Translasi dan Scalling
1. Operasi Translasi Nim Genap
Citra Input :
120 144 59 43 53
60 10 108 71 23
63 13 18 34 20
58 18 106 96 27
50 75 42 30 52
Perhitungan :
x’ = x + Tx y’ = y + Ty
Tx = 7 Ty = 3
120 (1, 1) = (1 + 7, 1 + 3) = (8, 4)
144 (1, 2) = (1 + 7, 2 + 3) = (8, 5)
59 (1, 3) = (1 + 7, 3 + 3) = (8, 6)
43 (1, 4) = (1 + 7, 4 + 3) = (8, 7)
53 (1, 5) = (1 + 7, 5 + 3) = (8, 8)
60 (2, 1) = (2 + 7, 1 + 3) = (9, 4)
10 (2, 2) = (2 + 7, 2 + 3) = (9, 5)
108 (2, 3) = (2 + 7, 3 + 3) = (9, 6)
71 (2, 4) = (2 + 7, 4 + 3) = (9, 7)
23 (2, 5) = (2 + 7, 5 + 3) = (9, 8)
63 (3, 1) = (3 + 7, 1 + 3) = (10, 4)
13 (3, 2) = (3 + 7, 2 + 3) = (10, 5)
18 (3, 3) = (3 + 7, 3 + 3) = (10, 6)
34 (3, 4) = (3 + 7, 4 + 3) = (10, 7)
20 (3, 5) = (3 + 7, 5 + 3) = (10, 8)
58 (4, 1) = (4 + 7, 1 + 3) = (11, 4)
18 (4, 2) = (4 + 7, 2 + 3) = (11, 5)
106 (4, 3) = (4 + 7, 3 + 3) = (11, 6)
96 (4, 4) = (4 + 7, 4 + 3) = (11, 7)
27 (4, 5) = (4 + 7, 5 + 3) = (11, 8)
50 (5, 1) = (5 + 7, 1 + 3) = (12, 4)
75 (5, 2) = (5 + 7, 2 + 3) = (12, 5)
42 (5, 3) = (5 + 7, 3 + 3) = (12, 6)
30 (5, 4) = (5 + 7, 4 + 3) = (12, 7)
52 (5, 5) = (5 + 7, 5 + 3) = (12, 8)
Citra Output :
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 120 14 59 43 53
4
0 0 0 60 10 108 71 23
0 0 0 63 13 18 34 20
0 0 0 58 18 106 96 27
0 0 0 50 75 42 30 52
2. Operasi Scalling Nim Genap
Citra Input :
120 144 59 43 53
60 10 108 71 23
63 13 18 34 20
58 18 106 96 27
50 75 42 30 52
Perhitungan :
x’ = ShX * x y’ = ShY * y
ShX = 6 ShY = 4
120 (1, 1) = (6 * 1, 4 * 1) = (6, 4)
144 (1, 2) = (6 * 1, 4 * 2) = (6, 8)
59 (1, 3) = (6 * 1, 4 * 3) = (6, 12)
43 (1, 4) = (6 * 1, 4 * 4) = (6, 16)
53 (1, 5) = (6 * 1, 4 * 5) = (6, 20)
60 (2, 1) = (6 * 2, 4 * 1) = (12, 4)
10 (2, 2) = (6 * 2, 4 * 2) = (12, 8)
108 (2, 3) = (6 * 2, 4 * 3) = (12, 12)
71 (2, 4) = (6 * 2, 4 * 4) = (12, 16)
23 (2, 5) = (6 * 2, 4 * 5) = (12, 20)
63 (3, 1) = (6 * 3, 4 * 1) = (18, 4)
13 (3, 2) = (6 * 3, 4 * 2) = (18, 8)
18 (3, 3) = (6 * 3, 4 * 3) = (18, 12)
34 (3, 4) = (6 * 3, 4 * 4) = (18, 16)
20 (3, 5) = (6 * 3, 4 * 5) = (18, 20)
58 (4, 1) = (6 * 4, 4 * 1) = (24, 4)
18 (4, 2) = (6 * 4, 4 * 2) = (24, 8)
106 (4, 3) = (6 * 4, 4 * 3) = (24, 12)
96 (4, 4) = (6 * 4, 4 * 4) = (24, 16)
27 (4, 5) = (6 * 4, 4 * 5) = (24, 20)
50 (5, 1) = (6 * 5, 4 * 1) = (30, 4)
75 (5, 2) = (6 * 5, 4 * 2) = (30, 8)
42 (5, 3) = (6 * 5, 4 * 3) = (30, 12)
30 (5, 4) = (6 * 5, 4 * 4) = (30, 16)
52 (5, 5) = (6 * 5, 4 * 5) = (30, 20)
Citra Output :
B. Tugas Program Membuat GUI
Source Code :
import cv2

import os

import tkinter as tk

from tkinter import filedialog

from PIL import Image, ImageTk

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.backends.backend_tkagg import


FigureCanvasTkAgg

class ImageApp:

path1 = ''

def __init__(self, root):

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.frame1.pack(side=tk.LEFT, padx=5, pady=5)

self.figure1 = plt.Figure(figsize=(4, 3), dpi=50)

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.frame2.pack(side=tk.LEFT, padx=5, pady=5)

self.figure2 = plt.Figure(figsize=(4, 3), dpi=50)

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.frame3.pack(side=tk.LEFT, padx=5, pady=5)

self.figure3 = plt.Figure(figsize=(4, 3), dpi=50)

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.figure4 = plt.Figure(figsize=(4, 3), dpi=50)

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.frame5.pack(side=tk.LEFT, padx=5, pady=5)

self.figure5 = plt.Figure(figsize=(4, 3), dpi=50)

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.frame6.pack(side=tk.LEFT, padx=5, pady=5)

self.figure6 = plt.Figure(figsize=(4, 3), dpi=50)

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

result = np.zeros((r + Tx, c + Ty),


dtype=np.uint8)

for x in range(r):

for y in range(c):

result[x + Tx, y + Ty] = self.img[x,


y]

self.axes2.imshow(result, cmap='gray')

self.canvas2.draw()
def cropping(self):

if self.path1:

x, y, w, h = 50, 50, 150, 150

result = self.img[y:y+h, x:x+w]

self.axes3.imshow(result, cmap='gray')

self.canvas3.draw()

def flipping(self):

if self.path1:

r, c = self.img.shape

result = np.zeros((r, c), dtype=np.uint8)

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)

result = cv2.warpAffine(self.img, M, (w, h))

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

result = np.zeros((r, c), dtype=np.uint8)

for x in range(m):

for y in range(n):

result[x * ShX : (x + 1) * ShX, y *


ShY : (y + 1) * ShY] = self.img[x, y]

self.axes6.imshow(result, cmap='gray')

self.canvas6.draw()

if __name__ == "__main__":

root = tk.Tk()

app = ImageApp(root)

root.mainloop()

Tampilan Hasil

Gambar 4.1 Tampilan Implementasi Operai GUI


Analisa :
Kode di atas menampilkan gambar dalam format grayscale dan
melakukan trasnformasi seperti translasi, cropping, flipping, rotasi, dan
scaling. Dengan enam frame terpisah untuk setiap operasi, pengguna dapat
memuat gambar, kemudian menerapkan translasi, cropping, flipping,
rotasi, dan scalling. Hasil setiap operasi ditampilkan dan gambar diambil
dari penyimpanan pengguna dan di olah dalam format grayscale.

You might also like