SlideShare une entreprise Scribd logo
1  sur  20
LAPORAN WORKSHOP KOMPUTER VISI
LINEAR FILTER DAN EDGE DETECTION
LUSIANA DIYAN NINGRUM
2210181051
3 D4 TEKNIK KOMPUTER B
PRODI SARJANA TERAPAN TEKNIK KOMPUTER
DEPARTEMEN TEKNIK INFORMATIKA DAN KOMPUTER
POLITEKNIK ELEKTRONIKA NEGERI SURABAYA
SURABAYA
KONVOLUSI
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat kernel;
Point anchor;
double delta=0;
int ddepth=-1;
int kernel_size=2;
// Initialize arguments for the filter
anchor = Point(1, 1);
Mat img = imread("E:/trial/trial/view.jpg", 17), hasil,
img_gray = imread("E:/trial/trial/view.jpg", 16);
// Loop - Will filter the image with different kernel sizes each 0.5 seconds
int ind = 0;
// Update kernel size for a normalized box filter
kernel = Mat::ones(kernel_size, kernel_size, CV_32F) /
(float)(kernel_size*kernel_size);
// Apply filter
filter2D(img, hasil, ddepth, kernel, anchor, delta, BORDER_DEFAULT);
imshow("Source RGB", img);
imshow("Hasil RGB", hasil);
filter2D(img_gray, hasil, ddepth, kernel, anchor, delta, BORDER_DEFAULT);
imshow("Source Gray", img_gray);
imshow("Hasil Gray", hasil);
waitKey();
return EXIT_SUCCESS;
}
1/2
1/3
1/5
1/9
1/15
ANALISA
konvolusi adalah operasi matematis citra digital, yaitu mengalikan sebuah citra dengan
sebuah mask atau kernel atau filter atau template. Konvolusi berguna untuk perbaikan
kualitas citra, mengurangi noise, distorsi deteksi, menghaluskan suatu citra atau memperjelas
citra dengan menggantikan nilai piksel dengan sejumlah nilai piksel yang sesuai atau
berdekatan dengan piksel aslinya. Dengan adanya konvolusi ini dapat menghaluskan atau
menghilangkan noise pada image sehingga image terlihat lebih kabur kontrasnya karena
konvolusi memiliki efek pemerataan derajat keabuan. Dapat dilihat dari gambar hasil
percobaan bahwa semakin kecil pengalinya maka gambar yang dihasilkan semakin smooth
atau gambar lebih kabur, sebagai contoh gambar yang dikonvolusi 1/15 lebih kabur hasilnya
dibandingkan image yang dikonvolusi sebesar 1/5.
GAUSSIAN FILTER
1. Image File
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img = imread("E:/trial/trial/view.jpg", 17),
grayImg = imread("E:/trial/trial/view.jpg", 16);
imshow("Original Image", img);
imshow("Gray Image", grayImg);
Mat Gfilter, Gfiltergray;
GaussianBlur(img, Gfilter, Size(5, 5), 8, 0);
imwrite("E:/trial/trial/GBlur.jpg", Gfilter);
imshow("Gausian Blur", Gfilter);
GaussianBlur(grayImg, Gfiltergray, Size(5, 5), 8, 0);
imwrite("E:/trial/trial/GBlur.jpg", Gfiltergray);
imshow("Gray Gausian Blur", Gfiltergray);
waitKey();
return EXIT_SUCCESS;
}
5
10
2. Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame, gray_frame, hasil;
cap >> frame;
cap.read(frame);
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
char c = (char)waitKey(1);
if (c == 27)
break;
cout << "Default Cols : " << frame.cols << endl;
cout << "Default Rows : " << frame.rows << endl << endl;
GaussianBlur(frame, hasil, Size(3, 3), 8, 0);
imwrite("GBlur.jpg", hasil);
/// Display
imshow("CAMERA", frame);
imshow("Gaussian Blur", hasil);
}
waitKey();
return EXIT_SUCCESS;
}
ANALISA
Pengolahan citra dengan menggunakan efek gaussian blur menyebabkan suatu citra menjadi
kabur sehingga sudut-sudut tajam pada citra akan menjadi lebih halus. Seperti pada gambar
hasil percobaan bahwa image yang mendapatkan efek gausian blur sebesar 10 memiliki sudut
– sudut image yang lebih halus atau mengabur dibandingkan dengan citra yang memperoleh
efek Gaussian sebesar 3. Semakin besar nilai efek Gaussian yang diberikan maka citra
gambar akan semakin halus dan sudut – sudut pada gambar (edge) terlihat lebih mengabur
sehingga image terlihat blur.
BILATERAL FILTER
1. Image File
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img = imread("E:/trial/trial/view.jpg", 17),
grayImg = imread("E:/trial/trial/view.jpg", 16);
imshow("Original Image", img);
imshow("Gray Image", grayImg);
Mat Bfilter, Bfiltergray;
bilateralFilter(img, Bfilter, 3, 3, 3);
imwrite("E:/trial/trial/GBlur1.jpg", Bfilter);
imshow("Bilateral Filtering", Bfilter);
bilateralFilter(grayImg, Bfiltergray, 3, 3, 3);
imwrite("E:/trial/trial/GBlur1.jpg", Bfiltergray);
imshow("Gray Bilateral Filtering", Bfiltergray);
waitKey();
return EXIT_SUCCESS;
}
8
15
ANALISA
Filter bilateral adalah filter penghalusan non-linier , menjaga tepi , dan mengurangi noise
untuk gambar . Ini menggantikan intensitas setiap piksel dengan nilai intensitas rata-rata
tertimbang dari piksel terdekat. Bobot ini dapat didasarkan pada distribusi Gaussian.
Implementasi filter bilateral pada citra image di atas adalah menghaluskan tepi gambar
sehingga semakin halus penampang dari citra.
2. Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame, gray_frame, hasil;
cap >> frame;
cap.read(frame);
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
char c = (char)waitKey(1);
if (c == 27)
break;
cout << "Default Cols : " << frame.cols << endl;
cout << "Default Rows : " << frame.rows << endl << endl;
bilateralFilter(frame, hasil, 3, 3, 3);
imwrite("GBlur.jpg", hasil);
/// Display
imshow("CAMERA", frame);
imshow("Bilateral Gray", gray_frame);
imshow("Bilateral Color", hasil);
}
waitKey();
return EXIT_SUCCESS;
}
EDGE DETECTION
1. Image
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img2 = imread("E:/trial/trial/sakura.jpg", CV_LOAD_IMAGE_COLOR),
edges;
int width = img2.cols, height = img2.rows;
imshow("Source Image", img2);
cout << "Default Cols : " << img2.cols << endl;
cout << "Default Rows : " << img2.rows << endl << endl;
Canny(img2, edges, 20, 60);
imshow("Canny RGB", edges);
imwrite("cany2.jpg", edges);
waitKey();
return EXIT_SUCCESS;
}
20,40
30,90
40,120
ANALISA
Tepi suatu obyek dalam citra dinyatakan sebagai titik yang nilai keabuannya berbeda
cukup besar dengan titik yang ada di sebelahnya. Parameter angka di dalam fungsi Canny
berguna untuk mengatur kerapatan program dalam mendeteksi tepi. Semakin besar nilai
parameter maka jangkauan tepi yang dideteksi semakin luas, sebaliknya semakin kecil
nilai parameter akan menghasilkan deteksi tepi yang rapat.
2. Livecam
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture cap(0);
if (cap.isOpened() == false)
{
cout << "Cannot open the video file" << endl;
cin.get();
return -1;
}
while (1)
{
Mat frame, gray_frame, edges;
cap >> frame;
cap.read(frame);
cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
char c = (char)waitKey(1);
if (c == 27)
break;
cout << "Default Cols : " << frame.cols << endl;
cout << "Default Rows : " << frame.rows << endl << endl;
Canny(frame, edges, 20, 60);
imwrite("canny2.jpg", edges);
/// Display
imshow("CAMERA", frame);
imshow("Canny", edges);
}
waitKey();
return EXIT_SUCCESS;
}
Teori Metode Pyramids => Piramida , atau representasi piramida , adalah jenis representasi
sinyal multi-skala yang dikembangkan oleh visi komputer , komunitas pemrosesan gambar
dan pemrosesan sinyal , di mana sinyal atau gambar dikenakan perataan dan subsampling
berulang. Representasi piramida adalah pendahulu dari representasi skala-ruang dan analisis
multiresolusi .
Program Downsampling (Gaussian Pyramid Down)
Program ini mengunakan fungsi PyrDown dengan melakukan downsampling pada
dekomposisi (pemecahan) Gaussian pyramid. Pertama dilakukan konvolusi pada image
dengan filter tertentu. Kemudian dilakukan downsampling pada gambar dengan menghapus
baris dan and kolom yang genap.
Program Upsampling (Gaussian Pyramid Up)
Program ini mengunakan fungsi PyrUp dengan melakukan up-sampling pada pemecahan
Gaussian pyramid. Pertama dilakukan up-sampling pada gambar dengan memasukkan nilai
kosong pada baris dan and kolom yang genap. Kemudian dilakukan konvolusi pada image
dengan filter “multiplied by 4” untuk interpolasi (penambahan). Jadi gambar lebih besar 4
kali dari gambar asal.
#include <opencv2opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/calib3d.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img2 = imread("E:/trial/trial/sakura.jpg", CV_LOAD_IMAGE_COLOR),
hasil;
int width = img2.cols, height = img2.rows;
imshow("Source Image", img2);
pyrUp(img2, hasil, Size(width * 2, height * 2));
cout << "PyramidUp_1 Kolom / Lebar = " << hasil.cols << endl;
cout << "PyramidUp_1 Baris / Tinggi = " << hasil.rows << endl;
imwrite("Pyramid1.jpg", hasil);
imshow("Pyramid1", hasil);
pyrUp(hasil, hasil, Size(width * 4, height * 4));
cout << "PyramidUp_2 Kolom / Lebar = " << hasil.cols << endl;
cout << "PyramidUp_2 Baris / Tinggi = " << hasil.cols << endl;
imwrite("Pyramid2.jpg", hasil);
imshow("Pyramid2", hasil);
waitKey();
return EXIT_SUCCESS;
}
pyrUp(hasil, hasil, Size(width * 2, height * 2));
cout << "PyramidUp_2 Kolom / Lebar = " << hasil.cols << endl;
cout << "PyramidUp_2 Baris / Tinggi = " << hasil.cols << endl;
imwrite("Pyramid2.jpg", hasil);
Linear Filter dan Edge Detection

