Ask Your Question
1

Deriche edge detector

asked 2015-11-21 13:23:18 -0500

updated 2015-11-21 14:39:46 -0500

i wonder if there is any work around Deriche edge detector? it would be a nice addition to OpenCV.

image description -------> image description

edit retag flag offensive close merge delete

Comments

It is not inside the repository and in my knowledge noone is working on it. However it seems that it is based on the Canny Edge Detector which is already available in OpenCV. So it might not be that difficult to add it to the repository. Care to take an attempt at it?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-11-23 08:22:14 -0500 )edit

@StevenPuttemans May be I'm wrong but I think that in OpenCV canny edge dector used is sobel (without opencl). Size of Sobel detector is ranging 3 to 7.

LBerger gravatar imageLBerger ( 2015-11-23 15:49:08 -0500 )edit

You have Sobel filter, then you have Canny which is based on the Sobel filter. However as described in wikipedia, the Deriche edge detector is a derivate of the canny, where some internal optimizations are done, so I am not sure why this answer would be incorrect?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-11-24 01:50:15 -0500 )edit
1

Difference is in implementation. Deriche use two IIR filters one for blurring and another for derivative. This filters have got two parameters one for blur scale and another for edge localisation. As it is IIR filter edge localisation is better than sobel filter but it is time consumming. You can download a code of dercihe imlementation here (I haven't checked if it ist good)

LBerger gravatar imageLBerger ( 2015-11-24 02:43:18 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2016-04-17 14:53:10 -0500

LBerger gravatar image

updated 2016-04-18 13:47:10 -0500

I have read @Miki answer in this post and disable CV_OCL_RUN and CV_IPP_RUN in my own copy of opencv canny. results is here :

#include<opencv2/opencv.hpp>
#include "opencv2/core/ocl.hpp"
#include<iostream>
using namespace cv;


using namespace cv;

/*
Using Canny's Criteria to Derive a Recursively Implemented Optimal Edge Detector International Journal of Computer Vision,167-187 (1987)
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.476.5736&rep=rep1&type=pdf
http://www.esiee.fr/~coupriem/Algo/algoima.html
*/


class ParallelGradientDericheYCols: public ParallelLoopBody
{
private:
    Mat &img;
    Mat &im1;
    double alphaMoyenne;
    double alphaDerive;
    bool verbose;

public:
    ParallelGradientDericheYCols(Mat& imgSrc, Mat &d,double alm,double ald):
        img(imgSrc),
        im1(d),
        alphaMoyenne(alm),
        alphaDerive(ald),
        verbose(false)
    {}
    void Verbose(bool b){verbose=b;}
    virtual void operator()(const Range& range) const
    {

        if (verbose)
            std::cout << getThreadNum()<<"# :Start from row " << range.start << " to "  << range.end-1<<" ("<<range.end-range.start<<" loops)" << std::endl;

        float               *f1,*f2;

        long                i,j,nb;
        long                tailleSequence=(img.rows>img.cols)?img.rows:img.cols;
        double              *g1=new double[tailleSequence],*g2=new double[tailleSequence];
        double  p=alphaDerive;
        double  k=pow(1-exp(-p),2.0)/(1+2*p*exp(-p)-exp(-2*p));
        double  kp=pow(1-exp(-p),2.0)/exp(-p);
        double a1=1,a2=0;
        double a3=0,a4=0;
        double b1=0,b3=2*exp(-p);
        double b2=0,b4=-2*exp(-p);
        int rows=img.rows,cols=img.cols;


        kp=pow(1-exp(-p),2.0)/exp(-p);
        a1=0,a2=kp*exp(-p),a3=-kp*exp(-p),a4=0;
        b1=2*exp(-p);
        b2=-exp(-2*p);


        switch(img.depth()){
        case CV_8U :
            {
            unsigned char       *c1;
            for (nb=0;nb<img.channels();nb++)
                {
                for (j=range.start;j<range.end;j++)
                    {
                    // Filtre causal vertical
                    c1 = (unsigned char*)img.ptr(0)+nb;
                    f2 = (float*)im1.ptr(0)+nb;
                    f2 += j;
                    c1+=j;
                    i=0;
                    g1[i] = (a1 + a2 +b1+b2)* *c1  ;
                    g1[i] = (a1 + a2 )* *c1  ;
                    i++;
                    c1+=cols;
                    g1[i] = a1 * *c1 + a2 * c1[-cols] + (b1+b2) * g1[i-1];
                    g1[i] = a1 * *c1 + a2 * c1[-cols] + (b1) * g1[i-1];
                    i++;
                    c1+=cols;
                    for (i=2;i<rows;i++,c1+=cols)
                        g1[i] = a1 * *c1 + a2 * c1[-cols] +b1*g1[i-1]+
                                b2 *g1[i-2];

                    // Filtre anticausal vertical
                    c1 = (unsigned char*)img.ptr(0)+nb;
                    c1 += (rows-1)*cols+j;
                    i = rows-1;
                    g2[i] =(a3+a4+b1+b2)* *c1; 
                    g2[i] =(a3+a4)* *c1; 
                    i--;
                    c1-=cols;
                    g2[i] = a3* c1[cols] + a4 * c1[cols]+(b1+b2)*g2[i+1];
                    g2[i] = a3* c1[cols] + a4 * c1[cols]+(b1)*g2[i+1];
                    i--;
                    c1-=cols;
                    for (i=rows-3;i>=0;i--,c1-=cols)
                        g2[i] = a3*c1[cols] +a4* c1[2*cols]+
                                b1*g2[i+1]+b2*g2[i+2];
                    for (i=0;i<rows;i++,f2+=cols)
                        *f2 = (float)(g1[i]+g2[i]);
                    }
                }
            }
            break;
        case CV_16S :
        case CV_16U :
            {
            unsigned short      *c1;
            for (nb=0;nb<img.channels();nb++)
                {
                for (j=range.start;j<range.end;j++)
                    {
                    c1 = ((unsigned short*)img.ptr(0))+nb;
                    f2 = ((float*)im1.ptr ...
(more)
edit flag offensive delete link more

Comments

Good job Laurent, thanks.

sturkmen gravatar imagesturkmen ( 2016-04-17 16:57:14 -0500 )edit
1

+1 I feel a new PR coming up?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-18 03:38:04 -0500 )edit
1

@StevenPuttemans a pr in https://github.com/Itseez/opencv_cont... for deriche filter only? About canny it's an another job because I have disable CV_OCL_RUN and CV_IPP_RUN and new function needs new arguments and apertureSize is not needed

LBerger gravatar imageLBerger ( 2016-04-18 13:52:56 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2015-11-21 13:23:18 -0500

Seen: 1,466 times

Last updated: Apr 18 '16