Skip to content

Commit 7b2c6f8

Browse files
committed
Merge pull request #375 from zhou-chao:wmfv3
2 parents a29ec8a + 8837948 commit 7b2c6f8

File tree

7 files changed

+1034
-0
lines changed

7 files changed

+1034
-0
lines changed

modules/ximgproc/doc/ximgproc.bib

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,21 @@ @InProceedings{LiCVPR2015LSC
148148
month = {June},
149149
year = {2015}
150150
}
151+
152+
@incollection{zhang2014rolling,
153+
title={Rolling guidance filter},
154+
author={Zhang, Qi and Shen, Xiaoyong and Xu, Li and Jia, Jiaya},
155+
booktitle={Computer Vision--ECCV 2014},
156+
pages={815--830},
157+
year={2014},
158+
publisher={Springer}
159+
}
160+
161+
@inproceedings{zhang2014100+,
162+
title={100+ times faster weighted median filter (WMF)},
163+
author={Zhang, Qi and Xu, Li and Jia, Jiaya},
164+
booktitle={Computer Vision and Pattern Recognition (CVPR), 2014 IEEE Conference on},
165+
pages={2830--2837},
166+
year={2014},
167+
organization={IEEE}
168+
}

modules/ximgproc/include/opencv2/ximgproc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "ximgproc/segmentation.hpp"
4646
#include "ximgproc/fast_hough_transform.hpp"
4747
#include "ximgproc/estimated_covariance.hpp"
48+
#include "ximgproc/weighted_median_filter.hpp"
4849
#include "ximgproc/slic.hpp"
4950
#include "ximgproc/lsc.hpp"
5051