Contenu connexe

Similaire à Linear Filter dan Edge Detection

Similaire à Linear Filter dan Edge Detection (20)

Dasar dasar pemrograman
Dasar dasar pemrogramanDasar dasar pemrograman
Dasar dasar pemrograman
 
Jeni Intro2 Bab11 Applet
Jeni Intro2 Bab11 AppletJeni Intro2 Bab11 Applet
Jeni Intro2 Bab11 Applet
 
How to hack #IDSECCONF2014 ctf online challenge - nganggur
How to hack #IDSECCONF2014 ctf online challenge - nganggurHow to hack #IDSECCONF2014 ctf online challenge - nganggur
How to hack #IDSECCONF2014 ctf online challenge - nganggur
 
Pertemuan 10 Pointer dan Macro
Pertemuan 10 Pointer dan MacroPertemuan 10 Pointer dan Macro
Pertemuan 10 Pointer dan Macro
 
Makalah d2
Makalah d2Makalah d2
Makalah d2
 
Duatitik
DuatitikDuatitik
Duatitik
 
FreeBSD Basic Setting
FreeBSD Basic SettingFreeBSD Basic Setting
FreeBSD Basic Setting
 
Intruksi Fundamental
Intruksi FundamentalIntruksi Fundamental
Intruksi Fundamental
 
