Skip to content

Commit bb937e5

Browse files
committed
Merge pull request #1174 from tucna:F1_transform
2 parents 5e4d9b0 + 25c4888 commit bb937e5

File tree

8 files changed

+886
-69
lines changed

8 files changed

+886
-69
lines changed

modules/fuzzy/doc/fuzzy.bib

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ @article{Perf:rec
2020
doi = {10.1016/j.knosys.2014.04.007},
2121
publisher={Elsevier}
2222
}
23+
24+
@article{Vlas:FT,
25+
title={The F-transform in Terms of Image Processing Tools},
26+
author={Vla{\v{s}}{\'a}nek, Pavel and Perfilieva, Irina},
27+
journal={Journal of Fuzzy Set Valued Analysis},
28+
volume={2016},
29+
number={1},
30+
pages={54--62},
31+
year={2016}
32+
}

modules/fuzzy/include/opencv2/fuzzy.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#include "opencv2/fuzzy/types.hpp"
4646
#include "opencv2/fuzzy/fuzzy_F0_math.hpp"
47+
#include "opencv2/fuzzy/fuzzy_F1_math.hpp"
4748
#include "opencv2/fuzzy/fuzzy_image.hpp"
4849

4950
/**
@@ -52,13 +53,17 @@
5253
Namespace for all functions is **ft**. The module brings implementation of the last image processing algorithms based on fuzzy mathematics.
5354
5455
@{
55-
@defgroup f0_math Math with F0-transfrom support
56+
@defgroup f0_math Math with F0-transform support
5657
57-
Fuzzy transform (F-transform) of the 0th degree transform whole image to a vector of its components. These components are used in latter computation.
58+
Fuzzy transform (F0-transform) of the 0th degree transforms whole image to a matrix of its components. These components are used in latter computation where each of them represents average color of certain subarea.
59+
60+
@defgroup f1_math Math with F1-transform support
61+
62+
Fuzzy transform (F1-transform) of the 1th degree transforms whole image to a matrix of its components. Each component is polynomial of the 1th degree carrying information about average color and average gradient of certain subarea.
5863
5964
@defgroup f_image Fuzzy image processing
6065
61-
Image proceesing based on F-transform is fast to process and easy to understand.
66+
Image proceesing based on fuzzy mathematics namely F-transform.
6267
@}
6368
6469
*/

modules/fuzzy/include/opencv2/fuzzy/fuzzy_F0_math.hpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,20 @@ namespace ft
5656
/** @brief Computes components of the array using direct F0-transform.
5757
@param matrix Input array.
5858
@param kernel Kernel used for processing. Function **createKernel** can be used.
59-
@param components Output 32-bit array for the components.
59+
@param components Output 32-bit float array for the components.
6060
@param mask Mask can be used for unwanted area marking.
6161
6262
The function computes components using predefined kernel and mask.
6363
6464
@note
6565
F-transform technique is described in paper @cite Perf:FT.
6666
*/
67-
CV_EXPORTS_AS(FT02D_components1) void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask);
68-
69-
/** @brief Computes components of the array using direct F0-transform.
70-
@param matrix Input array.
71-
@param kernel Kernel used for processing. Function **createKernel** can be used.
72-
@param components Output 32-bit array for the components.
73-
74-
The function computes components using predefined kernel.
75-
76-
@note
77-
F-transform technique is described in paper @cite Perf:FT.
78-
*/
79-
CV_EXPORTS_W void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components);
67+
CV_EXPORTS_W void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask = noArray());
8068

8169
/** @brief Computes inverse F0-transfrom.
82-
@param components Input 32-bit single channel array for the components.
70+
@param components Input 32-bit float single channel array for the components.
8371
@param kernel Kernel used for processing. Function **createKernel** can be used.
84-
@param output Output 32-bit array.
72+
@param output Output 32-bit float array.
8573
@param width Width of the output array.
8674
@param height Height of the output array.
8775
@@ -93,26 +81,17 @@ namespace ft
9381
/** @brief Computes F0-transfrom and inverse F0-transfrom at once.
9482
@param matrix Input matrix.
9583
@param kernel Kernel used for processing. Function **createKernel** can be used.
96-
@param output Output 32-bit array.
84+
@param output Output 32-bit float array.
9785
@param mask Mask used for unwanted area marking.
9886
9987
This function computes F-transfrom and inverse F-transfotm in one step. It is fully sufficient and optimized for **Mat**.
10088
*/
101-
CV_EXPORTS_AS(FT02D_process1) void FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask);
102-
103-
/** @brief Computes F0-transfrom and inverse F0-transfrom at once.
104-
@param matrix Input matrix.
105-
@param kernel Kernel used for processing. Function **createKernel** can be used.
106-
@param output Output 32-bit array.
107-
108-
This function computes F-transfrom and inverse F-transfotm in one step. It is fully sufficient and optimized for **Mat**.
109-
*/
110-
CV_EXPORTS_W void FT02D_process(InputArray matrix, InputArray kernel, OutputArray output);
89+
CV_EXPORTS_W void FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray());
11190