modules/ximgproc/include/opencv2/ximgproc/edge_filter.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ void jointBilateralFilter(InputArray joint, InputArray src, OutputArray dst, int
321321

322322
/** @brief Applies the rolling guidance filter to an image.
323323
324+
For more details, please see @cite zhang2014rolling
325+
324326
@param src Source 8-bit or floating-point, 1-channel or 3-channel image.
325327
326328
@param dst Destination image of the same size and type as src.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*M///////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4+
//
5+
// By downloading, copying, installing or using the software you agree to this license.
6+
// If you do not agree to this license, do not download, install,
7+
// copy or use the software.
8+
//
9+
//
10+
// License Agreement
11+
// For Open Source Computer Vision Library
12+
//
13+
// Copyright (C) 2015, The Chinese University of Hong Kong, all rights reserved.
14+
//
15+
// Third party copyrights are property of their respective owners.
16+
//
17+
// Redistribution and use in source and binary forms, with or without modification,
18+
// are permitted provided that the following conditions are met:
19+
//
20+
// * Redistribution's of source code must retain the above copyright notice,
21+
// this list of conditions and the following disclaimer.
22+
//
23+
// * Redistribution's in binary form must reproduce the above copyright notice,
24+
// this list of conditions and the following disclaimer in the documentation
25+
// and/or other materials provided with the distribution.
26+
//
27+
// * The name of the copyright holders may not be used to endorse or promote products
28+
// derived from this software without specific prior written permission.
29+
//
30+
// This software is provided by the copyright holders and contributors "as is" and
31+
// any express or implied warranties, including, but not limited to, the implied
32+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33+
// In no event shall the Intel Corporation or contributors be liable for any direct,
34+
// indirect, incidental, special, exemplary, or consequential damages
35+
// (including, but not limited to, procurement of substitute goods or services;
36+
// loss of use, data, or profits; or business interruption) however caused
37+
// and on any theory of liability, whether in contract, strict liability,
38+
// or tort (including negligence or otherwise) arising in any way out of
39+
// the use of this software, even if advised of the possibility of such damage.
40+
//
41+
//M*/
42+
43+
#ifndef __OPENCV_WEIGHTED_MEDIAN_FILTER_HPP__
44+
#define __OPENCV_WEIGHTED_MEDIAN_FILTER_HPP__
45+
#ifdef __cplusplus
46+
47+
/**
48+
* @file
49+
* @date Sept 9, 2015
50+
* @author Zhou Chao
51+
*/
52+
53+
#include <opencv2/core.hpp>
54+
#include <string>
55+
56+
namespace cv
57+
{
58+
namespace ximgproc
59+
{
60+
61+
/**
62+
* @brief Specifies weight types of weighted median filter.
63+
*/
64+
enum WMFWeightType
65+
{
66+
WMF_EXP, //!< \f$exp(-|I1-I2|^2/(2*sigma^2))\f$
67+
WMF_IV1, //!< \f$(|I1-I2|+sigma)^-1\f$
68+
WMF_IV2, //!< \f$(|I1-I2|^2+sigma^2)^-1\f$
69+
WMF_COS, //!< \f$dot(I1,I2)/(|I1|*|I2|)\f$
70+
WMF_JAC, //!< \f$(min(r1,r2)+min(g1,g2)+min(b1,b2))/(max(r1,r2)+max(g1,g2)+max(b1,b2))\f$
71+
WMF_OFF //!< unweighted
72+
};
73+
74+
/**
75+
* @brief Applies weighted median filter to an image.
76+
*
77+
* For more details about this implementation, please see @cite zhang2014100+
78+
*
79+
* @param joint Joint 8-bit, 1-channel or 3-channel image.
80+
* @param src Source 8-bit or floating-point, 1-channel or 3-channel image.
81+
* @param dst Destination image.
82+
* @param r Radius of filtering kernel, should be a positive integer.
83+
* @param sigma Filter range standard deviation for the joint image.
84+
* @param weightType weightType The type of weight definition, see WMFWeightType
85+
* @param mask A 0-1 mask that has the same size with I. This mask is used to ignore the effect of some pixels. If the pixel value on mask is 0,
86+
* the pixel will be ignored when maintaining the joint-histogram. This is useful for applications like optical flow occlusion handling.
87+
*
88+
* @sa medianBlur, jointBilateralFilter
89+
*/
90+
CV_EXPORTS void weightedMedianFilter(InputArray joint, InputArray src, OutputArray dst, int r, double sigma=25.5, WMFWeightType weightType=WMF_EXP, Mat mask=Mat());
91+
}
92+
}
93+
94+
#endif
95+
#endif
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
#include "perf_precomp.hpp"
38+
39+
namespace cvtest
40+
{
41+
42+
using std::tr1::tuple;
43+
using std::tr1::get;
44+
using namespace perf;
45+
using namespace testing;
46+
using namespace cv;
47+
using namespace cv::ximgproc;
48+
49+
typedef tuple<Size, MatType, int, int, int, WMFWeightType> WMFTestParam;
50+
typedef TestBaseWithParam<WMFTestParam> WeightedMedianFilterTest;
51+
52+
PERF_TEST_P(WeightedMedianFilterTest, perf,
53+
Combine(
54+
Values(szODD, szQVGA),
55+
Values(CV_8U, CV_32F),
56+
Values(1, 3),
57+
Values(1, 3),
58+
Values(3, 5),
59+
Values(WMF_EXP, WMF_COS))
60+
)
61+
{
62+
RNG rnd(1);
63+
64+
WMFTestParam params = GetParam();
65+
66+
double sigma = rnd.uniform(20.0, 30.0);
67+
Size sz = get<0>(params);
68+
int srcDepth = get<1>(params);
69+
int jCn = get<2>(params);
70+
int srcCn = get<3>(params);
71+
int r = get<4>(params);
72+
WMFWeightType weightType = get<5>(params);
73+
74+
Mat joint(sz, CV_MAKE_TYPE(CV_8U, jCn));
75+
Mat src(sz, CV_MAKE_TYPE(srcDepth, srcCn));
76+
Mat dst(sz, src.type());
77+
78+
cv::setNumThreads(cv::getNumberOfCPUs());
79+
declare.in(joint, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs());
80+
81+
TEST_CYCLE_N(1)
82+
{
83+
weightedMedianFilter(joint, src, dst, r, sigma, weightType);
84+
}
85+
86+
SANITY_CHECK_NOTHING();
87+
}
88+
}

0 commit comments

Comments
 (0)