1.2K views

Uploaded by pi194043

A modified version of canny edge detection which uses color gradient and provide multiple thresholding edge images

save

You are on page 1of 11

Pi19404

February 10, 2014

Contents

Contents

Modied Canny Edge Detection

0.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0.2 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

3 10 10

2 | 11

0.1 Introduction

In this article we will look at Modified canny edge detection which will provide output corresponding to different thresholds.We will also consider the use of color gradients instead of gray scale gradients

Canny Edge detection algorithm is optimal edge detection algorithm. The result is a binary image,where the edge approximate the true edges of the image Canny edge detection algorithm provides a computational method to achieve

Canny Edge detection algorithm consists of 5 steps

The first step is to perform Gaussian Smoothing to eliminate the noise in the image The gaussian filter is optimal filter in the sense that in increases the SNR and provide the best localization characteristics.This have been proved in the paper ??. After gaussian smoothing edge detection is performed to obtain the gradients along the x and y directions.

3 | 11

void smoothing(Mat src,Mat &dst,int aperture) { cv::GaussianBlur(src,src,Size(aperture,aperture),1); } smoothing(src,src,aperture); Mat dx,dy; cv::Sobel(src,dx,CV_32F,1,0,aperture,1, 0, cv::BORDER_REPLICATE); cv::Sobel(src,dy,CV_32F,0,1,aperture,1, 0, cv::BORDER_REPLICATE); cv::cartToPolar(dx,dy,fmag,fori,true);

Next step is non maxima suppression,which selects the locally dominant gradient Let us extract the edge orientation and resolve it into one of orientation at 0,45,90,135.

//pointer to orientation image float *ptr2=(float*)ori.data; for(int i=1;i<height-1;i++) { for(int j=1;j<width-1;j++) { float ori1=ptr2[j+i*width]; for(int k=0;k<4;k++) { float i1=(k*45)+45; float i2=i1-45; float i3=(k*45)+180; float i4=i3+45; float ori2=((int)(ori1+(45.0/2))); if(ori2 >360) ori2=ori2-360; //checking orienation of 0,45,90,135 if((ori2 < i1 && ori2 >=i2 ) ||(ori2 >= i3 && ori2 <=i4)) { ori1=k*45; break; }

4 | 11

Thus we compute the dominant edge direction about the neighborhood and check if the magnitude of gradient is strongest along neighborhood pixels along the gradient. If the gradient value is maximum,it is retained else value is set to 0 The result is shown in figure 1d

(b) smoothing

(d) suppressed

The input to canny edge detection algorithm is a pair of thresholds,lower and higher threshold. Any pixel in the image greater than lower threshold is considered to be an edge pixel and marked accordingly.The thresholded images are shown in figure 1e and figure 1f. The pixels indicated in figure 1f indicate points which are surely edges. The pixels indicated in figure 1e may be an edge.

cv::threshold(fmag,hout,higher,255,CV_THRESH_BINARY); cv::threshold(fmag,lout,lower,255,CV_THRESH_BINARY);

If any pixels in the image are connected to these edge pixels and have gradient greater than higher threshold,they are also marked as edge pixels.

5 | 11

Thus this can be considered as following edge .To begin with we need a pixel with gradient magnitude greater than higher threshold,and edge following is done till be encounted a neighborhood where all the pixels are lower than the lower threshold . To check if a neighbour is connected to edge ,we simple check if point is possibly and edge

//function to check if point is connected to edge bool check_color(Point p) { int x=p.x; int y=p.y; if(x<nMinx || x >nMaxx || y<nMiny || y >nMaxy) return false; float *pl=(float*)lout.data; float val2=pl[x+y*s.width]; int val=getPixel(p); if(val>0) return false; //check if pixel is possibly an edge if(val2>0) return true; else return false; return false; }

This process is called hysterisis thresholding. We will use a stack based implementation of connceted component analysis.

//main function for performing connected component anaysis //starting from higher threshold images void connectedComponent(Mat hout) { float *ptr1=(float *)hout.data; nMinx=1; nMaxx=s.width-2;

6 | 11

nMiny=1; nMaxy=s.height-2; for(int i=nMiny;i<nMaxy;i++) { for(int j=nMinx;j<nMaxx;j++) { if(ptr1[j+i*s.width]>0 ) { stackfill(j,i); } } } //function which perform edge following void stackfill(int x,int y) { points.push(Point(x,y)); while(points.empty()==false) { //pop elements from top of stack Point p=points.top(); points.pop(); setPixel(p); //add neighbors to the stack for(int i=-1;i<=1;i++) { for(int j=-1;j<=1;j++) { if(i==0 && j==0) continue; Point p1=Point(p.x+i,p.y+j); //check if pixel is a edge if(check_color(p1)==true) { points.push(p1); } }

