Sunday, 6 November 2011

EDGE DETECTION

Edge detection is a fundamental tool in image processing and computer vision, particularly in the areas of feature detection and feature extraction, which aim at identifying points in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The same problem of finding discontinuities in 1D signals is known as step detection

following are some of the edge detection techniques usually followed by the programmers for edge detection
          
            1) Canny edge detector
            2) Sobel edge detector
            3) Laplace edge detector
            4) Prewitt edge detector
            5) Robert edge detector

The Canny edge detection operator was developed by John F. Canny in 1986 and uses a multi-stage algorithm to detect a wide range of edges in images. Most importantly, Canny also produced a computational theory of edge detection explaining why the technique works.

The Sobel operator is used in image processing, particularly within edge detection algorithms. Technically, it is a discrete differentiation operator, computing an approximation of the gradient of the image intensity function. At each point in the image, the result of the Sobel operator is either the corresponding gradient vector or the norm of this vector. The Sobel operator is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical direction and is therefore relatively inexpensive in terms of computations. On the other hand, the gradient approximation which it produces is relatively crude, in particular for high frequency variations in the image.

The Prewitt operator is used in image processing, particularly within edge detection algorithms. Technically, it is a discrete differentiation operator, computing an approximation of the gradient of the image intensity function. At each point in the image, the result of the Prewitt operator is either the corresponding gradient vector or the norm of this vector. The Prewitt operator is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical direction and is therefore relatively inexpensive in terms of computations. On the other hand, the gradient approximation which it produces is relatively crude, in particular for high frequency variations in the image.

following is  the code for implementing the edge detection techniques in opencv





#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "cvaux.h"




int _tmain(int argc, _TCHAR* argv[])
{
IplImage * image=cvLoadImage("C:/Users/PENUMARTHY/Desktop/a.jpg",1);
IplImage * gray= cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
IplImage * sobel= cvCreateImage(cvGetSize(image), IPL_DEPTH_16S, 1);
IplImage * laplace= cvCreateImage(cvGetSize(image), IPL_DEPTH_16S, 1);
IplImage * cannay=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage * corner=cvCreateImage(cvGetSize(image),IPL_DEPTH_32F,1);
    cvCvtColor(image,gray,CV_BGR2GRAY);
    cvPreCornerDetect( gray, corner, 7 );
cvCanny (gray,cannay,150,100, 3 );
    cvSobel( gray,sobel,1,1,7 );
cvLaplace( gray, laplace, 7 );
cvNamedWindow("cannay",1);
cvShowImage("cannay",cannay);
cvNamedWindow("laplace",1);
cvShowImage("laplace",laplace);
cvNamedWindow("sobel",1);
cvShowImage("sobel",sobel);
cvNamedWindow("prewit",1);
cvShowImage("prewit",corner);
cvNamedWindow("gray",1);
cvShowImage("gray",gray);
cvNamedWindow("show",1);
cvShowImage("show",image);
cvWaitKey(0);
}

output:-

SIMPLE OPENCV PROGRAM AND ITS EXECUTION

here is a simple OpenCv program to get image from a location in the computer and show it using a windows console


#include "stdafx.h"
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"

int _tmain(int argc, _TCHAR* argv[])
{
 IplImage *image = 0;
 image = cvLoadImage( "" D:/PHOTOES/Images/mylogo2.jpg", 1 );
  cvNamedWindow( "Show", 1 );
  cvShowImage( "Show", image );
  printf( "Press any key to exit\n");
  cvWaitKey(0);
  cvDestroyWindow("result");
  return 0;
}

output
  note:- to compile a program we need to press F5 or go to Debug->Start Debugging




CONFIGURING OPENCV PROJECT

After integrating the libraries with Microsoft visual studios 2008. let us start performing the start of ny creating a new project in Microsoft Visual Studios 2008
                                                  to create a project go to File->New->Project

in the left side tree select visual c++ and in the rigt side list make a selection of "win32 console application"

provide a name to the project in the project name dialog click ok.as soon as u click ok another dialog box will appear just click finish there

now an editor interface for the project will appear then go to Project-> " project name" properties... in this case my project name is "blink"

then a dialog box will open where expand "Configuration Properties" in left tree->then expand "linker" branch in it-> select input in it
then in the right side window select Additional Dependencies provide the following inputs
cv210.lib
cvaux210.lib
cxcore210.lib
highgui210.lib then click ok

now the project is ready to be designed and executed
note:- for every project the configuration must be done


INSTALLING OPENCV IN WINDOWS & INTEGRATING WITH VISUAL STUDIOS 2008

INSTALLATION
Following steps are to be followed to complete the installation and run the OpenCv in windows platform
 
 1) download the OpenCv libraries into the system from the link

 2) install OpenCv librabries in the windows system .while  installing ensure that the path of libaries are added                  to the current/all users .


3) provide the path where the OpenCv is to be installed and remember the path for future references
(say C:\OpenCV2.1 )

 3) check the installation by executing sample programs provided while OpenCv installation
 (say C:\OpenCV2.1\samples\c )

INTEGRATION



1.    Open VC++ Directories configuration: Tools > Options > Projects and Solutions > VC++ Directories
  1. 1.Choose "Show directories for: Include files 
       "Add  pathwhere opencv is installed\include\opencv" 
(say C:\OpenCV2.1\include\opencv) if my path is "C:\OpenCV2.1”
   





    2.Choose "Show directories for: Library files"
    1. Add "$openCVDir\lib"  (say C:\OpenCV2.1\lib)       


     


   3.Choose "Show directories for: Source files"
    1. Add "$openCVDir\src\cv" (say C:\OpenCV2.1\src\cv)
    2. Add "$openCVDir\src\cvaux" (say C:\OpenCV2.1\src\cvaux)
    3. Add "$openCVDir\src\cxcore" (say C:\OpenCV2.1\src\cxcore)
    4. Add "$openCVDir\src\highgui" ( say C:\OpenCV2.1\src\highgui)