From: Ievgen Khvedchenia Date: Thu, 1 May 2014 15:27:24 +0000 (+0300) Subject: Prepare to merge KAZE and AKAZE nldiffusion_functions source files (work in progress). X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~400^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2df7242646e6da7ad86f56eb2f81d239526f461e;p=profile%2Fivi%2Fopencv.git Prepare to merge KAZE and AKAZE nldiffusion_functions source files (work in progress). --- diff --git a/modules/features2d/src/akaze/AKAZEFeatures.cpp b/modules/features2d/src/akaze/AKAZEFeatures.cpp index 4f33508..dd7876d 100644 --- a/modules/features2d/src/akaze/AKAZEFeatures.cpp +++ b/modules/features2d/src/akaze/AKAZEFeatures.cpp @@ -7,7 +7,7 @@ */ #include "AKAZEFeatures.h" -#include "fed.h" +#include "../kaze/fed.h" #include "nldiffusion_functions.h" using namespace std; diff --git a/modules/features2d/src/akaze/fed.h b/modules/features2d/src/akaze/fed.h deleted file mode 100644 index 4ac82f6..0000000 --- a/modules/features2d/src/akaze/fed.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef FED_H -#define FED_H - -//****************************************************************************** -//****************************************************************************** - -// Includes -#include -#include - -//************************************************************************************* -//************************************************************************************* - -// Declaration of functions -int fed_tau_by_process_time(const float& T, const int& M, const float& tau_max, - const bool& reordering, std::vector& tau); -int fed_tau_by_cycle_time(const float& t, const float& tau_max, - const bool& reordering, std::vector &tau) ; -int fed_tau_internal(const int& n, const float& scale, const float& tau_max, - const bool& reordering, std::vector &tau); -bool fed_is_prime_internal(const int& number); - -//************************************************************************************* -//************************************************************************************* - -#endif // FED_H diff --git a/modules/features2d/src/akaze/nldiffusion_functions.cpp b/modules/features2d/src/akaze/nldiffusion_functions.cpp index e0e2990..f64e504 100644 --- a/modules/features2d/src/akaze/nldiffusion_functions.cpp +++ b/modules/features2d/src/akaze/nldiffusion_functions.cpp @@ -235,7 +235,6 @@ namespace cv { * @param scale Scale factor for the derivative size */ void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, int xorder, int yorder, int scale) { - Mat kx, ky; compute_derivative_kernels(kx, ky, xorder, yorder, scale); sepFilter2D(src, dst, CV_32F, kx, ky); @@ -243,6 +242,58 @@ namespace cv { /* ************************************************************************* */ /** + * @brief Compute Scharr derivative kernels for sizes different than 3 + * @param kx_ The derivative kernel in x-direction + * @param ky_ The derivative kernel in y-direction + * @param dx The derivative order in x-direction + * @param dy The derivative order in y-direction + * @param scale The kernel size + */ + void compute_derivative_kernels(cv::OutputArray kx_, cv::OutputArray ky_, int dx, int dy, int scale) { + + const int ksize = 3 + 2 * (scale - 1); + + // The usual Scharr kernel + if (scale == 1) { + getDerivKernels(kx_, ky_, dx, dy, 0, true, CV_32F); + return; + } + + kx_.create(ksize, 1, CV_32F, -1, true); + ky_.create(ksize, 1, CV_32F, -1, true); + Mat kx = kx_.getMat(); + Mat ky = ky_.getMat(); + + float w = 10.0f / 3.0f; + float norm = 1.0f / (2.0f*scale*(w + 2.0f)); + + for (int k = 0; k < 2; k++) { + Mat* kernel = k == 0 ? &kx : &ky; + int order = k == 0 ? dx : dy; + float kerI[1000]; + + for (int t = 0; t < ksize; t++) { + kerI[t] = 0; + } + + if (order == 0) { + kerI[0] = norm; + kerI[ksize / 2] = w*norm; + kerI[ksize - 1] = norm; + } + else if (order == 1) { + kerI[0] = -1; + kerI[ksize / 2] = 0; + kerI[ksize - 1] = 1; + } + + Mat temp(kernel->rows, kernel->cols, CV_32F, &kerI[0]); + temp.copyTo(*kernel); + } + } + + /* ************************************************************************* */ + /** * @brief This function performs a scalar non-linear diffusion step * @param Ld2 Output image in the evolution * @param c Conductivity image @@ -302,27 +353,6 @@ namespace cv { /* ************************************************************************* */ /** - * @brief This function downsamples the input image with the kernel [1/4,1/2,1/4] - * @param img Input image to be downsampled - * @param dst Output image with half of the resolution of the input image - */ - void downsample_image(const cv::Mat& src, cv::Mat& dst) { - - int i1 = 0, j1 = 0, i2 = 0, j2 = 0; - - for (i1 = 1; i1 < src.rows; i1 += 2) { - j2 = 0; - for (j1 = 1; j1 < src.cols; j1 += 2) { - *(dst.ptr(i2)+j2) = 0.5f*(*(src.ptr(i1)+j1)) + 0.25f*(*(src.ptr(i1)+j1 - 1) + *(src.ptr(i1)+j1 + 1)); - j2++; - } - - i2++; - } - } - - /* ************************************************************************* */ - /** * @brief This function downsamples the input image using OpenCV resize * @param img Input image to be downsampled * @param dst Output image with half of the resolution of the input image @@ -335,57 +365,7 @@ namespace cv { resize(src, dst, dst.size(), 0, 0, cv::INTER_AREA); } - /* ************************************************************************* */ - /** - * @brief Compute Scharr derivative kernels for sizes different than 3 - * @param kx_ The derivative kernel in x-direction - * @param ky_ The derivative kernel in y-direction - * @param dx The derivative order in x-direction - * @param dy The derivative order in y-direction - * @param scale The kernel size - */ - void compute_derivative_kernels(cv::OutputArray kx_, cv::OutputArray ky_, int dx, int dy, int scale) { - - const int ksize = 3 + 2 * (scale - 1); - - // The usual Scharr kernel - if (scale == 1) { - getDerivKernels(kx_, ky_, dx, dy, 0, true, CV_32F); - return; - } - kx_.create(ksize, 1, CV_32F, -1, true); - ky_.create(ksize, 1, CV_32F, -1, true); - Mat kx = kx_.getMat(); - Mat ky = ky_.getMat(); - - float w = 10.0f / 3.0f; - float norm = 1.0f / (2.0f*scale*(w + 2.0f)); - - for (int k = 0; k < 2; k++) { - Mat* kernel = k == 0 ? &kx : &ky; - int order = k == 0 ? dx : dy; - float kerI[1000]; - - for (int t = 0; t < ksize; t++) { - kerI[t] = 0; - } - - if (order == 0) { - kerI[0] = norm; - kerI[ksize / 2] = w*norm; - kerI[ksize - 1] = norm; - } - else if (order == 1) { - kerI[0] = -1; - kerI[ksize / 2] = 0; - kerI[ksize - 1] = 1; - } - - Mat temp(kernel->rows, kernel->cols, CV_32F, &kerI[0]); - temp.copyTo(*kernel); - } - } } } } \ No newline at end of file diff --git a/modules/features2d/src/akaze/nldiffusion_functions.h b/modules/features2d/src/akaze/nldiffusion_functions.h index 0fab6c5..b6dd2e8 100644 --- a/modules/features2d/src/akaze/nldiffusion_functions.h +++ b/modules/features2d/src/akaze/nldiffusion_functions.h @@ -28,7 +28,6 @@ namespace cv { float compute_k_percentile(const cv::Mat& img, float perc, float gscale, int nbins, int ksize_x, int ksize_y); void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, int xorder, int, int scale); void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float& stepsize); - void downsample_image(const cv::Mat& src, cv::Mat& dst); void halfsample_image(const cv::Mat& src, cv::Mat& dst); void compute_derivative_kernels(cv::OutputArray kx_, cv::OutputArray ky_, int dx, int dy, int scale); bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value, int row, int col, bool same_img); diff --git a/modules/features2d/src/kaze/fed.h b/modules/features2d/src/kaze/fed.h index d9e8c49..c313b81 100644 --- a/modules/features2d/src/kaze/fed.h +++ b/modules/features2d/src/kaze/fed.h @@ -5,11 +5,6 @@ //****************************************************************************** // Includes -#include -#include -#include -#include -#include #include //************************************************************************************* diff --git a/modules/features2d/src/kaze/nldiffusion_functions.cpp b/modules/features2d/src/kaze/nldiffusion_functions.cpp index 23ffaf1..a24a1a5 100644 --- a/modules/features2d/src/kaze/nldiffusion_functions.cpp +++ b/modules/features2d/src/kaze/nldiffusion_functions.cpp @@ -28,14 +28,14 @@ // Namespaces using namespace std; using namespace cv; -using namespace cv::details::kaze; -//************************************************************************************* -//************************************************************************************* +/* ************************************************************************* */ namespace cv { namespace details { namespace kaze { + + /* ************************************************************************* */ /** * @brief This function smoothes an image with a Gaussian kernel * @param src Input image @@ -44,8 +44,7 @@ namespace cv { * @param ksize_y Kernel size in Y-direction (vertical) * @param sigma Kernel standard deviation */ - void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, - int ksize_x, int ksize_y, float sigma) { + void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, int ksize_x, int ksize_y, float sigma) { int ksize_x_ = 0, ksize_y_ = 0; @@ -68,9 +67,7 @@ namespace cv { GaussianBlur(src, dst, Size(ksize_x_, ksize_y_), sigma, sigma, cv::BORDER_REPLICATE); } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function computes the Perona and Malik conductivity coefficient g1 * g1 = exp(-|dL|^2/k^2) @@ -83,9 +80,7 @@ namespace cv { cv::exp(-(Lx.mul(Lx) + Ly.mul(Ly)) / (k*k), dst); } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function computes the Perona and Malik conductivity coefficient g2 * g2 = 1 / (1 + dL^2 / k^2) @@ -98,9 +93,7 @@ namespace cv { dst = 1. / (1. + (Lx.mul(Lx) + Ly.mul(Ly)) / (k*k)); } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function computes Weickert conductivity coefficient g3 * @param Lx First order image derivative in X-direction (horizontal) @@ -118,9 +111,7 @@ namespace cv { dst = 1.0f - dst; } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function computes a good empirical value for the k contrast factor * given an input image, the percentile (0-1), the gradient scale and the number of @@ -208,9 +199,7 @@ namespace cv { return kperc; } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function computes Scharr image derivatives * @param src Input image @@ -219,16 +208,13 @@ namespace cv { * @param yorder Derivative order in Y-direction (vertical) * @param scale Scale factor or derivative size */ - void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, - int xorder, int yorder, int scale) { + void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, int xorder, int yorder, int scale) { Mat kx, ky; compute_derivative_kernels(kx, ky, xorder, yorder, scale); sepFilter2D(src, dst, CV_32F, kx, ky); } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief Compute derivative kernels for sizes different than 3 * @param _kx Horizontal kernel values @@ -237,8 +223,7 @@ namespace cv { * @param dy Derivative order in Y-direction (vertical) * @param scale_ Scale factor or derivative size */ - void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky, - int dx, int dy, int scale) { + void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky, int dx, int dy, int scale) { int ksize = 3 + 2 * (scale - 1); @@ -273,9 +258,7 @@ namespace cv { } } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function performs a scalar non-linear diffusion step * @param Ld2 Output image in the evolution @@ -336,9 +319,7 @@ namespace cv { Ld = Ld + Lstep; } - //************************************************************************************* - //************************************************************************************* - + /* ************************************************************************* */ /** * @brief This function checks if a given pixel is a maximum in a local neighbourhood * @param img Input image where we will perform the maximum search @@ -349,8 +330,7 @@ namespace cv { * @param same_img Flag to indicate if the image value at (x,y) is in the input image * @return 1->is maximum, 0->otherwise */ - bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value, - int row, int col, bool same_img) { + bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value, int row, int col, bool same_img) { bool response = true;