Program 2 lampu kedip
Program 2 lampu kedipProgram 2 lampu kedip
Program 2 lampu kedip
 
sp243-061043-959-1.ppt
sp243-061043-959-1.pptsp243-061043-959-1.ppt
sp243-061043-959-1.ppt
 
Pertemuan 6 Fungsi String
Pertemuan 6 Fungsi StringPertemuan 6 Fungsi String
Pertemuan 6 Fungsi String
 
FreeBSD Proxy Server
FreeBSD Proxy ServerFreeBSD Proxy Server
FreeBSD Proxy Server
 
Pertemuan1 - PHP Dasar
Pertemuan1 - PHP DasarPertemuan1 - PHP Dasar
Pertemuan1 - PHP Dasar
 
Fuzzyfikasi
FuzzyfikasiFuzzyfikasi
Fuzzyfikasi
 
Perkenalan Pemrograman C++
Perkenalan Pemrograman C++Perkenalan Pemrograman C++
Perkenalan Pemrograman C++
 
bab_v_percabangan.pdf
bab_v_percabangan.pdfbab_v_percabangan.pdf
bab_v_percabangan.pdf
 
Cbq
CbqCbq
Cbq
 
Algoritma dan Pemrograman C++ (Program Structure)
Algoritma dan Pemrograman C++ (Program Structure)Algoritma dan Pemrograman C++ (Program Structure)
Algoritma dan Pemrograman C++ (Program Structure)
 