11291
/** @brief Computes F0-transfrom and inverse F0-transfrom at once and return state.
11392
@param matrix Input matrix.
11493
@param kernel Kernel used for processing. Function **createKernel** can be used.
115-
@param output Output 32-bit array.
94+
@param output Output 32-bit float array.
11695
@param mask Mask used for unwanted area marking.
11796
@param maskOutput Mask after one iteration.
11897
@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.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling,
14+
// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners.
15+
//
16+
// Redistribution and use in source and binary forms, with or without modification,
17+
// are permitted provided that the following conditions are met:
18+
//
19+
// * Redistribution's of source code must retain the above copyright notice,
20+
// this list of conditions and the following disclaimer.
21+
//
22+
// * Redistribution's in binary form must reproduce the above copyright notice,
23+
// this list of conditions and the following disclaimer in the documentation
24+
// and/or other materials provided with the distribution.
25+
//
26+
// * The name of the copyright holders may not be used to endorse or promote products
27+
// derived from this software without specific prior written permission.
28+
//
29+
// This software is provided by the copyright holders and contributors "as is" and
30+
// any express or implied warranties, including, but not limited to, the implied
31+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32+
// In no event shall the Intel Corporation or contributors be liable for any direct,
33+
// indirect, incidental, special, exemplary, or consequential damages
34+
// (including, but not limited to, procurement of substitute goods or services;
35+
// loss of use, data, or profits; or business interruption) however caused
36+
// and on any theory of liability, whether in contract, strict liability,
37+
// or tort (including negligence or otherwise) arising in any way out of
38+
// the use of this software, even if advised of the possibility of such damage.
39+
//
40+
//M*/
41+
42+
#ifndef __OPENCV_FUZZY_F1_MATH_H__
43+
#define __OPENCV_FUZZY_F1_MATH_H__
44+
45+
#include "opencv2/fuzzy/types.hpp"
46+
#include "opencv2/core.hpp"
47+
48+
namespace cv
49+
{
50+
51+
namespace ft
52+
{
53+
//! @addtogroup f1_math
54+
//! @{
55+
56+
/** @brief Computes components of the array using direct F1-transform.
57+
@param matrix Input array.
58+
@param kernel Kernel used for processing. Function **createKernel** can be used.
59+
@param components Output 32-bit float array for the components.
60+
61+
The function computes linear components using predefined kernel.
62+
63+
@note
64+
F-transform technique of first degreee is described in paper @cite Vlas:FT.
65+
*/
66+
CV_EXPORTS_W void FT12D_components(InputArray matrix, InputArray kernel, OutputArray components);
67+
68+
/** @brief Computes elements of F1-transform components.
69+
@param matrix Input array.
70+
@param kernel Kernel used for processing. Function **createKernel** can be used.
71+
@param c00 Elements represent average color.
72+
@param c10 Elements represent average vertical gradient.
73+
@param c01 Elements represent average horizontal gradient.
74+
@param components Output 32-bit float array for the components.
75+
@param mask Mask can be used for unwanted area marking.
76+
77+
The function computes components and its elements using predefined kernel and mask.
78+
79+
@note
80+
F-transform technique of first degreee is described in paper @cite Vlas:FT.
81+
*/
82+
CV_EXPORTS_W void FT12D_polynomial(InputArray matrix, InputArray kernel, OutputArray c00, OutputArray c10, OutputArray c01, OutputArray components, InputArray mask = noArray());
83+
84+
/** @brief Creates vertical matrix for F1-transform computation.
85+
@param radius Radius of the basic function.
86+
@param matrix The vertical matrix.
87+
@param chn Number of channels.
88+
89+
The function creates helper vertical matrix for F1-transfrom processing. It is used for gradient computation.
90+
*/
91+
CV_EXPORTS_W void FT12D_createPolynomMatrixVertical(int radius, OutputArray matrix, const int chn);
92+
93+
/** @brief Creates horizontal matrix for F1-transform computation.
94+
@param radius Radius of the basic function.
95+
@param matrix The horizontal matrix.
96+
@param chn Number of channels.
97+
98+
The function creates helper horizontal matrix for F1-transfrom processing. It is used for gradient computation.
99+
*/
100+
CV_EXPORTS_W void FT12D_createPolynomMatrixHorizontal(int radius, OutputArray matrix, const int chn);
101+
102+
/** @brief Computes F1-transfrom and inverse F1-transfrom at once.
103+
@param matrix Input matrix.
104+
@param kernel Kernel used for processing. Function **createKernel** can be used.
105+
@param output Output 32-bit float array.
106+
@param mask Mask used for unwanted area marking.
107+
108+
This function computes F1-transfrom and inverse F1-transfotm in one step. It is fully sufficient and optimized for **Mat**.
109+
*/
110+
CV_EXPORTS_W void FT12D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray());
111+
112+
/** @brief Computes inverse F1-transfrom.
113+
@param components Input 32-bit float single channel array for the components.
114+
@param kernel Kernel used for processing. The same kernel as for components computation must be used.
115+
@param output Output 32-bit float array.
116+
@param width Width of the output array.
117+
@param height Height of the output array.
118+
119+
@note
120+
F-transform technique of first degreee is described in paper @cite Vlas:FT.
121+
*/
122+
CV_EXPORTS_W void FT12D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height);
123+
124+
//! @}
125+
}
126+
}
127+
128+
#endif // __OPENCV_FUZZY_F1_MATH_H__