7 | 11

} }

Robust edge detection is typically a difficult task in real time environment due to varying illumination,shadows etc. The gradient computation is performed on a grayscale image As a modification to canny ,gradients are computed for each of channels of color image individually. Orientation corresponding to dominant orientation is retained. Non maxima supression is performed on this final image The output is seen in figure 1h,1j and ?? It can be seen that much better edge image is obtained using color gradients. It may also be required that we perform thresholding at different levels

8 | 11

Thus we can pass a vector of thresholds to canny as input and get a vector of images at output. Only the function from the point of hysteris is performed for each pair of threshold.

void canny(Mat src,vector<Mat> &dst,vector<double> lower,vector<double> hi { Mat fmag,fori,disp; s=Size(src.cols,src.rows); //perform gaussian smoothing //cvtColor(src,src,CV_BGR2GRAY); smoothing(src,src,aperture); //computing the color gradients if(src.channels()>1) colorGradient(src,fmag,fori,aperture); else { Mat dx,dy; //computing gradients along x and y direction cv::Sobel(src,dx,CV_32F,1,0,aperture,1, 0, cv::BORDER_REPLICATE); cv::Sobel(src,dy,CV_32F,0,1,aperture,1, 0, cv::BORDER_REPLICATE); //compute magnitude and orientation of gradient cv::cartToPolar(dx,dy,fmag,fori,true); } //perform non maxima suppression nonMaxima(fmag,fori); Mat hout; dst.resize(lower.size()); //applying multiple thresholds for(int i=0;i<lower.size();i++) { //apply lower and higher gradient thresholds cv::threshold(fmag,hout,lower[i],255,CV_THRESH_BINARY); cv::threshold(fmag,lout,higher[i],255,CV_THRESH_BINARY); connectedComponent(hout); lout.copyTo(dst[i]); }

9 | 11

0.2 Code

The code for modified canny edge detector can be found in the git repository https://github.com/pi19404/OpenVision/ in files ImgProc/edgedetector.cpp and ImgProc/edgedetector.hpp files.

10 | 11

Bibliography

Bibliography

[1] F. John Canny. A Computational Approach to Edge Detection. In: 8.6 (1986), pp. 679698.

doi: http://doi.acm.org/10.1145/11274.11275.

11 | 11

- Normalized convolution for image interpolationUploaded bypi194043
- Adaptive Skin Color DetectorUploaded bypi194043
- A linear channel filterUploaded bypi194043
- ARM Neon Optimization for image interleaving and deinterleavingUploaded bypi194043
- Fast 2D Separable Symmetric/Anti-Symmmetric ConvolutionUploaded bypi194043
- Continuous Emission Hidden Markov Model for sequence classificationUploaded bypi194043
- Dense optical flow expansion based on polynomial basis approximationUploaded bypi194043
- Random Ferns for Patch DescriptionUploaded bypi194043
- SubPixel Corner Localization AlgorithmUploaded bypi194043
- Multi Class Logistic Regression Training and TestingUploaded bypi194043
- NEON - ARMUploaded byKuba
- Fast Asymmetric Learning for Cascade Face Detection Training/Testing UtilityUploaded bypi194043
- Gaussian Multivariate Distribution -Part 1Uploaded bypi194043
- polynomial approximation of a 2D signalUploaded bypi194043
- Polynomial Approximation of 1D signalUploaded bypi194043
- Uniform Local Binary Pattern and Spatial Histogram ComputationUploaded bypi194043
- OpenCL Heterogenenous program for Image Processing - ColorSpace conversion BGR-HSV,HSV-BGR,BGR-GRAYUploaded bypi194043
- Android OpenCV Simple Face TrackerUploaded bypi194043
- Canny Edge Detection CodeUploaded byPutu Adi Susanta
- Control Limited Adaptive Histogram Equalization for Image EnhancementUploaded bypi194043
- Uniform Color QuantizationUploaded bypi194043
- Image enhancement using FusionUploaded bypi194043
- Polynomial Approximation of 2D image patch -Part 2Uploaded bypi194043
- OpenCL Image Convolution Filter - Box FilterUploaded bypi194043
- Android OpenCV Face detectionUploaded bypi194043
- OpenCL 2D Convolution Using Separable Filters -Box FilterUploaded bypi194043
- Fast 3D Extension of Fast Feature Detection for SpatioTemporal Corner DetectionUploaded bypi194043
- Local Binary PatternUploaded bypi194043
- Computing Rectangular Haar Features for Cascade Detection TrainingUploaded bypi194043
- Feature Detection - Overview of Harris Corner Feature DetectionUploaded bypi194043

- Implementation of discrete hidden markov model for sequence classification in C++ using EigenUploaded bypi194043
- Markov chain implementation in C++ using EigenUploaded bypi194043
- OpenVision Library Gaussian Mixture Model ImplementationUploaded bypi194043
- Continuous Emission Hidden Markov Model for sequence classificationUploaded bypi194043
- Dense optical flow expansion based on polynomial basis approximationUploaded bypi194043
- Polynomial Approximation of 2D image patch -Part 2Uploaded bypi194043
- Multi Class Logistic Regression Training and TestingUploaded bypi194043
- Compiling Native C/C++ library for AndroidUploaded bypi194043
- Gaussian Multivariate Distribution -Part 1Uploaded bypi194043
- polynomial approximation of a 2D signalUploaded bypi194043
- Uniform Local Binary Pattern and Spatial Histogram ComputationUploaded bypi194043
- Tan and Triggs Illumination normalizationUploaded bypi194043
- C++ virtual functions and abstract classUploaded bypi194043
- C++ static members and functionUploaded bypi194043
- Random Ferns for Patch DescriptionUploaded bypi194043
- Integral Image for Computation of Mean And VarianceUploaded bypi194043
- Embedded Systems Programming with ARM on Linux - Blinking LEDUploaded bypi194043
- C++ InheritanceUploaded bypi194043
- Mean Shift AlgorithmUploaded bypi194043
- Local Binary PatternUploaded bypi194043
- C++ Const,Volatile Type QualifiersUploaded bypi194043
- Polynomial Approximation of 1D signalUploaded bypi194043

- informes12y3arquitecturadecomputadores-Uploaded byFw94
- ECRobotInstaller: Automated download and install for ECRobotUploaded byRaymond Chui
- circuitos electricos de caUploaded byMartin Landeros Blanco
- Dinamica e modellistica della turbolenza - Esercitazioni del corsoUploaded byAlfredo Patrizi
- powerwave产品指南Uploaded byMani_3ip
- metasys® ifc2-3030Uploaded bymubs73
- Random Variables & Probability DistributionsUploaded byyashar2500
- TN_1_Bande_de_base.pdfUploaded byJaouane Hamza
- EQUIPO 3 ENDOCRINOUploaded bygeorginab_3
- Water RocketUploaded byvelumani2003
- Mini Tower FermentorUploaded byaguilaquecae
- Principia-13-Dez-2009Uploaded byJosé Renato Gaziero Cella
- Paired Observation.pdfUploaded byJennybabe Peta
- Manual Unidirve 1Uploaded byAndrés Suárez
- UCS 500N7.2 Multifunctional Transient Simulator.pdfUploaded byKristina Moore
- Propiedades de Los Fluidos - Mecánica de Fluidos e HidraulicaUploaded byOscar Garcés
- Sistema de Coleta de DadosUploaded byIsaque Rodrigues
- o&m Project Report-03Uploaded bygavishjain
- C1580.13946Uploaded byashraf
- Turbocompresor Luigi MEJORADOUploaded byLuigi Ortiɀ
- TRIGONOMETRIA_SEM4_2010-I (1).pdfUploaded byJorge Campos
- Practica 1 fisicaUploaded bylalofreud
- Artigo04 o Comportamento Do Consumidor de InformacoesUploaded byraqueldias2009
- EL CIRCUITO ELÉCTRICOUploaded byLusblaidys Mayorca
- Manual de servicio Marmita FT-GL[20-60]-FT40GLF-parts.pdfUploaded byPitter M Montilla N
- Understanding and Eliminating Pressure Fluctuations in 2010 Process SafetyUploaded byandri
- MC PLC LAB 2013Uploaded bysivaeeinfo
- final skittles projectUploaded byapi-341512483
- Chapitre 3 Convertisseurs AC DC Partie1 Redressement Non Commandé_étudientUploaded byMohamed Yacine Rachedi
- ASTM D3039.pdfUploaded byRafaelMartínez