-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add weighted median filter #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
modules/ximgproc/include/opencv2/ximgproc/weighted_median_filter.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /*M/////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. | ||
| // | ||
| // By downloading, copying, installing or using the software you agree to this license. | ||
| // If you do not agree to this license, do not download, install, | ||
| // copy or use the software. | ||
| // | ||
| // | ||
| // License Agreement | ||
| // For Open Source Computer Vision Library | ||
| // | ||
| // Copyright (C) 2015, The Chinese University of Hong Kong, all rights reserved. | ||
| // | ||
| // Third party copyrights are property of their respective owners. | ||
| // | ||
| // Redistribution and use in source and binary forms, with or without modification, | ||
| // are permitted provided that the following conditions are met: | ||
| // | ||
| // * Redistribution's of source code must retain the above copyright notice, | ||
| // this list of conditions and the following disclaimer. | ||
| // | ||
| // * Redistribution's in binary form must reproduce the above copyright notice, | ||
| // this list of conditions and the following disclaimer in the documentation | ||
| // and/or other materials provided with the distribution. | ||
| // | ||
| // * The name of the copyright holders may not be used to endorse or promote products | ||
| // derived from this software without specific prior written permission. | ||
| // | ||
| // This software is provided by the copyright holders and contributors "as is" and | ||
| // any express or implied warranties, including, but not limited to, the implied | ||
| // warranties of merchantability and fitness for a particular purpose are disclaimed. | ||
| // In no event shall the Intel Corporation or contributors be liable for any direct, | ||
| // indirect, incidental, special, exemplary, or consequential damages | ||
| // (including, but not limited to, procurement of substitute goods or services; | ||
| // loss of use, data, or profits; or business interruption) however caused | ||
| // and on any theory of liability, whether in contract, strict liability, | ||
| // or tort (including negligence or otherwise) arising in any way out of | ||
| // the use of this software, even if advised of the possibility of such damage. | ||
| // | ||
| //M*/ | ||
|
|
||
| #ifndef __OPENCV_WEIGHTED_MEDIAN_FILTER_HPP__ | ||
| #define __OPENCV_WEIGHTED_MEDIAN_FILTER_HPP__ | ||
| #ifdef __cplusplus | ||
|
|
||
| /** | ||
| * @file | ||
| * @date Sept 9, 2015 | ||
| * @author Zhou Chao | ||
| */ | ||
|
|
||
| #include <opencv2/core.hpp> | ||
| #include <string> | ||
|
|
||
| namespace cv | ||
| { | ||
| namespace ximgproc | ||
| { | ||
|
|
||
| /** | ||
| * @brief Specifies weight types of weighted median filter. | ||
| */ | ||
| enum WMFWeightType | ||
| { | ||
| WMF_EXP, //!< \f$exp(-|I1-I2|^2/(2*sigma^2))\f$ | ||
| WMF_IV1, //!< \f$(|I1-I2|+sigma)^-1\f$ | ||
| WMF_IV2, //!< \f$(|I1-I2|^2+sigma^2)^-1\f$ | ||
| WMF_COS, //!< \f$dot(I1,I2)/(|I1|*|I2|)\f$ | ||
| WMF_JAC, //!< \f$(min(r1,r2)+min(g1,g2)+min(b1,b2))/(max(r1,r2)+max(g1,g2)+max(b1,b2))\f$ | ||
| WMF_OFF //!< unweighted | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Applies weighted median filter to an image. | ||
| * | ||
| * For more details about this implementation, please see @cite zhang2014100+ | ||
| * | ||
| * @param joint Joint 8-bit, 1-channel or 3-channel image. | ||
| * @param src Source 8-bit or floating-point, 1-channel or 3-channel image. | ||
| * @param dst Destination image. | ||
| * @param r Radius of filtering kernel, should be a positive integer. | ||
| * @param sigma Filter range standard deviation for the joint image. | ||
| * @param weightType weightType The type of weight definition, see WMFWeightType | ||
| * @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, | ||
| * the pixel will be ignored when maintaining the joint-histogram. This is useful for applications like optical flow occlusion handling. | ||
| * | ||
| * @sa medianBlur, jointBilateralFilter | ||
| */ | ||
| CV_EXPORTS void weightedMedianFilter(InputArray joint, InputArray src, OutputArray dst, int r, double sigma=25.5, WMFWeightType weightType=WMF_EXP, Mat mask=Mat()); | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * By downloading, copying, installing or using the software you agree to this license. | ||
| * If you do not agree to this license, do not download, install, | ||
| * copy or use the software. | ||
| * | ||
| * | ||
| * License Agreement | ||
| * For Open Source Computer Vision Library | ||
| * (3 - clause BSD License) | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without modification, | ||
| * are permitted provided that the following conditions are met : | ||
| * | ||
| * *Redistributions of source code must retain the above copyright notice, | ||
| * this list of conditions and the following disclaimer. | ||
| * | ||
| * * Redistributions in binary form must reproduce the above copyright notice, | ||
| * this list of conditions and the following disclaimer in the documentation | ||
| * and / or other materials provided with the distribution. | ||
| * | ||
| * * Neither the names of the copyright holders nor the names of the contributors | ||
| * may be used to endorse or promote products derived from this software | ||
| * without specific prior written permission. | ||
| * | ||
| * This software is provided by the copyright holders and contributors "as is" and | ||
| * any express or implied warranties, including, but not limited to, the implied | ||
| * warranties of merchantability and fitness for a particular purpose are disclaimed. | ||
| * In no event shall copyright holders or contributors be liable for any direct, | ||
| * indirect, incidental, special, exemplary, or consequential damages | ||
| * (including, but not limited to, procurement of substitute goods or services; | ||
| * loss of use, data, or profits; or business interruption) however caused | ||
| * and on any theory of liability, whether in contract, strict liability, | ||
| * or tort(including negligence or otherwise) arising in any way out of | ||
| * the use of this software, even if advised of the possibility of such damage. | ||
| */ | ||
|
|
||
| #include "perf_precomp.hpp" | ||
|
|
||
| namespace cvtest | ||
| { | ||
|
|
||
| using std::tr1::tuple; | ||
| using std::tr1::get; | ||
| using namespace perf; | ||
| using namespace testing; | ||
| using namespace cv; | ||
| using namespace cv::ximgproc; | ||
|
|
||
| typedef tuple<Size, MatType, int, int, int, WMFWeightType> WMFTestParam; | ||
| typedef TestBaseWithParam<WMFTestParam> WeightedMedianFilterTest; | ||
|
|
||
| PERF_TEST_P(WeightedMedianFilterTest, perf, | ||
| Combine( | ||
| Values(szODD, szQVGA), | ||
| Values(CV_8U, CV_32F), | ||
| Values(1, 3), | ||
| Values(1, 3), | ||
| Values(3, 5), | ||
| Values(WMF_EXP, WMF_COS)) | ||
| ) | ||
| { | ||
| RNG rnd(1); | ||
|
|
||
| WMFTestParam params = GetParam(); | ||
|
|
||
| double sigma = rnd.uniform(20.0, 30.0); | ||
| Size sz = get<0>(params); | ||
| int srcDepth = get<1>(params); | ||
| int jCn = get<2>(params); | ||
| int srcCn = get<3>(params); | ||
| int r = get<4>(params); | ||
| WMFWeightType weightType = get<5>(params); | ||
|
|
||
| Mat joint(sz, CV_MAKE_TYPE(CV_8U, jCn)); | ||
| Mat src(sz, CV_MAKE_TYPE(srcDepth, srcCn)); | ||
| Mat dst(sz, src.type()); | ||
|
|
||
| cv::setNumThreads(cv::getNumberOfCPUs()); | ||
| declare.in(joint, src, WARMUP_RNG).out(dst).tbb_threads(cv::getNumberOfCPUs()); | ||
|
|
||
| TEST_CYCLE_N(1) | ||
| { | ||
| weightedMedianFilter(joint, src, dst, r, sigma, weightType); | ||
| } | ||
|
|
||
| SANITY_CHECK_NOTHING(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference to this paper should be added to the corresponding filter documentation.