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

Modified Canny Edge Detection

**Modified Canny Edge Detection
**

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

**Robust Detection Good Localization Single response to edge
**

Canny Edge detection algorithm consists of 5 steps

Smoothing Computing Gradients Non-Maxima Suppression Double thresholding Hysterisis

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

Modified Canny Edge Detection

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; }

}

}

}

//updating discretized orientation ptr2[j+i*width]=ori1;

4 | 11

**Modified Canny Edge Detection
**

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

(a) original image

(b) smoothing

(c) magnitude image

(d) suppressed

(e) lower threshs

(f) higher threshs

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

**Modified Canny Edge Detection
**

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

Modified Canny Edge Detection

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

Modified Canny Edge Detection

} }

}

}

The output is show in figure 1g

(g) final edge

(h) color edge

(i) color supressed

(j) final cedge

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

**Modified Canny Edge Detection
**

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

Modified Canny Edge Detection

}

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

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

- Compiling Native C/C++ library for AndroidUploaded bypi194043
- Polynomial Approximation of 2D image patch -Part 2Uploaded 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
- A linear channel filterUploaded bypi194043
- ARM Neon Optimization for image interleaving and deinterleavingUploaded bypi194043
- Adaptive Skin Color DetectorUploaded bypi194043
- OpenVision Library Gaussian Mixture Model ImplementationUploaded bypi194043
- Markov chain implementation in C++ using EigenUploaded bypi194043
- Implementation of discrete hidden markov model for sequence classification in C++ using EigenUploaded bypi194043
- C++ Const,Volatile Type QualifiersUploaded bypi194043
- C++ InheritanceUploaded bypi194043
- Local Binary PatternUploaded bypi194043
- Mean Shift AlgorithmUploaded bypi194043
- Embedded Systems Programming with ARM on Linux - Blinking LEDUploaded bypi194043
- Random Ferns for Patch DescriptionUploaded bypi194043
- Integral Image for Computation of Mean And VarianceUploaded bypi194043
- C++ static members and functionUploaded bypi194043
- C++ virtual functions and abstract classUploaded bypi194043
- Tan and Triggs Illumination normalizationUploaded bypi194043
- Normalized convolution for image interpolationUploaded bypi194043
- Uniform Local Binary Pattern and Spatial Histogram ComputationUploaded bypi194043

- Sistema de Evaluacion Calificacion y Acreditacion CorrUploaded bySilvia Benitez
- Aeropuerto.docxUploaded byAdrianaJAO
- Propiedades medicinales del ajoUploaded byJonathanHernándezCastillo
- Elaboracion de Conservas de Frutas en AlmibarUploaded byAlfonsoLuisBarandicaComas
- tech_676_912.pdfUploaded byAna Castro
- Report.Uploaded byDgk Raju
- Certificate in Cyber Security Feb 2016Uploaded byWaldon Hendricks
- Over GreasingUploaded byantonyale
- my cliftonstrengths student action itemsUploaded byapi-382275593
- Ejemplo de mediación grupo3Uploaded byGeorgina Cascante Rivera
- 8 - complete.pdfUploaded byAlman-Najar Namla
- bilan_simple.xlsUploaded byمراد الزرق
- 11562Uploaded byLeonel Coyla
- Peace Corps Namibia Welcome Book | June 2013 'CCD'Uploaded byAccessible Journal Media: Peace Corps Documents
- Sullana y sus problemas de contaminación ambientalUploaded byjoseluis251168
- working in bc questionsUploaded byapi-339563881
- 1.3 Caso Práctico Gestion Por ProcesosUploaded byIsa Karina
- Poderes e Deveres do Administrador PúblicoUploaded byEtiany Oliveira Santos
- Cinematica Exercicios LegalUploaded byAnanda Freitas
- Aduana _Oficio Circular N°561Uploaded byraer1971
- Alboqub,StatisticsUploaded byameer
- D.Leg.1427Uploaded byLa Ley
- Sample Trust DeedUploaded byCA Mukesh Kumar Mishra
- Indemnity-Bond-Form-No.3762-To-get-duplicate-LIC-policy-Bond.pdfUploaded byPurushothama Rao Nalamati
- Connection F1- Hilti HSA StudUploaded bypeilingteoh6384
- Coverall NomexUploaded byRudi Syam
- The Geometric Characteristics of the Linear Features in Close Range PhotogrammetryUploaded byIJERD
- j.jaad.2005.06.036Uploaded bybogdansoro
- HiPath Xpressions Compact V3.0 Short Reference Guide Standard User InterfaceUploaded byenjoythedocs
- Comparing Pressure Flow Solvers for Dinamic SimulationUploaded byNeil Carrasco