@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.
Namespace for all functions is `ft`. The module brings implementation of the last image processing algorithms based on fuzzy mathematics. Method are named based on the pattern `FT`_degree_dimension`_`method.
@{
@defgroup f0_math Math with F0-transform support
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.
Fuzzy transform (\f$F^0\f$-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.
@defgroup f1_math Math with F1-transform support
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.
Fuzzy transform (\f$F^1\f$-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.
/** @brief Computes F0-transfrom and inverse F0-transfrom at once and return state.
/** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once and return state.
@param matrix Input matrix.
@param kernel Kernel used for processing. Function **createKernel** can be used.
@param kernel Kernel used for processing. Function `ft::createKernel` can be used.
@param output Output 32-bit float 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.
@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.
This function computes iteration of F-transfrom and inverse F-transfotm and handle image and mask change. The function is used in `ft::inpaint` function.
/** @brief Sligtly less accurate version of F0-transfrom computation optimized for higher speed. The methods counts with linear basic function.
/** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function.
@param matrix Input 3 channels matrix.
@param radius Radius of the **LINEAR** basic function.
@param radius Radius of the `ft::LINEAR` basic function.
@param output Output array.
This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~10 times faster than **FT02D_process** method.
This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~10 times faster than `ft::FT02D_process` method.
/** @brief Sligtly less accurate version of F0-transfrom computation optimized for higher speed. The methods counts with linear basic function.
/** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function.
@param matrix Input 3 channels matrix.
@param radius Radius of the **LINEAR** basic function.
@param radius Radius of the `ft::LINEAR` basic function.
@param output Output array.
This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~9 times faster then **FT02D_process** method and more accurate than **FT02D_FL_process** method.
This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~9 times faster then `ft::FT02D_process` method and more accurate than `ft::FT02D_FL_process` method.
Filtering using F-transform {#tutorial_fuzzy_filtering}
=============
Goal
====
This tutorial demonstrates to you how to use F-transform for image filtering. You will see:
- basic theory behind,
- illustration of different settings.
Fuzzy transform application
====
As I shown in previous tutorial, F-transform is a tool of fuzzy mathematics highly usable in image processing. Let me rewrite the formula using kernel \f$g\f$ introduced before as well:
Inpainting using F-transform {#tutorial_fuzzy_inpainting}
=============
Goal
====
In this tutorial, you will learn how image inpainting using F-transform works. It consists in:
- basic theory behind,
- three different algorithms.
Introduction
====
The goal of this tutorial is to show that the inverse F-transform can be used for image reconstruction. By the image reconstruction, we mean a reconstruction of a corrupted image where corruption is everything that the original image does not include. It can be noise, text, scratch, etc. Proposal is to solve the problem of reconstruction with the help of an approximation technique. This means that we will be looking for an approximating image which is close to the given one and at the same time, does not contain what we recognize as the corruption. This task is called _image inpainting_.
Fuzzy transform application
====
As I shown in previous tutorial, F-transform is a tool of fuzzy mathematics highly usable in image processing. Let me rewrite the formula using kernel \f$g\f$ introduced before as well:
where \f$\iota_{kl} \subset I\f$ centered to pixel \f$(k \cdot h,l \cdot h)\f$ and \f$g\f$ is a kernel. For purpose of image processing, a binary mask \f$S\f$ is used such as
\f[
g^s_{kl} = g \circ s_{kl}
\f]
where \f$s_{k,l} \subset S\f$. Subarea \f$s\f$ of mask \f$S\f$ corresponds with subarea \f$\iota\f$ of image \f$I\f$. Operator \f$\circ\f$ is element-wise matrix multiplication (Hadamard product). Formula is updated to
The sample below demonstrates the usage of image inpainting. Three artificial images are created using the same input and three different type of corruption. In the real life usage, the input image will be already presented but here we created it by ourselves.
First of all, we must load our image and three masks used for artificial damage creation.
@code{.cpp}
// Input image
Mat I = imread("input.png");
// Various masks
Mat mask1 = imread("mask1.png", IMREAD_GRAYSCALE);
Mat mask2 = imread("mask2.png", IMREAD_GRAYSCALE);
Mat mask3 = imread("mask3.png", IMREAD_GRAYSCALE);
@endcode
> See that mask must be loaded as `IMREAD_GRAYSCALE`.
In the next step, the masks are used for damaging our input image.
@code{.cpp}
// Apply the damage
Mat input1, input2, input3;
I.copyTo(input1, mask1);
I.copyTo(input2, mask2);
I.copyTo(input3, mask3);
@endcode
Using the masks, we applied three different kind of corruption on the same input image. Here is the result.
![input1, input2 and input3](images/fuzzy_inp_input.jpg)
> Do not forget that in real life usage, images `input1`, `input2` and `input3` are created naturaly and used as the input directly.
Declaration of output images follows. In the following lines, the method of inpainting is applied. Let me explain three different algorithms one by one.
The `ONE_STEP` algorithm simply compute direct F-transform ignoring damaged parts using kernel with radius `2` (as specified in the method calling). Inverse F-transform fill up the missing area using values from the components nearby. It is up to you to choose radius which is big enough.
`MULTI_STEP` algorithm works in the same way but defined radius (`2` in this case) is automatically increased if it is found insufficient. If you want to fill up the hole and you are not sure how big radius you need, you can choose `MULTI_STEP` and let the computer decide. The lowest possible will be found.
Best choice in majority of cases is `ITERATIVE`. This way of processing use small radius of basic functions for small kind of damage and higher ones for bigger holes.
In this tutorial, the basic concept of fuzzy transform is presented. You will learn:
- mathematic background,
- how to apply concept of fuzziness to image processing.
The presented explanation demands knowledge of basic math. All related papers are cited and mostly accessible on https://www.researchgate.net/.
Introduction
====
In the last years, the theory of F-transforms has been intensively developed in many directions. In image processing, it has had successful applications in image compression and reduction, image fusion, edge detection and image reconstruction @cite Perf:FT @cite MSLP:cod-decod @cite Fusion:AFS12 @cite IPMU2012 @cite Perf:rec @cite vlavsanek2015patch. The F-transform is a technique that places a continuous/discrete function in correspondence with a finite vector of its F-transform components. In image processing, where images are identified by intensity functions of two arguments, the F-transform of the latter is given by a matrix of components.
Let me introduce F-transform of a 2D grayscale image \f$I\f$ that is considered as a function \f$I:[0,M]\times [0,N]\to [0,255]\f$ where \f$[0,M]=\{0,1,2,\ldots,M\}; [0,N]=\{0,1,2,\ldots,N\}\f$. It is assumed that the image is defined at points (pixels) that belong to the set \f$P\f$, where \f$P=\{(x,y)\mid x=0,1,\ldots, M;y=0,1,\ldots, N\}\f$.
Let \f$A_0, \dots ,A_m\f$ and \f$B_0, \dots ,B_n\f$ be basic functions, \f$A_0, \dots ,A_m : [0,M]\to [0, 1]\f$ be fuzzy partition of \f$[0,M]\f$ and \f$B_0, \dots ,B_n :[0,N]\to [0, 1]\f$ be fuzzy partition of \f$[0,N]\f$. Assume that the set of pixels \f$P\f$ is _sufficiently dense with respect to the chosen partitions_. This means that for all \f$k\in{0,\dots, m}(\exists x\in [0,M]) \ A_k(x)>0\f$, and for all \f$l\in{0,\dots, n}(\exists y\in [0,N])\ B_l(y)>0\f$.
\f$F^0\f$-transform
====
We say that the \f$m\times n\f$-matrix of real numbers \f$F^0_{mn}[I] = (F^0_{kl})\f$ is called _the (discrete) F-transform_ of \f$I\f$ with respect to \f$\{A_0, \dots,A_m\}\f$ and \f$\{B_0, \dots,B_n\}\f$ if for all \f$k=0,\dots,m,\ l=0,\dots,n\f$:
The coefficients \f$F^0_{kl}\f$ are called _components_ of the \f$F^0\f$-transform.
\f$F^1\f$-transform
====
\f$F^1\f$-transform has been presented in @cite perfilieva2014differentiation. We say that matrix \f$F^1_{mn}[I] = (F^1_{kl}), k=0,\ldots, m, l=0,\ldots, n\f$, is the \f$F^1\f$-transform of \f$I\f$ with respect to \f$\{A_k\times B_l\mid k=0,\ldots, m, l=0,\ldots, n\}\f$, and \f$F^1_{kl}\f$ is the corresponding \f$F^1\f$-transform component.
The \f$F^1\f$-transform components of \f$I\f$ are linear polynomials in the form
The technique of F-transforms uses two steps: _direct and inverse_. The direct step is described in the previous section whereas the inverse is as follows
where \f$O\f$ is the output (reconstructed) image and \f$d\f$ is F-transform degree. In fact, the algorithm computes the F-transform components of the input image \f$I\f$ and spreads the components afterwards to the size of \f$I\f$. For details see @cite Perf:rec. Application to image processing is possible to take from two different views.
From pixel point of view
----
The pixels are processed one by one in a way that appropriate basic functions are found for each of them. It will be exactly four, two in each direction. We need some helper structure in the memory for collecting their values. The values will be used in the nominator of the related fuzzy component. Implementation of this approach uses keyword `FL` as __fast__ processing (because of more optimizations) and __linear basic function__.
![Pixel point of view with marked basic functions related to processed pixel.](images/fuzzy_pixel_view.jpg)
From fuzzy component point of view
----
In this way, image is divided to the regular areas. Each area is processed separately using kernel window. This approach benefits from easy to understand, matrix based processing with straight forward parallelization.
![Fuzzy component point of view with marked basic functions related to processed area.](images/fuzzy_BF_view.jpg)
This approach uses kernel \f$g\f$. Let us show linear case with radius \f$h = 2\f$ as an example.