Deteksi tepi dengan operator-operator masih memiliki kelemahan, diantaranya pada satu perubahan nilai piksel akan diperoleh banyak piksel tepi. Disamping itu, derau dan tekstur yang memiliki variasi nilai piksel yang cukup tinggi (tekstur kasar) pada suatu citra dapat juga terdeteksi sebagai tepi. Sebagai contoh, pada deteksi tepi dengan metode Prewitt, derau pada gambar terdeteksi sebagai piksel tepi
Script Program
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
int high_switch_value = 0;
int highInt = 0;
int low_switch_value = 0;
int lowInt = 0;
void switch_callback_h( int position ){
highInt = position;
}
void switch_callback_l( int position ){
lowInt = position;
}
int _tmain(int argc, _TCHAR* argv[])
{
const char* name = "Edge Detection Window";
// ukuran kernel
int N = 7;
// Set up images
IplImage* img = cvLoadImage( "rame.jpg", 0 ); //nama gambar adalah rame.jpg
IplImage* img_b = cvCreateImage( cvSize(img->width+N-1,img->height+N-1), img->depth, img->nChannels );
IplImage* out = cvCreateImage( cvGetSize(img_b), IPL_DEPTH_8U, img_b->nChannels );
// menambahkan garis border
CvPoint offset = cvPoint((N-1)/2,(N-1)/2);
cvCopyMakeBorder(img, img_b, offset, IPL_BORDER_REPLICATE, cvScalarAll(0));
// Membuat Window
cvNamedWindow( name, 1 );
// Variable
int aperature_size = N;
double lowThresh = 20;
double highThresh = 40;
// Membuat trackbars
cvCreateTrackbar( "High", name, &high_switch_value, 4, switch_callback_h );
cvCreateTrackbar( "Low", name, &low_switch_value, 4, switch_callback_l );
while( 1 ) {
switch( highInt ){
case 0:
highThresh = 200;
break;
case 1:
highThresh = 400;
break;
case 2:
highThresh = 600;
break;
case 3:
highThresh = 800;
break;
case 4:
highThresh = 1000;
break;
}
switch( lowInt ){
case 0:
lowThresh = 0;
break;
case 1:
lowThresh = 100;
break;
case 2:
lowThresh = 200;
break;
case 3:
lowThresh = 400;
break;
case 4:
lowThresh = 600;
break;
}
// Proses deteksi tepi menggunakan canny tranformation
cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );
cvShowImage(name, out);
if( cvWaitKey( 15 ) == 27 )
break;
}
// Program selesai dan melepas resource
cvReleaseImage( &img );
cvReleaseImage( &img_b );
cvReleaseImage( &out );
cvDestroyWindow( name );
return 0;
}
Citra Akhir
1 comment:
wah terima kasih banget udah nge-share source code nya. Berguna banget buat belajar. :)
Post a Comment