modules/fuzzy/src/fuzzy_F0_math.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,20 @@ void ft::FT02D_FL_process_float(InputArray matrix, const int radius, OutputArray
301301

302302
void ft::FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask)
303303
{
304-
CV_Assert(matrix.channels() == kernel.channels() && mask.channels() == 1);
304+
CV_Assert(matrix.channels() == kernel.channels());
305+
306+
Mat inputMask;
307+
308+
if (mask.getMat().empty())
309+
{
310+
inputMask = Mat::ones(matrix.size(), CV_8U);
311+
}
312+
else
313+
{
314+
CV_Assert(mask.channels() == 1);
315+
316+
inputMask = mask.getMat();
317+
}
305318

306319
int radiusX = (kernel.cols() - 1) / 2;
307320
int radiusY = (kernel.rows() - 1) / 2;
@@ -312,7 +325,7 @@ void ft::FT02D_components(InputArray matrix, InputArray kernel, OutputArray comp
312325
Mat maskPadded;
313326

314327
copyMakeBorder(matrix, matrixPadded, radiusY, kernel.rows(), radiusX, kernel.cols(), BORDER_CONSTANT, Scalar(0));
315-
copyMakeBorder(mask, maskPadded, radiusY, kernel.rows(), radiusX, kernel.cols(), BORDER_CONSTANT, Scalar(0));
328+
copyMakeBorder(inputMask, maskPadded, radiusY, kernel.rows(), radiusX, kernel.cols(), BORDER_CONSTANT, Scalar(0));
316329

317330
components.create(Bn, An, CV_MAKETYPE(CV_32F, matrix.channels()));
318331

@@ -343,13 +356,6 @@ void ft::FT02D_components(InputArray matrix, InputArray kernel, OutputArray comp
343356
}
344357
}
345358

346-
void ft::FT02D_components(InputArray matrix, InputArray kernel, OutputArray components)
347-
{
348-
Mat mask = Mat::ones(matrix.size(), CV_8U);
349-
350-
ft::FT02D_components(matrix, kernel, components, mask);
351-
}
352-
353359
void ft::FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height)
354360
{
355361
CV_Assert(components.channels() == 1 && kernel.channels() == 1);
@@ -386,16 +392,22 @@ void ft::FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray o
386392
outputZeroes(Rect(radiusX, radiusY, width, height)).copyTo(output);
387393
}
388394

389-
void ft::FT02D_process(InputArray matrix, InputArray kernel, OutputArray output)
395+
void ft::FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask)
390396
{
391-
Mat mask = Mat::ones(matrix.size(), CV_8U);
397+
CV_Assert(matrix.channels() == kernel.channels());
392398

393-
ft::FT02D_process(matrix, kernel, output, mask);
394-
}
399+
Mat inputMask;
395400

396-
void ft::FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask)
397-
{
398-
CV_Assert(matrix.channels() == kernel.channels() && mask.channels() == 1);
401+
if (mask.getMat().empty())
402+
{
403+
inputMask = Mat::ones(matrix.size(), CV_8U);
404+
}
405+
else
406+
{
407+
CV_Assert(mask.channels() == 1);
408+
409+
inputMask = mask.getMat();
410+
}
399411

400412
int radiusX = (kernel.cols() - 1) / 2;
401413
int radiusY = (kernel.rows() - 1) / 2;
@@ -412,7 +424,7 @@ void ft::FT02D_process(InputArray matrix, InputArray kernel, OutputArray output,
412424
Mat outputZeroes(outputHeightPadded, outputWidthPadded, output.type(), Scalar(0));
413425

414426
copyMakeBorder(matrix, matrixPadded, radiusY, kernel.rows(), radiusX, kernel.cols(), BORDER_CONSTANT, Scalar(0));
415-
copyMakeBorder(mask, maskPadded, radiusY, kernel.rows(), radiusX, kernel.cols(), BORDER_CONSTANT, Scalar(0));
427+
copyMakeBorder(inputMask, maskPadded, radiusY, kernel.rows(), radiusX, kernel.cols(), BORDER_CONSTANT, Scalar(0));
416428

417429
for (int i = 0; i < An; i++)
418430
{

0 commit comments

Comments
 (0)