Merge pull request #467 from vpisarev:fuzzy
commit
efee450611
20 changed files with 1162 additions and 0 deletions
@ -0,0 +1,3 @@ |
||||
set(the_description "Fuzzy mathematical image processing") |
||||
|
||||
ocv_define_module(fuzzy opencv_imgproc opencv_core) |
@ -0,0 +1,26 @@ |
||||
Fuzzy image processing |
||||
======================= |
||||
|
||||
Author and maintainer: Pavel Vlasanek |
||||
pavel.vlasanek@osu.cz |
||||
|
||||
This module is focused on the image processing using fuzzy mathematics, namely fuzzy (F)-transform. The F-transform technique approximates input function, where only few input values are known. The technique of F-transform takes local areas as areas with some additional structure. This structure is characterized by fuzzy predicates that may express any information which is relevant for a problem. In image processing, this can be, for example, a distance from a certain point, a relationship between points, color/intensity, texture, etc. |
||||
|
||||
The F-transform is a technique putting a continuous/discrete function into a correspondence with a finite vector of its F-transform components. In image processing, where images are identified with intensity functions of two arguments, the F-transform of the latter is given by a matrix of components. The module currently covering F0-trasnform, where components are scalars. |
||||
|
||||
The components can be used for inverse F-transform, where approximated input function is obtained. If input function (image) includes some damaged or missing areas, these areas are recomputed and restored after invesre F-transform processing. |
||||
|
||||
Let me give you two related papers: |
||||
|
||||
Perfilieva, Irina, and Pavel Vlašánek. "Image Reconstruction by means of F-transform." Knowledge-Based Systems 70 (2014): 55-63. |
||||
|
||||
Perfilieva, Irina. "Fuzzy transforms: Theory and applications." Fuzzy sets and systems 157.8 (2006): 993-1023. |
||||
|
||||
Investigation of the F-transform technique leads to several applications in image processing. Currently investigated are image inpainting, filtering, resampling, edge detection, compression and image fusion. |
||||
|
||||
The module covers: |
||||
|
||||
* F0 processing (fuzzy_F0_math.cpp): Functions for computation of the image F0 components and inverse F0-transform. |
||||
* Fuzzy image processing (fuzzy_image.cpp): Functions aimed to image processing currently including image inpainting and image filtering. |
||||
|
||||
There are also tests in test_image.cpp using resources from opencv_extra, and samples in fuzzy_inpainting.cpp and fuzzy_filtering.cpp. |
@ -0,0 +1,22 @@ |
||||
@article{Perf:FT, |
||||
title={Fuzzy transforms: Theory and applications}, |
||||
author={Perfilieva, Irina}, |
||||
journal={Fuzzy sets and systems}, |
||||
volume={157}, |
||||
number={8}, |
||||
pages={993--1023}, |
||||
year={2006}, |
||||
publisher={Elsevier} |
||||
} |
||||
|
||||
@article{Perf:rec, |
||||
title={Image Reconstruction by means of F-transform}, |
||||
author={Perfilieva, Irina and Vla{\v{s}}{\'a}nek, Pavel}, |
||||
journal={Knowledge-Based Systems}, |
||||
keywords = {myown}, |
||||
volume={70}, |
||||
pages={55--63}, |
||||
year={2014}, |
||||
doi = {10.1016/j.knosys.2014.04.007}, |
||||
publisher={Elsevier} |
||||
} |
@ -0,0 +1,66 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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_FUZZY_H__ |
||||
#define __OPENCV_FUZZY_H__ |
||||
|
||||
#include "opencv2/fuzzy/types.hpp" |
||||
#include "opencv2/fuzzy/fuzzy_F0_math.hpp" |
||||
#include "opencv2/fuzzy/fuzzy_image.hpp" |
||||
|
||||
/**
|
||||
@defgroup fuzzy Image processing based on fuzzy mathematics |
||||
|
||||
Namespace for all functions is **ft**. The module brings implementation of the last image processing algorithms based on fuzzy mathematics. |
||||
|
||||
@{ |
||||
@defgroup f0_math Math with F0-transfrom support |
||||
|
||||
Fuzzy transform (F-transform) of the 0th degree transform whole image to a vector of its components. These components are used in latter computation. |
||||
|
||||
@defgroup f_image Fuzzy image processing |
||||
|
||||
Image proceesing based on F-transform is fast to process and easy to understand. |
||||
@} |
||||
|
||||
*/ |
||||
|
||||
#endif // __OPENCV_FUZZY_H__
|
@ -0,0 +1,119 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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_FUZZY_F0_MATH_H__ |
||||
#define __OPENCV_FUZZY_F0_MATH_H__ |
||||
|
||||
#include "opencv2/fuzzy/types.hpp" |
||||
#include "opencv2/core.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
namespace ft |
||||
{ |
||||
//! @addtogroup f0_math
|
||||
//! @{
|
||||
|
||||
/** @brief Computes components of the array using direct F0-transform.
|
||||
@param matrix Input 1-channel array. |
||||
@param kernel Kernel used for processing. Function **createKernel** can be used. |
||||
@param components Output 32-bit array for the components. |
||||
@param mask Mask can be used for unwanted area marking. |
||||
|
||||
The function computes components using predefined kernel and mask. |
||||
|
||||
@note |
||||
F-transform technique is described in paper @cite Perf:FT. |
||||
*/ |
||||
CV_EXPORTS void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask); |
||||
|
||||
/** @brief Computes components of the array using direct F0-transform.
|
||||
@param matrix Input 1-channel array. |
||||
@param kernel Kernel used for processing. Function **createKernel** can be used. |
||||
@param components Output 32-bit array for the components. |
||||
|
||||
The function computes components using predefined kernel. |
||||
|
||||
@note |
||||
F-transform technique is described in paper @cite Perf:FT. |
||||
*/ |
||||
CV_EXPORTS void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components); |
||||
|
||||
/** @brief Computes inverse F0-transfrom.
|
||||
@param components Input 32-bit array for the components. |
||||
@param kernel Kernel used for processing. Function **createKernel** can be used. |
||||
@param output Output 32-bit array. |
||||
@param width Width of the output array. |
||||
@param height Height of the output array. |
||||
|
||||
@note |
||||
F-transform technique is described in paper @cite Perf:FT. |
||||
*/ |
||||
CV_EXPORTS void FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); |
||||
|
||||
/** @brief Computes F0-transfrom and inverse F0-transfrom at once.
|
||||
@param image Input image. |
||||
@param kernel Kernel used for processing. Function **createKernel** can be used. |
||||
@param output Output 32-bit array. |
||||
@param mask Mask used for unwanted area marking. |
||||
|
||||
This function computes F-transfrom and inverse F-transfotm in one step. It is fully sufficient and optimized for **Mat**. |
||||
*/ |
||||
CV_EXPORTS void FT02D_process(const Mat &image, const Mat &kernel, Mat &output, const Mat &mask); |
||||
|
||||
/** @brief Computes F0-transfrom and inverse F0-transfrom at once and return state.
|
||||
@param image Input image. |
||||
@param kernel Kernel used for processing. Function **createKernel** can be used. |
||||
@param imageOutput Output 32-bit array. |
||||
@param mask Mask used for unwanted area marking. |
||||
@param maskOutput Mask after one iteration. |
||||
@param firstStop If **true** function returns -1 when first problem appears. In case of **false**, the process is completed and summation of all problems returned. |
||||
|
||||
This function computes iteration of F-transfrom and inverse F-transfotm and handle image and mask change. The function is used in *inpaint* function. |
||||
*/ |
||||
CV_EXPORTS int FT02D_iteration(const Mat &image, const Mat &kernel, Mat &imageOutput, const Mat &mask, Mat &maskOutput, bool firstStop = true); |
||||
|
||||
//! @}
|
||||
} |
||||
} |
||||
|
||||
#endif // __OPENCV_FUZZY_F0_MATH_H__
|
@ -0,0 +1,109 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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_FUZZY_IMAGE_H__ |
||||
#define __OPENCV_FUZZY_IMAGE_H__ |
||||
|
||||
#include "types.hpp" |
||||
#include "opencv2/core.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
namespace ft |
||||
{ |
||||
//! @addtogroup f_image
|
||||
//! @{
|
||||
|
||||
/** @brief Creates kernel from basic functions.
|
||||
@param A Basic function used in axis **x**. |
||||
@param B Basic function used in axis **y**. |
||||
@param kernel Final 32-b kernel derived from **A** and **B**. |
||||
@param chn Number of kernel channels. |
||||
|
||||
The function creates kernel usable for latter fuzzy image processing. |
||||
*/ |
||||
CV_EXPORTS void createKernel(cv::InputArray A, cv::InputArray B, cv::OutputArray kernel, const int chn = 1); |
||||
|
||||
/** @brief Creates kernel from general functions.
|
||||
@param function Function type could be one of the following: |
||||
- **LINEAR** Linear basic function. |
||||
@param radius Radius of the basic function. |
||||
@param kernel Final 32-b kernel. |
||||
@param chn Number of kernel channels. |
||||
|
||||
The function creates kernel from predefined functions. |
||||
*/ |
||||
CV_EXPORTS void createKernel(int function, int radius, cv::OutputArray kernel, const int chn = 1); |
||||
|
||||
/** @brief Image inpainting
|
||||
@param image Input image. |
||||
@param mask Mask used for unwanted area marking. |
||||
@param output Output 32-bit image. |
||||
@param radius Radius of the basic function. |
||||
@param function Function type could be one of the following: |
||||
- **LINEAR** Linear basic function. |
||||
@param algorithm Algorithm could be one of the following: |
||||
- **ONE_STEP** One step algorithm. |
||||
- **MULTI_STEP** Algorithm automaticaly increasing radius of the basic function. |
||||
- **ITERATIVE** Iterative algorithm running in more steps using partial computations. |
||||
|
||||
This function provides inpainting technique based on the fuzzy mathematic. |
||||
|
||||
@note |
||||
The algorithms are described in paper @cite Perf:rec. |
||||
*/ |
||||
CV_EXPORTS void inpaint(const cv::Mat &image, const cv::Mat &mask, cv::Mat &output, int radius = 2, int function = ft::LINEAR, int algorithm = ft::ONE_STEP); |
||||
|
||||
/** @brief Image filtering
|
||||
@param image Input image. |
||||
@param kernel Final 32-b kernel. |
||||
@param output Output 32-bit image. |
||||
|
||||
Filtering of the input image by means of F-transform. |
||||
*/ |
||||
CV_EXPORTS void filter(const cv::Mat &image, const cv::Mat &kernel, cv::Mat &output); |
||||
|
||||
//! @}
|
||||
} |
||||
} |
||||
|
||||
#endif // __OPENCV_FUZZY_IMAGE_H__
|
@ -0,0 +1,70 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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_FUZZY_TYPES_H__ |
||||
#define __OPENCV_FUZZY_TYPES_H__ |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
namespace ft |
||||
{ |
||||
//! @addtogroup fuzzy
|
||||
//! @{
|
||||
|
||||
enum
|
||||
{ |
||||
LINEAR = 1, |
||||
SINUS = 2 |
||||
}; |
||||
|
||||
enum
|
||||
{ |
||||
ONE_STEP = 1, |
||||
MULTI_STEP = 2, |
||||
ITERATIVE = 3 |
||||
}; |
||||
|
||||
//! @}
|
||||
} |
||||
} |
||||
|
||||
#endif // __OPENCV_FUZZY_TYPES_H__
|
@ -0,0 +1,47 @@ |
||||
/* Sample - Filtering
|
||||
* Target is to apply filtering using F-transform |
||||
* on the image "input.png". Two different kernels |
||||
* are used, where bigger radius (100 in this case) |
||||
* means higher level of blurriness. |
||||
* |
||||
* Image "output1_filter.png" is created from "input.png" |
||||
* using "kernel1" with radius 3. |
||||
* |
||||
* Image "output2_filter.png" is created from "input.png" |
||||
* using "kernel2" with radius 100. |
||||
* |
||||
* Both kernels are created from linear function, using |
||||
* linear interpolation (parametr ft:LINEAR). |
||||
*/ |
||||
|
||||
#include "opencv2/core.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include "opencv2/fuzzy.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
|
||||
int main(void) |
||||
{ |
||||
// Input image
|
||||
Mat I = imread("input.png"); |
||||
|
||||
// Kernel cretion
|
||||
Mat kernel1, kernel2; |
||||
|
||||
ft::createKernel(ft::LINEAR, 3, kernel1, 3); |
||||
ft::createKernel(ft::LINEAR, 100, kernel2, 3); |
||||
|
||||
// Filtering
|
||||
Mat output1, output2; |
||||
|
||||
ft::filter(I, kernel1, output1); |
||||
ft::filter(I, kernel2, output2); |
||||
|
||||
// Save output
|
||||
|
||||
imwrite("output1_filter.png", output1); |
||||
imwrite("output2_filter.png", output2); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,72 @@ |
||||
/* Sample - Inpainting
|
||||
* Target is to apply inpainting using F-transform |
||||
* on the image "input.png". The image is damaged |
||||
* by various types of corruption: |
||||
* |
||||
* input1 = image & mask1 |
||||
* input2 = image & mask2 |
||||
* input3 = image & mask3 |
||||
* |
||||
* Three algorithms "ft::ONE_STEP", "ft::MULTI_STEP" |
||||
* and "ft::ITERATIVE" are demonstrated on the |
||||
* appropriate type of damage. |
||||
* |
||||
* ft::ONE_STEP |
||||
* "output1_inpaint.png": input1, mask1 |
||||
* |
||||
* ft::MULTI_STEP |
||||
* "output2_inpaint.png": input2, mask2 |
||||
* "output3_inpaint.png": input3, mask3 |
||||
* |
||||
* ft::ITERATIVE |
||||
* "output4_inpaint.png": input3, mask3 |
||||
* |
||||
* Linear kernel with radius 2 is used for all |
||||
* samples. |
||||
*/ |
||||
|
||||
#include "opencv2/core.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
#include "opencv2/fuzzy.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
|
||||
int main(void) |
||||
{ |
||||
// Input image
|
||||
Mat I = imread("input.png"); |
||||
|
||||
// Various masks
|
||||
Mat mask1 = imread("mask1.png"); |
||||
Mat mask2 = imread("mask2.png"); |
||||
Mat mask3 = imread("mask3.png"); |
||||
|
||||
// Apply the damage
|
||||
Mat input1, input2, input3; |
||||
|
||||
I.copyTo(input1, mask1); |
||||
I.copyTo(input2, mask2); |
||||
I.copyTo(input3, mask3); |
||||
|
||||
// Inpaint with various algorithm
|
||||
Mat output1, output2, output3, output4; |
||||
|
||||
ft::inpaint(input1, mask1, output1, 2, ft::LINEAR, ft::ONE_STEP); |
||||
ft::inpaint(input2, mask2, output2, 2, ft::LINEAR, ft::MULTI_STEP); |
||||
ft::inpaint(input3, mask3, output3, 2, ft::LINEAR, ft::MULTI_STEP); |
||||
ft::inpaint(input3, mask3, output4, 2, ft::LINEAR, ft::ITERATIVE); |
||||
|
||||
// Save output
|
||||
imwrite("output1_inpaint.png", output1); |
||||
imwrite("output2_inpaint.png", output2); |
||||
imwrite("output3_inpaint.png", output3); |
||||
imwrite("output4_inpaint.png", output4); |
||||
|
||||
// Save damaged input for comparison
|
||||
imwrite("input1.png", input1); |
||||
imwrite("input2.png", input2); |
||||
imwrite("input3.png", input3); |
||||
|
||||
return 0; |
||||
} |
After Width: | Height: | Size: 399 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 3.0 KiB |
@ -0,0 +1,254 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
|
||||
void ft::FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask) |
||||
{ |
||||
Mat matrixMat = matrix.getMat(); |
||||
Mat kernelMat = kernel.getMat(); |
||||
Mat maskMat = mask.getMat(); |
||||
|
||||
CV_Assert(matrixMat.channels() == 1 && kernelMat.channels() == 1 && maskMat.channels() == 1); |
||||
|
||||
int radiusX = (kernelMat.cols - 1) / 2; |
||||
int radiusY = (kernelMat.rows - 1) / 2; |
||||
int An = matrixMat.cols / radiusX + 1; |
||||
int Bn = matrixMat.rows / radiusY + 1; |
||||
|
||||
Mat matrixPadded; |
||||
Mat maskPadded; |
||||
|
||||
copyMakeBorder(matrixMat, matrixPadded, radiusY, kernelMat.rows, radiusX, kernelMat.cols, BORDER_CONSTANT, Scalar(0)); |
||||
copyMakeBorder(maskMat, maskPadded, radiusY, kernelMat.rows, radiusX, kernelMat.cols, BORDER_CONSTANT, Scalar(0)); |
||||
|
||||
components.create(Bn, An, CV_32F); |
||||
Mat componentsMat = components.getMat(); |
||||
|
||||
for (int i = 0; i < An; i++) |
||||
{ |
||||
for (int o = 0; o < Bn; o++) |
||||
{ |
||||
int centerX = (i * radiusX) + radiusX; |
||||
int centerY = (o * radiusY) + radiusY; |
||||
Rect area(centerX - radiusX, centerY - radiusY, kernelMat.cols, kernelMat.rows); |
||||
|
||||
Mat roiImage(matrixPadded, area); |
||||
Mat roiMask(maskPadded, area); |
||||
Mat kernelMasked; |
||||
|
||||
kernelMat.copyTo(kernelMasked, roiMask); |
||||
|
||||
Mat numerator; |
||||
multiply(roiImage, kernelMasked, numerator, 1, CV_32F); |
||||
|
||||
componentsMat.row(o).col(i) = sum(numerator) / sum(kernelMasked); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void ft::FT02D_components(InputArray matrix, InputArray kernel, OutputArray components) |
||||
{ |
||||
Mat mask = Mat::ones(matrix.size(), CV_8U); |
||||
|
||||
ft::FT02D_components(matrix, kernel, components, mask); |
||||
} |
||||
|
||||
void ft::FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height) |
||||
{ |
||||
Mat componentsMat = components.getMat(); |
||||
Mat kernelMat = kernel.getMat(); |
||||
|
||||
CV_Assert(componentsMat.channels() == 1 && kernelMat.channels() == 1); |
||||
|
||||
int radiusX = (kernelMat.cols - 1) / 2; |
||||
int radiusY = (kernelMat.rows - 1) / 2; |
||||
int paddedOutputWidth = radiusX + width + kernelMat.cols; |
||||
int paddedOutputHeight = radiusY + height + kernelMat.rows; |
||||
|
||||
output.create(height, width, CV_32F); |
||||
|
||||
Mat outputZeroes(paddedOutputHeight, paddedOutputWidth, CV_32F, Scalar(0)); |
||||
|
||||
for (int i = 0; i < componentsMat.cols; i++) |
||||
{ |
||||
for (int o = 0; o < componentsMat.rows; o++) |
||||
{ |
||||
int centerX = (i * radiusX) + radiusX; |
||||
int centerY = (o * radiusY) + radiusY; |
||||
Rect area(centerX - radiusX, centerY - radiusY, kernelMat.cols, kernelMat.rows); |
||||
|
||||
Mat roiOutput(outputZeroes, area); |
||||
roiOutput += kernelMat.mul(componentsMat.at<float>(o,i)); |
||||
} |
||||
} |
||||
|
||||
outputZeroes(Rect(radiusX, radiusY, width, height)).copyTo(output); |
||||
} |
||||
|
||||
void ft::FT02D_process(const cv::Mat &image, const cv::Mat &kernel, cv::Mat &output, const cv::Mat &mask) |
||||
{ |
||||
CV_Assert(image.channels() == kernel.channels()); |
||||
|
||||
int radiusX = (kernel.cols - 1) / 2; |
||||
int radiusY = (kernel.rows - 1) / 2; |
||||
int An = image.cols / radiusX + 1; |
||||
int Bn = image.rows / radiusY + 1; |
||||
int outputWidthPadded = radiusX + image.cols + kernel.cols; |
||||
int outputHeightPadded = radiusY + image.rows + kernel.rows; |
||||
|
||||
Mat imagePadded; |
||||
Mat maskPadded; |
||||
|
||||
output = Mat::zeros(outputHeightPadded, outputWidthPadded, CV_MAKETYPE(CV_32F, image.channels())); |
||||
|
||||
copyMakeBorder(image, imagePadded, radiusY, kernel.rows, radiusX, kernel.cols, BORDER_CONSTANT, Scalar(0)); |
||||
copyMakeBorder(mask, maskPadded, radiusY, kernel.rows, radiusX, kernel.cols, BORDER_CONSTANT, Scalar(0)); |
||||
|
||||
for (int i = 0; i < An; i++) |
||||
{ |
||||
for (int o = 0; o < Bn; o++) |
||||
{ |
||||
int centerX = (i * radiusX) + radiusX; |
||||
int centerY = (o * radiusY) + radiusY; |
||||
Rect area(centerX - radiusX, centerY - radiusY, kernel.cols, kernel.rows); |
||||
|
||||
Mat roiImage(imagePadded, area); |
||||
Mat roiMask(maskPadded, area); |
||||
Mat kernelMasked; |
||||
|
||||
kernel.copyTo(kernelMasked, roiMask); |
||||
|
||||
Mat numerator; |
||||
multiply(roiImage, kernelMasked, numerator, 1, CV_32F); |
||||
|
||||
Scalar component; |
||||
divide(sum(numerator), sum(kernelMasked), component, 1, CV_32F); |
||||
|
||||
Mat inverse; |
||||
multiply(kernel, component, inverse, 1, CV_32F); |
||||
|
||||
Mat roiOutput(output, area); |
||||
add(roiOutput, inverse, roiOutput); |
||||
} |
||||
} |
||||
|
||||
output = output(Rect(radiusX, radiusY, image.cols, image.rows)); |
||||
} |
||||
|
||||
int ft::FT02D_iteration(const Mat &image, const Mat &kernel, Mat &imageOutput, const Mat &mask, Mat &maskOutput, bool firstStop) |
||||
{ |
||||
CV_Assert(image.channels() == kernel.channels() && mask.channels() == 1); |
||||
|
||||
int radiusX = (kernel.cols - 1) / 2; |
||||
int radiusY = (kernel.rows - 1) / 2; |
||||
int An = image.cols / radiusX + 1; |
||||
int Bn = image.rows / radiusY + 1; |
||||
int outputWidthPadded = radiusX + image.cols + kernel.cols; |
||||
int outputHeightPadded = radiusY + image.rows + kernel.rows; |
||||
int undefinedComponents = 0; |
||||
|
||||
Mat imagePadded; |
||||
Mat maskPadded; |
||||
|
||||
imageOutput = Mat::zeros(outputHeightPadded, outputWidthPadded, CV_MAKETYPE(CV_32F, image.channels())); |
||||
maskOutput = Mat::ones(outputHeightPadded, outputWidthPadded, CV_8UC1); |
||||
|
||||
copyMakeBorder(image, imagePadded, radiusY, kernel.rows, radiusX, kernel.cols, BORDER_CONSTANT, Scalar(0)); |
||||
copyMakeBorder(mask, maskPadded, radiusY, kernel.rows, radiusX, kernel.cols, BORDER_CONSTANT, Scalar(0)); |
||||
|
||||
for (int i = 0; i < An; i++) |
||||
{ |
||||
for (int o = 0; o < Bn; o++) |
||||
{ |
||||
int centerX = (i * radiusX) + radiusX; |
||||
int centerY = (o * radiusY) + radiusY; |
||||
Rect area(centerX - radiusX, centerY - radiusY, kernel.cols, kernel.rows); |
||||
|
||||
Mat roiImage(imagePadded, area); |
||||
Mat roiMask(maskPadded, area); |
||||
Mat kernelMasked; |
||||
|
||||
kernel.copyTo(kernelMasked, roiMask); |
||||
|
||||
Mat numerator; |
||||
multiply(roiImage, kernelMasked, numerator, 1, CV_32F); |
||||
|
||||
Scalar denominator = sum(kernelMasked); |
||||
|
||||
if (denominator[0] == 0) |
||||
{ |
||||
if (firstStop) |
||||
{ |
||||
imageOutput = imageOutput(Rect(radiusX, radiusY, image.cols, image.rows)); |
||||
maskOutput = maskPadded(Rect(radiusX, radiusY, image.cols, image.rows)); |
||||
|
||||
return -1; |
||||
} |
||||
else |
||||
{ |
||||
undefinedComponents++; |
||||
|
||||
Mat roiMaskOutput(maskOutput, Rect(centerX - radiusX + 1, centerY - radiusY + 1, kernel.cols - 2, kernel.rows - 2)); |
||||
roiMaskOutput = 0; |
||||
|
||||
continue; |
||||
} |
||||
} |
||||
|
||||
Scalar component; |
||||
divide(sum(numerator), denominator, component, 1, CV_32F); |
||||
|
||||
Mat inverse; |
||||
multiply(kernel, component, inverse, 1, CV_32F); |
||||
|
||||
Mat roiImageOutput(imageOutput, area); |
||||
add(roiImageOutput, inverse, roiImageOutput); |
||||
} |
||||
} |
||||
|
||||
imageOutput = imageOutput(Rect(radiusX, radiusY, image.cols, image.rows)); |
||||
maskOutput = maskOutput(Rect(radiusX, radiusY, image.cols, image.rows)); |
||||
|
||||
return undefinedComponents; |
||||
} |
@ -0,0 +1,180 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
|
||||
void ft::createKernel(InputArray A, InputArray B, OutputArray kernel, const int chn) |
||||
{ |
||||
Mat AMat = A.getMat(); |
||||
Mat BMat = B.getMat(); |
||||
Mat kernelOneChannel = AMat * BMat; |
||||
std::vector<Mat> channels; |
||||
|
||||
for (int i = 0; i < chn; i++) |
||||
{ |
||||
channels.push_back(kernelOneChannel); |
||||
} |
||||
|
||||
merge(channels, kernel); |
||||
} |
||||
|
||||
void ft::createKernel(int function, int radius, cv::OutputArray kernel, const int chn) |
||||
{ |
||||
int basicFunctionWidth = 2 * radius + 1; |
||||
Mat kernelOneChannel; |
||||
Mat A(1, basicFunctionWidth, CV_32F, 0.0f); |
||||
std::vector<Mat> channels; |
||||
|
||||
A.at<float>(0, radius) = 1; |
||||
|
||||
if (function == ft::LINEAR) |
||||
{ |
||||
float a = 1.0f / radius; |
||||
|
||||
for (int i = 1; i < radius; i++) |
||||
{ |
||||
float previous = A.at<float>(0, i - 1); |
||||
float current = previous + a; |
||||
|
||||
A.at<float>(0, i) = current; |
||||
A.at<float>(0, (2 * radius) - i) = current; |
||||
} |
||||
|
||||
mulTransposed(A, kernelOneChannel, true); |
||||
} |
||||
|
||||
for (int i = 0; i < chn; i++) |
||||
{ |
||||
channels.push_back(kernelOneChannel); |
||||
} |
||||
|
||||
merge(channels, kernel); |
||||
} |
||||
|
||||
void ft::inpaint(const cv::Mat &image, const cv::Mat &mask, cv::Mat &output, int radius, int function, int algorithm) |
||||
{ |
||||
if (algorithm == ft::ONE_STEP) |
||||
{ |
||||
Mat kernel; |
||||
ft::createKernel(function, radius, kernel, image.channels()); |
||||
|
||||
Mat processingInput; |
||||
image.convertTo(processingInput, CV_32F); |
||||
|
||||
Mat processingOutput; |
||||
ft::FT02D_process(processingInput, kernel, processingOutput, mask); |
||||
|
||||
processingInput.copyTo(processingOutput, mask); |
||||
|
||||
output = processingOutput; |
||||
} |
||||
else if (algorithm == ft::MULTI_STEP) |
||||
{ |
||||
Mat kernel; |
||||
Mat processingOutput; |
||||
Mat outpuMask; |
||||
int state = 0; |
||||
int currentRadius = radius; |
||||
|
||||
Mat processingInput; |
||||
image.convertTo(processingInput, CV_32F); |
||||
|
||||
Mat processingMask; |
||||
cvtColor(mask, processingMask, COLOR_BGR2GRAY); |
||||
|
||||
do |
||||
{ |
||||
ft::createKernel(function, currentRadius, kernel, image.channels()); |
||||
|
||||
state = ft::FT02D_iteration(processingInput, kernel, processingOutput, processingMask, outpuMask, true); |
||||
|
||||
currentRadius++; |
||||
} |
||||
while(state != 0); |
||||
|
||||
processingInput.copyTo(processingOutput, mask); |
||||
|
||||
output = processingOutput; |
||||
} |
||||
else if (algorithm == ft::ITERATIVE) |
||||
{ |
||||
Mat kernel; |
||||
Mat processingOutput; |
||||
Mat maskOutput; |
||||
int state = 0; |
||||
int currentRadius = radius; |
||||
|
||||
Mat originalImage; |
||||
image.convertTo(originalImage, CV_32F); |
||||
|
||||
Mat processingInput; |
||||
image.convertTo(processingInput, CV_32F); |
||||
|
||||
Mat processingMask; |
||||
cvtColor(mask, processingMask, COLOR_BGR2GRAY); |
||||
|
||||
do |
||||
{ |
||||
ft::createKernel(function, currentRadius, kernel, image.channels()); |
||||
|
||||
Mat invMask = 1 - processingMask; |
||||
|
||||
state = ft::FT02D_iteration(processingInput, kernel, processingOutput, processingMask, maskOutput, false); |
||||
|
||||
maskOutput.copyTo(processingMask); |
||||
processingOutput.copyTo(processingInput, invMask); |
||||
|
||||
currentRadius++; |
||||
} |
||||
while(state != 0); |
||||
|
||||
output = processingInput; |
||||
} |
||||
} |
||||
|
||||
void ft::filter(const cv::Mat &image, const cv::Mat &kernel, cv::Mat &output) |
||||
{ |
||||
Mat mask = Mat::ones(image.size(), CV_8U); |
||||
|
||||
ft::FT02D_process(image, kernel, output, mask); |
||||
} |
@ -0,0 +1,50 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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_PRECOMP_H__ |
||||
#define __OPENCV_PRECOMP_H__ |
||||
|
||||
#include "opencv2/core/private.hpp" |
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/fuzzy.hpp" |
||||
|
||||
#endif |
@ -0,0 +1,123 @@ |
||||
/*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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
|
||||
// Pavel Vlasanek, 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*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include <string> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
|
||||
class CV_FuzzyImageTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_FuzzyImageTest(); |
||||
~CV_FuzzyImageTest(); |
||||
protected: |
||||
void run(int); |
||||
}; |
||||
|
||||
CV_FuzzyImageTest::CV_FuzzyImageTest() |
||||
{ |
||||
} |
||||
CV_FuzzyImageTest::~CV_FuzzyImageTest() {} |
||||
|
||||
void CV_FuzzyImageTest::run( int ) |
||||
{ |
||||
string folder = string(ts->get_data_path()) + "fuzzy/"; |
||||
Mat orig = imread(folder + "orig.png"); |
||||
Mat exp1 = imread(folder + "exp1.png"); |
||||
Mat exp2 = imread(folder + "exp2.png"); |
||||
Mat exp3 = imread(folder + "exp3.png"); |
||||
Mat mask1 = imread(folder + "mask1.png"); |
||||
Mat mask2 = imread(folder + "mask2.png"); |
||||
|
||||
if (orig.empty() || exp1.empty() || exp2.empty() || mask1.empty() || mask2.empty()) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
// Conversion because of comparison.
|
||||
|
||||
orig.convertTo(orig, CV_32F); |
||||
exp1.convertTo(exp1, CV_32F); |
||||
exp2.convertTo(exp2, CV_32F); |
||||
exp3.convertTo(exp3, CV_32F); |
||||
|
||||
Mat res1, res2,res3; |
||||
ft::inpaint(orig, mask1, res1, 2, ft::LINEAR, ft::ONE_STEP); |
||||
ft::inpaint(orig, mask2, res2, 2, ft::LINEAR, ft::MULTI_STEP); |
||||
ft::inpaint(orig, mask2, res3, 2, ft::LINEAR, ft::ITERATIVE); |
||||
|
||||
Mat diff1, diff2, diff3; |
||||
absdiff(orig, res1, diff1); |
||||
absdiff(orig, res2, diff2); |
||||
absdiff(orig, res3, diff3); |
||||
|
||||
double n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask1.reshape(1)); |
||||
double n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask2.reshape(1)); |
||||
double n3 = cvtest::norm(diff3.reshape(1), NORM_INF, mask2.reshape(1)); |
||||
|
||||
if (n1 != 0 || n2 != 0 || n3 != 0) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
return; |
||||
} |
||||
|
||||
absdiff(exp1, res1, diff1); |
||||
absdiff(exp2, res2, diff2); |
||||
absdiff(exp3, res3, diff3); |
||||
|
||||
n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask1.reshape(1)); |
||||
n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask2.reshape(1)); |
||||
n3 = cvtest::norm(diff3.reshape(1), NORM_INF, mask2.reshape(1)); |
||||
|
||||
const int jpeg_thres = 3; |
||||
if (n1 > jpeg_thres || n2 > jpeg_thres || n3 > jpeg_thres) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); |
||||
return; |
||||
} |
||||
|
||||
ts->set_failed_test_info(cvtest::TS::OK); |
||||
} |
||||
|
||||
TEST(Fuzzy_image, regression) { CV_FuzzyImageTest test; test.safe_run(); } |
@ -0,0 +1,3 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
CV_TEST_MAIN("cv") |
@ -0,0 +1,16 @@ |
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__ |
||||
#define __OPENCV_TEST_PRECOMP_HPP__ |
||||
|
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/imgcodecs.hpp" |
||||
#include "opencv2/fuzzy.hpp" |
||||
|
||||
#endif |
Loading…
Reference in new issue