FreeBSD Bandwidth Management
FreeBSD Bandwidth ManagementFreeBSD Bandwidth Management
FreeBSD Bandwidth Management
 
fungsi algoritma
fungsi algoritmafungsi algoritma
fungsi algoritma
 

Plus de Lusiana Diyan

Komunikasi Bisnis yang Efektif
Komunikasi Bisnis yang EfektifKomunikasi Bisnis yang Efektif
Komunikasi Bisnis yang EfektifLusiana Diyan
 
Berkomunikasi dalam Tim
Berkomunikasi dalam TimBerkomunikasi dalam Tim
Berkomunikasi dalam TimLusiana Diyan
 
Berkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan KeragamanBerkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan KeragamanLusiana Diyan
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan BisnisLusiana Diyan
 
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan BisnisKemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan BisnisLusiana Diyan
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan BisnisLusiana Diyan
 
Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3Lusiana Diyan
 
Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2Lusiana Diyan
 
Vocabulary Engineering Enrichment
Vocabulary Engineering EnrichmentVocabulary Engineering Enrichment
Vocabulary Engineering EnrichmentLusiana Diyan
 
DESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENTDESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENTLusiana Diyan
 
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan CoppeliasimTutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan CoppeliasimLusiana Diyan
 
CRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQLCRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQLLusiana Diyan
 
Kontrol LED melalui Web Server
Kontrol LED melalui Web ServerKontrol LED melalui Web Server
Kontrol LED melalui Web ServerLusiana Diyan
 
Akses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry PiAkses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry PiLusiana Diyan
 
Building A Simple Robot in VREP
Building A Simple Robot in VREPBuilding A Simple Robot in VREP
Building A Simple Robot in VREPLusiana Diyan
 
Tutorial Menggunakan Software Eagle
Tutorial Menggunakan Software EagleTutorial Menggunakan Software Eagle
Tutorial Menggunakan Software EagleLusiana Diyan
 
Proses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat LunakProses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat LunakLusiana Diyan
 
Produk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat LunakProduk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat LunakLusiana Diyan
 
Open Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DCOpen Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DCLusiana Diyan
 

Plus de Lusiana Diyan (20)

Komunikasi Bisnis yang Efektif
Komunikasi Bisnis yang EfektifKomunikasi Bisnis yang Efektif
Komunikasi Bisnis yang Efektif
 
Berkomunikasi dalam Tim
Berkomunikasi dalam TimBerkomunikasi dalam Tim
Berkomunikasi dalam Tim
 
Berkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan KeragamanBerkomunikasi di Dunia dengan Keragaman
Berkomunikasi di Dunia dengan Keragaman
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan Bisnis
 
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan BisnisKemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
Kemampuan Berkomunikasi 6 - Menyelesaikan Pesan Bisnis
 
Menulis Pesan Bisnis
Menulis Pesan BisnisMenulis Pesan Bisnis
Menulis Pesan Bisnis
 
Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3Vocabulary Engineering Enrichment 3
Vocabulary Engineering Enrichment 3
 
Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2Vocabulary Engineering Enrichment 2
Vocabulary Engineering Enrichment 2
 
Vocabulary Engineering Enrichment
Vocabulary Engineering EnrichmentVocabulary Engineering Enrichment
Vocabulary Engineering Enrichment
 
DESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENTDESIGN THINGKING & PROJECT MANAGEMENT
DESIGN THINGKING & PROJECT MANAGEMENT
 
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan CoppeliasimTutorial Membuat Simple Crane Menggunakan Coppeliasim
Tutorial Membuat Simple Crane Menggunakan Coppeliasim
 
CRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQLCRUD pada Android Studio menggunakan MySQL
CRUD pada Android Studio menggunakan MySQL
 
Kontrol LED melalui Web Server
Kontrol LED melalui Web ServerKontrol LED melalui Web Server
Kontrol LED melalui Web Server
 
Installasi NodeMCU
Installasi NodeMCUInstallasi NodeMCU
Installasi NodeMCU
 
Akses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry PiAkses GPIO pada Raspberry Pi
Akses GPIO pada Raspberry Pi
 
Building A Simple Robot in VREP
Building A Simple Robot in VREPBuilding A Simple Robot in VREP
Building A Simple Robot in VREP
 
Tutorial Menggunakan Software Eagle
Tutorial Menggunakan Software EagleTutorial Menggunakan Software Eagle
Tutorial Menggunakan Software Eagle
 
Proses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat LunakProses Rekayasa Perangkat Lunak
Proses Rekayasa Perangkat Lunak
 
Produk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat LunakProduk Rekasaya Perangkat Lunak
Produk Rekasaya Perangkat Lunak
 
Open Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DCOpen Loop Analog Control System - Motor DC
Open Loop Analog Control System - Motor DC
 

