A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_URI::$config is deprecated
Filename: core/URI.php
Line Number: 101
Backtrace:
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Router::$uri is deprecated
Filename: core/Router.php
Line Number: 127
Backtrace:
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$benchmark is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$hooks is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$config is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$log is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$utf8 is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$uri is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$exceptions is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$router is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$output is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$security is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$input is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$lang is deprecated
Filename: core/Controller.php
Line Number: 75
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$load is deprecated
Filename: core/Controller.php
Line Number: 78
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$db is deprecated
Filename: core/Loader.php
Line Number: 396
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_DB_mysqli_driver::$failover is deprecated
Filename: database/DB_driver.php
Line Number: 371
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 132
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 292
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 166
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 235
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 315
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Filename: drivers/Session_files_driver.php
Line Number: 356
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 289
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Session ini settings cannot be changed after headers have already been sent
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Session cannot be started after headers have already been sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$session is deprecated
Filename: core/Loader.php
Line Number: 1283
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$form_validation is deprecated
Filename: core/Loader.php
Line Number: 1283
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 8
Function: __construct
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property Welcome::$m_data is deprecated
Filename: core/Loader.php
Line Number: 358
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 11
Function: model
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$benchmark is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$hooks is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$config is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$log is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$utf8 is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$uri is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$exceptions is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$router is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$output is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$security is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$input is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$lang is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$load is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$db is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$session is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$form_validation is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property CI_Loader::$m_data is deprecated
Filename: core/Loader.php
Line Number: 931
Backtrace:
File: /home/alfe6346/public_html/application/controllers/Welcome.php
Line: 187
Function: view
File: /home/alfe6346/public_html/index.php
Line: 315
Function: require_once
alf-printing Digital-Printing dan Media Pembelajaran
Cepat, Berkualitas, dan Terjangkau
Indonesia
Pengenalan Metode Low-Level Citra
Pengolahan Citra Digital
Pengenalan Metode Low-Level Preprocessing Tujuan: memahami konsep, jenis operasi (resize, crop, Gaussian blur, grayscale), serta contoh implementasi Python (OpenCV).
Menjelaskan konsep dasar pengolahan citra digital. Memahami prinsip metode low-level preprocessing. Menerapkan operasi dasar (resize, crop, blur, grayscale). Menyadari pentingnya preprocessing untuk analisis citra. Pengertian Pengolahan Citra Digital Pengolahan citra digital adalah proses memanipulasi gambar menggunakan algoritma komputer untuk memperbaiki atau mengekstrak informasi dari gambar.
Citra digital direpresentasikan sebagai array numerik:
Grayscale (abu-abu) : 2 dimensi (tinggi × lebar)RGB (berwarna) : 3 dimensi (tinggi × lebar × 3 kanal)Konsep Low-Level Preprocessing Low-Level Preprocessing merupakan tahap awal dalam pengolahan citra yang bekerja langsung pada nilai intensitas piksel. Tujuannya memperbaiki kualitas citra tanpa mengubah maknanya. Proses ini menjadi fondasi bagi tahap middle-level dan high-level processing.
Jenis Operasi Low-Level Preprocessing 1) Resize Menyeragamkan ukuran citra agar konsisten sebagai input model/pipeline.
2) Crop Mengambil area penting dari citra, umumnya pusat atau ROI.
3) Gaussian Blur Menghaluskan citra dan mengurangi noise menggunakan kernel Gaussian.
4) Grayscale Mengubah gambar berwarna menjadi keabuan untuk menyederhanakan analisis.
Contoh Implementasi Python (OpenCV) import cv2
img = cv2.imread('gambar.jpg')
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
resized = cv2.resize(img_rgb, (256, 256))
blurred = cv2.GaussianBlur(resized, (5, 5), 0)
gray = cv2.cvtColor(blurred, cv2.COLOR_RGB2GRAY)
Fungsi Tiap Tahap Resize – Menyeragamkan ukuran.Crop – Fokus pada area penting.Blur – Mengurangi noise .Grayscale – Menyederhanakan warna untuk analisis.Alur Proses Low-Level Preprocessing Citra Asli (RGB) → Resize (256×256) → Crop Tengah (50%) → Gaussian Blur (5×5) → Grayscale → Citra Siap Digunakan
Kaitan dengan Tahap Lain Hasil low-level preprocessing digunakan sebagai input untuk middle-level seperti deteksi tepi, segmentasi, dan ekstraksi fitur. Preprocessing yang baik meningkatkan akurasi dan efisiensi analisis lanjutan.
Contoh Aplikasi Deteksi wajah – citra diubah ke grayscale sebelum dideteksi. OCR – citra difilter dan diubah ke abu-abu sebelum ekstraksi teks. Klasifikasi daun/sel – preprocessing mengurangi noise sebelum segmentasi. Kesimpulan Low-level preprocessing merupakan tahap dasar pengolahan citra digital. Operasi resize, crop, blur, dan grayscale meningkatkan kualitas citra. Hasilnya menentukan keberhasilan analisis lanjutan. Python (OpenCV + Pillow) memudahkan implementasinya. Penerapan 1) Import & Dependensi import os, sys # manipulasi path
import cv2 # OpenCV: resize, GaussianBlur, cvtColor
import tkinter as tk
from tkinter import filedialog, messagebox # GUI & dialog
from PIL import Image, ImageTk # Pillow untuk konversi
import numpy as np # representasi array
2) Penyiapan Path Modul Internal Menambahkan _ROOT_DIR ke sys.path agar paket internal (mis. common.io) dapat diimpor.
3) Kelas PreprocessGUI Mengelola state dan logika GUI (judul, panel kontrol, area tampilan).
4) open_image Dialog pemilihan file & pemuatan gambar, dengan penanganan error.
5) Metode Bantuan _ensure_image memastikan gambar sudah dimuat sebelum operasi.
6) Operasi Citra show_original – tampilkan citra awal.op_resize – ubah ke 256×256.op_crop_center – potong pusat 50%.op_blur_gauss – kernel 5×5.op_gray – RGB → Grayscale.7) Rendering Helpers _render & _fit_image untuk menyesuaikan tampilan dan menjaga kualitas.
8) Entry Point if __name__ == "__main__":
root = tk.Tk()
app = PreprocessGUI(root)
root.mainloop()
9) Alur Eksekusi Singkat User memilih file → tampil “Citra Asli” → pilih operasi (Resize/Crop/Blur/Grayscale) → hasil ditampilkan.
10) Catatan Teknis & Best Practice Konsisten kanal warna (RGB vs BGR) saat konversi. Tahan referensi PhotoImage di atribut agar tidak di-GC. Hindari upscale berlebihan untuk tampilan. 11) Ide Peningkatan Simpan hasil, Undo/Redo. Slider parameter (kernel blur, persentase crop, target size). Info citra (ukuran/tipe) di status bar. Penerapan :
1) Import & Dependensi
import os, sysDigunakan untuk manipulasi path (menambahkan root project ke sys.path agar modul internal bisa diimpor).
import cv2OpenCV untuk operasi gambar: resize, GaussianBlur, cvtColor.
import tkinter as tk dan from tkinter import filedialog, messageboxTkinter membangun GUI; filedialog untuk memilih file gambar; messagebox untuk pesan error/info.
from PIL import Image, ImageTkPillow untuk konversi array NumPy ↔ object Image dan adaptor ImageTk.PhotoImage yang bisa ditempel ke tk.Label.
import numpy as npRepresentasi citra sebagai array numerik.
2) Penyiapan Path Modul Internal
Gambar 1 Tujuan: memastikan package internal (common.io) dapat diimpor saat file ini dijalankan langsung.
_FILE_DIR = folder tempat file ini berada.
_ROOT_DIR = satu tingkat di atasnya (diasumsikan folder project).
Menambahkan _ROOT_DIR ke sys.path agar Python dapat menemukan paket common.
from common.io import read_image
Mengimpor helper pembaca gambar (diasumsikan mengembalikan RGB sebagai np.ndarray).
3) Deklarasi Kelas: PreprocessGUI
class PreprocessGUI:
Fungsi: menampung seluruh state dan logika GUI (MVP sederhana).
3.1 Konstruktor: __init__(self, root)
Parameter:root — instance tk.Tk() (jendela utama).
Judul window:self.root.title("Preprocess - Resize, Crop, Blur").
State
self.img_rgb: np.ndarray | None = None
self.photo: ImageTk.PhotoImage | None = None
img_rgb menyimpan citra saat ini dalam format RGB (atau None jika belum ada).
photo menyimpan objek PhotoImage terakhir agar tidak di-garbage collected (wajib dalam Tkinter).
Top Bar
Gambar 2 Frame baris atas untuk tombol “Buka Gambar...” dan label status path.
command=self.open_image menghubungkan klik tombol ke metode pembuka file.
Panel Kontrol Operasi
Gambar 3 LabelFrame sebagai container berjudul “Operasi Preprocess”.
btn_specs mendefinisikan label tombol dan callback-nya.
Loop membuat tombol untuk tiap operasi.
Area Tampilan
Gambar 4 title_label menampilkan judul/teks status operasi terkini (mis. “Resize 256x256”).
img_label adalah kanvas sederhana yang menempelkan PhotoImage (gambar hasil proses).
4) Metode: open_image(self)
Dialog pemilihan file dan pemuatan gambar.
Gambar 5 Memunculkan dialog untuk memilih file gambar (filter beberapa ekstensi umum).
Memakai read_image untuk membaca ke RGB ndarray.
Menangani error dengan messagebox.showerror.
Menyimpan path di label status dan langsung menampilkan citra asli.
5) Metode Bantuan: _ensure_image(self) -> bool
Gambar 6 Guard: memastikan ada gambar yang dimuat sebelum menjalankan operasi apa pun.
6) Operasi Citra
6.1 show_original(self)
Menampilkan citra self.img_rgb apa adanya.
Memanggil _render(..., title="Citra Asli (RGB)").
6.2 op_resize(self)
Gambar 7 Resize menjadi 256×256 piksel (interpolasi default OpenCV: bilinear untuk mengecil & membesar).
6.3 op_crop_center(self)
Gambar 8 Mengambil kotak pusat 50% (memotong 25% dari tiap sisi).
Menggunakan slicing NumPy: img[rows, cols].
6.4 op_blur_gauss(self)
blurred = cv2.GaussianBlur(self.img_rgb, (5, 5), 0)
self._render(blurred, title="Gaussian Blur (5x5)")
Gaussian blur kernel 5×5, sigmaX=0 → dihitung otomatis dari kernel size.
6.5 op_gray(self)
gray = cv2.cvtColor(self.img_rgb, cv2.COLOR_RGB2GRAY)
self._render(gray, title="Grayscale")
Konversi RGB → Grayscale.
Hasil array 2D (1 channel, dtype sama/di-cast ke uint8 saat render).
7) Rendering Helpers
7.1 _render(self, img: np.ndarray, title: str = "")
Gambar 9 Menerima array NumPy (grayscale 2D atau RGB 3D).
Pastikan tipe uint8, buat PIL.Image.
Menyesuaikan ukuran tampilan agar tidak lewat dari 960×600 (tanpa upscale berlebihan).
Simpan ke self.photo (mencegah GC), lalu set ke img_label.
Update judul operasi.
7.2 _fit_image(im: Image.Image, max_w: int, max_h: int) -> Image.Image (staticmethod)
Gambar 10 Hitung faktor skala agar fit di dalam bounding box max_w × max_h tanpa distorsi.
min(..., 1.0) mencegah upscale (hanya downscale).
Gunakan filter LANCZOS untuk kualitas downscale bagus.
8) Entry Point (Main Guard)
if __name__ == "__main__":
root = tk.Tk()
app = PreprocessGUI(root)
root.mainloop()
Membuat jendela Tkinter, instantiate GUI, dan menjalankan event loop.
9) Alur Eksekusi Singkat
User klik Buka Gambar… → pilih file → read_image memuat array RGB → tampil “Citra Asli”.
User menekan salah satu tombol operasi:
Resize → 256×256.
Crop Tengah → 50% pusat.
Gaussian Blur → penghalusan.
Grayscale → ubah ke abu-abu.
Hasil ditampilkan di img_label, judul operasi diperbarui di title_label.
10) Catatan Teknis & Best Practice
RGB vs BGR:OpenCV lazimnya memakai BGR, tapi di sini diasumsikan read_image mengembalikan RGB. Konsisten karena:
cv2.GaussianBlur bekerja independen dari urutan kanal.
cvtColor(..., COLOR_RGB2GRAY) sudah benar untuk RGB.Pastikan read_image tidak mengembalikan BGR; jika BGR, ganti konversi ke COLOR_BGR2GRAY.
Type Hints:np.ndarray | None butuh Python 3.10+ (operator |). Untuk 3.9, gunakan Optional[np.ndarray].
Menahan Referensi Gambar:self.photo wajib disimpan sebagai atribut; jika lokal, gambar tak tampil (di-GC).
Resizing untuk Tampilan:_fit_image menghindari citra terlalu besar untuk GUI, menjaga performa dan layout.
Error Handling:Sudah ada try/except baca gambar. Anda bisa tambah validasi tipe/shape.
Responsiveness:Saat ini layout memakai .pack(). Untuk UI lebih adaptif, bisa kombinasi pack/grid dan atur expand=True, fill=tk.BOTH.
11) Ide Peningkatan (opsional)
Simpan Hasil: tambah tombol “Simpan Sebagai…” (filedialog.asksaveasfilename) + PIL.Image.save. Undo/Redo: simpan stack riwayat operasi. Parameterisasi: sediakan slider kernel blur, ukuran crop persentase, target resize. Drag & Drop: pakai binding OS untuk drop file langsung ke jendela. Info Citra: tampilkan ukuran & tipe di status. Kalau Anda mau, saya bisa menambahkan komentar inline langsung ke dalam kode atau membuat versi dengan tombol Simpan dan slider parameter.