Skip to content

Commit 8634252

Browse files
LaurentBergeralalek
authored andcommitted
Merge pull request #701 from LaurentBerger:DericheFilter
1 parent af26ce3 commit 8634252

File tree

6 files changed

+649
-11
lines changed

6 files changed

+649
-11
lines changed

modules/ximgproc/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Extended Image Processing
22
=========================
33

4-
1. Structured Forests
5-
2. Domain Transform Filter
6-
3. Guided Filter
7-
4. Adaptive Manifold Filter
8-
5. Joint Bilateral Filter
9-
6. Superpixels
10-
7. Graph segmentation
11-
8. Selective search from segmentation
12-
10. Paillou Filter
13-
11. Fast Line Detector
4+
- Structured Forests
5+
- Domain Transform Filter
6+
- Guided Filter
7+
- Adaptive Manifold Filter
8+
- Joint Bilateral Filter
9+
- Superpixels
10+
- Graph segmentation
11+
- Selective search from segmentation
12+
- Paillou Filter
13+
- Fast Line Detector
14+
- Deriche Filter

modules/ximgproc/doc/ximgproc.bib

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ @incollection{PFF2004
7676
publisher={Springer}
7777
}
7878

79+
@article{deriche1987using,
80+
title={Using Canny's criteria to derive a recursively implemented optimal edge detector},
81+
author={Deriche, Rachid},
82+
journal={International journal of computer vision},
83+
volume={1},
84+
number={2},
85+
pages={167--187},
86+
year={1987},
87+
publisher={Springer}
88+
}
7989

8090
@article{uijlings2013selective,
8191
title={Selective search for object recognition},

modules/ximgproc/include/opencv2/ximgproc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include "ximgproc/lsc.hpp"
5151
#include "ximgproc/paillou_filter.hpp"
5252
#include "ximgproc/fast_line_detector.hpp"
53-
53+
#include "ximgproc/deriche_filter.hpp"
5454

5555
/** @defgroup ximgproc Extended Image Processing
5656
@{
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* By downloading, copying, installing or using the software you agree to this license.
3+
* If you do not agree to this license, do not download, install,
4+
* copy or use the software.
5+
*
6+
*
7+
* License Agreement
8+
* For Open Source Computer Vision Library
9+
* (3 - clause BSD License)
10+
*
11+
* Redistribution and use in source and binary forms, with or without modification,
12+
* are permitted provided that the following conditions are met :
13+
*
14+
* * Redistributions of source code must retain the above copyright notice,
15+
* this list of conditions and the following disclaimer.
16+
*
17+
* * Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and / or other materials provided with the distribution.
20+
*
21+
* * Neither the names of the copyright holders nor the names of the contributors
22+
* may be used to endorse or promote products derived from this software
23+
* without specific prior written permission.
24+
*
25+
* This software is provided by the copyright holders and contributors "as is" and
26+
* any express or implied warranties, including, but not limited to, the implied
27+
* warranties of merchantability and fitness for a particular purpose are disclaimed.
28+
* In no event shall copyright holders or contributors be liable for any direct,
29+
* indirect, incidental, special, exemplary, or consequential damages
30+
* (including, but not limited to, procurement of substitute goods or services;
31+
* loss of use, data, or profits; or business interruption) however caused
32+
* and on any theory of liability, whether in contract, strict liability,
33+
* or tort(including negligence or otherwise) arising in any way out of
34+
* the use of this software, even if advised of the possibility of such damage.
35+
*/
36+
37+
#ifndef __OPENCV_DERICHEFILTER_HPP__
38+
#define __OPENCV_DERICHEFILTER_HPP__
39+
#ifdef __cplusplus
40+
41+
#include <opencv2/core.hpp>
42+
43+
namespace cv {
44+
namespace ximgproc {
45+
46+
//! @addtogroup ximgproc_filters
47+
//! @{
48+
49+
/**
50+
* @brief Applies Y Deriche filter to an image.
51+
*
52+
* For more details about this implementation, please see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.476.5736&rep=rep1&type=pdf
53+
*
54+
* @param _op Source 8-bit or 16bit image, 1-channel or 3-channel image.
55+
* @param _dst result CV_32FC image with same number of channel than _op.
56+
* @param alphaDerive double see paper
57+
* @param alphaMean double see paper
58+
*
59+
*/
60+
CV_EXPORTS void GradientDericheY(InputArray _op, OutputArray _dst, double alphaDerive,double alphaMean);
61+
/**
62+
* @brief Applies X Deriche filter to an image.
63+
*
64+
* For more details about this implementation, please see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.476.5736&rep=rep1&type=pdf
65+
*
66+
* @param _op Source 8-bit or 16bit image, 1-channel or 3-channel image.
67+
* @param _dst result CV_32FC image with same number of channel than _op.
68+
* @param alphaDerive double see paper
69+
* @param alphaMean double see paper
70+
*
71+
*/
72+
CV_EXPORTS void GradientDericheX(InputArray _op, OutputArray _dst, double alphaDerive,double alphaMean);
73+
74+
}
75+
}
76+
#endif
77+
#endif
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* By downloading, copying, installing or using the software you agree to this license.
3+
* If you do not agree to this license, do not download, install,
4+
* copy or use the software.
5+
*
6+
*
7+
* License Agreement
8+
* For Open Source Computer Vision Library
9+
* (3 - clause BSD License)
10+
*
11+
* Redistribution and use in source and binary forms, with or without modification,
12+
* are permitted provided that the following conditions are met :
13+
*
14+
* *Redistributions of source code must retain the above copyright notice,
15+
* this list of conditions and the following disclaimer.
16+
*
17+
* * Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and / or other materials provided with the distribution.
20+
*
21+
* * Neither the names of the copyright holders nor the names of the contributors
22+
* may be used to endorse or promote products derived from this software
23+
* without specific prior written permission.
24+
*
25+
* This software is provided by the copyright holders and contributors "as is" and
26+
* any express or implied warranties, including, but not limited to, the implied
27+
* warranties of merchantability and fitness for a particular purpose are disclaimed.
28+
* In no event shall copyright holders or contributors be liable for any direct,
29+
* indirect, incidental, special, exemplary, or consequential damages
30+
* (including, but not limited to, procurement of substitute goods or services;
31+
* loss of use, data, or profits; or business interruption) however caused
32+
* and on any theory of liability, whether in contract, strict liability,
33+
* or tort(including negligence or otherwise) arising in any way out of
34+
* the use of this software, even if advised of the possibility of such damage.
35+
*/
36+
#include <opencv2/core.hpp>
37+
#include <opencv2/core/utility.hpp>
38+
#include <opencv2/highgui.hpp>
39+
#include <opencv2/ximgproc.hpp>
40+
#include "opencv2/ximgproc/deriche_filter.hpp"
41+
42+
using namespace cv;
43+
using namespace cv::ximgproc;
44+
45+
#include <iostream>
46+
using namespace std;
47+
48+
int alDerive=100;
49+
int alMean=100;
50+
Ptr<Mat> img;
51+
const string & winName = "Gradient Modulus";
52+
53+
static void DisplayImage(Mat x,string s)
54+
{
55+
vector<Mat> sx;
56+
split(x, sx);
57+
vector<double> minVal(3), maxVal(3);
58+
for (size_t i = 0; i < sx.size(); i++)
59+
{
60+
minMaxLoc(sx[i], &minVal[i], &maxVal[i]);
61+
}
62+
maxVal[0] = *max_element(maxVal.begin(), maxVal.end());
63+
minVal[0] = *min_element(minVal.begin(), minVal.end());
64+
Mat uc;
65+
x.convertTo(uc, CV_8U,255/(maxVal[0]-minVal[0]),-255*minVal[0]/(maxVal[0]-minVal[0]));
66+
imshow(s, uc);
67+
}
68+
69+
70+
/**
71+
* @function DericheFilter
72+
* @brief Trackbar callback
73+
*/
74+
static void DericheFilter(int, void*)
75+
{
76+
Mat dst;
77+
double d=alDerive/100.0,m=alMean/100.0;
78+
Mat rx,ry;
79+
GradientDericheX(*img.get(),rx,d,m);
80+
GradientDericheY(*img.get(),ry,d,m);
81+
DisplayImage(rx, "Gx");
82+
DisplayImage(ry, "Gy");
83+
add(rx.mul(rx),ry.mul(ry),dst);
84+
sqrt(dst,dst);
85+
DisplayImage(dst, winName );
86+
}
87+
88+
int main(int argc, char* argv[])
89+
{
90+
Mat *m=new Mat;
91+
cv::CommandLineParser parser(argc, argv, "{help h | | show help message}{@input | | input image}");
92+
if (parser.has("help"))
93+
{
94+
parser.printMessage();
95+
return -1;
96+
}
97+
string input_image = parser.get<string>("@input");
98+
if (input_image.empty())
99+
{
100+
parser.printMessage();
101+
parser.printErrors();
102+
return -2;
103+
}
104+
if (argc==2)
105+
*m = imread(input_image);
106+
if (m->empty())
107+
{
108+
cout << "File not found or empty image\n";
109+
return -3;
110+
}
111+
imshow("Original", *m);
112+
img =Ptr<Mat>(m);
113+
namedWindow( winName, WINDOW_AUTOSIZE );
114+
/// Create a Trackbar for user to enter threshold
115+
createTrackbar( "Derive:",winName, &alDerive, 400, DericheFilter );
116+
createTrackbar( "Mean:", winName, &alMean, 400, DericheFilter );
117+
DericheFilter(0,NULL);
118+
waitKey();
119+
return 0;
120+
}

0 commit comments

Comments
 (0)