Linear Filter dan Edge Detection

  • 1. LAPORAN WORKSHOP KOMPUTER VISI LINEAR FILTER DAN EDGE DETECTION LUSIANA DIYAN NINGRUM 2210181051 3 D4 TEKNIK KOMPUTER B PRODI SARJANA TERAPAN TEKNIK KOMPUTER DEPARTEMEN TEKNIK INFORMATIKA DAN KOMPUTER POLITEKNIK ELEKTRONIKA NEGERI SURABAYA SURABAYA
  • 2. KONVOLUSI #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat kernel; Point anchor; double delta=0; int ddepth=-1; int kernel_size=2; // Initialize arguments for the filter anchor = Point(1, 1); Mat img = imread("E:/trial/trial/view.jpg", 17), hasil, img_gray = imread("E:/trial/trial/view.jpg", 16); // Loop - Will filter the image with different kernel sizes each 0.5 seconds int ind = 0; // Update kernel size for a normalized box filter kernel = Mat::ones(kernel_size, kernel_size, CV_32F) / (float)(kernel_size*kernel_size); // Apply filter filter2D(img, hasil, ddepth, kernel, anchor, delta, BORDER_DEFAULT); imshow("Source RGB", img); imshow("Hasil RGB", hasil); filter2D(img_gray, hasil, ddepth, kernel, anchor, delta, BORDER_DEFAULT); imshow("Source Gray", img_gray); imshow("Hasil Gray", hasil); waitKey(); return EXIT_SUCCESS; } 1/2
  • 5. ANALISA konvolusi adalah operasi matematis citra digital, yaitu mengalikan sebuah citra dengan sebuah mask atau kernel atau filter atau template. Konvolusi berguna untuk perbaikan kualitas citra, mengurangi noise, distorsi deteksi, menghaluskan suatu citra atau memperjelas citra dengan menggantikan nilai piksel dengan sejumlah nilai piksel yang sesuai atau berdekatan dengan piksel aslinya. Dengan adanya konvolusi ini dapat menghaluskan atau menghilangkan noise pada image sehingga image terlihat lebih kabur kontrasnya karena konvolusi memiliki efek pemerataan derajat keabuan. Dapat dilihat dari gambar hasil percobaan bahwa semakin kecil pengalinya maka gambar yang dihasilkan semakin smooth atau gambar lebih kabur, sebagai contoh gambar yang dikonvolusi 1/15 lebih kabur hasilnya dibandingkan image yang dikonvolusi sebesar 1/5. GAUSSIAN FILTER 1. Image File #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat img = imread("E:/trial/trial/view.jpg", 17), grayImg = imread("E:/trial/trial/view.jpg", 16);
  • 6. imshow("Original Image", img); imshow("Gray Image", grayImg); Mat Gfilter, Gfiltergray; GaussianBlur(img, Gfilter, Size(5, 5), 8, 0); imwrite("E:/trial/trial/GBlur.jpg", Gfilter); imshow("Gausian Blur", Gfilter); GaussianBlur(grayImg, Gfiltergray, Size(5, 5), 8, 0); imwrite("E:/trial/trial/GBlur.jpg", Gfiltergray); imshow("Gray Gausian Blur", Gfiltergray); waitKey(); return EXIT_SUCCESS; } 5
  • 7. 10 2. Livecam #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { VideoCapture cap(0); if (cap.isOpened() == false) { cout << "Cannot open the video file" << endl; cin.get(); return -1; } while (1) { Mat frame, gray_frame, hasil; cap >> frame; cap.read(frame); cvtColor(frame, gray_frame, COLOR_BGR2GRAY); char c = (char)waitKey(1); if (c == 27) break; cout << "Default Cols : " << frame.cols << endl; cout << "Default Rows : " << frame.rows << endl << endl;
  • 8. GaussianBlur(frame, hasil, Size(3, 3), 8, 0); imwrite("GBlur.jpg", hasil); /// Display imshow("CAMERA", frame); imshow("Gaussian Blur", hasil); } waitKey(); return EXIT_SUCCESS; } ANALISA Pengolahan citra dengan menggunakan efek gaussian blur menyebabkan suatu citra menjadi kabur sehingga sudut-sudut tajam pada citra akan menjadi lebih halus. Seperti pada gambar hasil percobaan bahwa image yang mendapatkan efek gausian blur sebesar 10 memiliki sudut – sudut image yang lebih halus atau mengabur dibandingkan dengan citra yang memperoleh efek Gaussian sebesar 3. Semakin besar nilai efek Gaussian yang diberikan maka citra gambar akan semakin halus dan sudut – sudut pada gambar (edge) terlihat lebih mengabur sehingga image terlihat blur. BILATERAL FILTER 1. Image File #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat img = imread("E:/trial/trial/view.jpg", 17), grayImg = imread("E:/trial/trial/view.jpg", 16); imshow("Original Image", img); imshow("Gray Image", grayImg); Mat Bfilter, Bfiltergray;
  • 9. bilateralFilter(img, Bfilter, 3, 3, 3); imwrite("E:/trial/trial/GBlur1.jpg", Bfilter); imshow("Bilateral Filtering", Bfilter); bilateralFilter(grayImg, Bfiltergray, 3, 3, 3); imwrite("E:/trial/trial/GBlur1.jpg", Bfiltergray); imshow("Gray Bilateral Filtering", Bfiltergray); waitKey(); return EXIT_SUCCESS; } 8
  • 10. 15 ANALISA Filter bilateral adalah filter penghalusan non-linier , menjaga tepi , dan mengurangi noise untuk gambar . Ini menggantikan intensitas setiap piksel dengan nilai intensitas rata-rata tertimbang dari piksel terdekat. Bobot ini dapat didasarkan pada distribusi Gaussian. Implementasi filter bilateral pada citra image di atas adalah menghaluskan tepi gambar sehingga semakin halus penampang dari citra. 2. Livecam #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { VideoCapture cap(0); if (cap.isOpened() == false) { cout << "Cannot open the video file" << endl; cin.get(); return -1;
  • 11. } while (1) { Mat frame, gray_frame, hasil; cap >> frame; cap.read(frame); cvtColor(frame, gray_frame, COLOR_BGR2GRAY); char c = (char)waitKey(1); if (c == 27) break; cout << "Default Cols : " << frame.cols << endl; cout << "Default Rows : " << frame.rows << endl << endl; bilateralFilter(frame, hasil, 3, 3, 3); imwrite("GBlur.jpg", hasil); /// Display imshow("CAMERA", frame); imshow("Bilateral Gray", gray_frame); imshow("Bilateral Color", hasil); } waitKey(); return EXIT_SUCCESS; }
  • 12. EDGE DETECTION 1. Image #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat img2 = imread("E:/trial/trial/sakura.jpg", CV_LOAD_IMAGE_COLOR), edges; int width = img2.cols, height = img2.rows; imshow("Source Image", img2); cout << "Default Cols : " << img2.cols << endl; cout << "Default Rows : " << img2.rows << endl << endl; Canny(img2, edges, 20, 60); imshow("Canny RGB", edges); imwrite("cany2.jpg", edges); waitKey(); return EXIT_SUCCESS; }
  • 13. 20,40
  • 15. ANALISA Tepi suatu obyek dalam citra dinyatakan sebagai titik yang nilai keabuannya berbeda cukup besar dengan titik yang ada di sebelahnya. Parameter angka di dalam fungsi Canny berguna untuk mengatur kerapatan program dalam mendeteksi tepi. Semakin besar nilai parameter maka jangkauan tepi yang dideteksi semakin luas, sebaliknya semakin kecil nilai parameter akan menghasilkan deteksi tepi yang rapat. 2. Livecam #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { VideoCapture cap(0); if (cap.isOpened() == false) { cout << "Cannot open the video file" << endl; cin.get(); return -1; } while (1) { Mat frame, gray_frame, edges; cap >> frame; cap.read(frame); cvtColor(frame, gray_frame, COLOR_BGR2GRAY);
  • 16. char c = (char)waitKey(1); if (c == 27) break; cout << "Default Cols : " << frame.cols << endl; cout << "Default Rows : " << frame.rows << endl << endl; Canny(frame, edges, 20, 60); imwrite("canny2.jpg", edges); /// Display imshow("CAMERA", frame); imshow("Canny", edges); } waitKey(); return EXIT_SUCCESS; } Teori Metode Pyramids => Piramida , atau representasi piramida , adalah jenis representasi sinyal multi-skala yang dikembangkan oleh visi komputer , komunitas pemrosesan gambar dan pemrosesan sinyal , di mana sinyal atau gambar dikenakan perataan dan subsampling berulang. Representasi piramida adalah pendahulu dari representasi skala-ruang dan analisis multiresolusi .
  • 17. Program Downsampling (Gaussian Pyramid Down) Program ini mengunakan fungsi PyrDown dengan melakukan downsampling pada dekomposisi (pemecahan) Gaussian pyramid. Pertama dilakukan konvolusi pada image dengan filter tertentu. Kemudian dilakukan downsampling pada gambar dengan menghapus baris dan and kolom yang genap. Program Upsampling (Gaussian Pyramid Up) Program ini mengunakan fungsi PyrUp dengan melakukan up-sampling pada pemecahan Gaussian pyramid. Pertama dilakukan up-sampling pada gambar dengan memasukkan nilai kosong pada baris dan and kolom yang genap. Kemudian dilakukan konvolusi pada image dengan filter “multiplied by 4” untuk interpolasi (penambahan). Jadi gambar lebih besar 4 kali dari gambar asal.
  • 18. #include <opencv2opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/calib3d.hpp> #include <opencv2/features2d.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat img2 = imread("E:/trial/trial/sakura.jpg", CV_LOAD_IMAGE_COLOR), hasil; int width = img2.cols, height = img2.rows; imshow("Source Image", img2); pyrUp(img2, hasil, Size(width * 2, height * 2)); cout << "PyramidUp_1 Kolom / Lebar = " << hasil.cols << endl; cout << "PyramidUp_1 Baris / Tinggi = " << hasil.rows << endl; imwrite("Pyramid1.jpg", hasil); imshow("Pyramid1", hasil); pyrUp(hasil, hasil, Size(width * 4, height * 4)); cout << "PyramidUp_2 Kolom / Lebar = " << hasil.cols << endl; cout << "PyramidUp_2 Baris / Tinggi = " << hasil.cols << endl; imwrite("Pyramid2.jpg", hasil); imshow("Pyramid2", hasil);
  • 19. waitKey(); return EXIT_SUCCESS; } pyrUp(hasil, hasil, Size(width * 2, height * 2)); cout << "PyramidUp_2 Kolom / Lebar = " << hasil.cols << endl; cout << "PyramidUp_2 Baris / Tinggi = " << hasil.cols << endl; imwrite("Pyramid2.jpg", hasil);