Prepare to merge KAZE and AKAZE nldiffusion_functions source files (work in progress).
This commit is contained in:
parent
30f73623ce
commit
2df7242646
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "AKAZEFeatures.h"
|
#include "AKAZEFeatures.h"
|
||||||
#include "fed.h"
|
#include "../kaze/fed.h"
|
||||||
#include "nldiffusion_functions.h"
|
#include "nldiffusion_functions.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef FED_H
|
|
||||||
#define FED_H
|
|
||||||
|
|
||||||
//******************************************************************************
|
|
||||||
//******************************************************************************
|
|
||||||
|
|
||||||
// Includes
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
//*************************************************************************************
|
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
// Declaration of functions
|
|
||||||
int fed_tau_by_process_time(const float& T, const int& M, const float& tau_max,
|
|
||||||
const bool& reordering, std::vector<float>& tau);
|
|
||||||
int fed_tau_by_cycle_time(const float& t, const float& tau_max,
|
|
||||||
const bool& reordering, std::vector<float> &tau) ;
|
|
||||||
int fed_tau_internal(const int& n, const float& scale, const float& tau_max,
|
|
||||||
const bool& reordering, std::vector<float> &tau);
|
|
||||||
bool fed_is_prime_internal(const int& number);
|
|
||||||
|
|
||||||
//*************************************************************************************
|
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
#endif // FED_H
|
|
@ -235,12 +235,63 @@ namespace cv {
|
|||||||
* @param scale Scale factor for the derivative size
|
* @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) {
|
void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, int xorder, int yorder, int scale) {
|
||||||
|
|
||||||
Mat kx, ky;
|
Mat kx, ky;
|
||||||
compute_derivative_kernels(kx, ky, xorder, yorder, scale);
|
compute_derivative_kernels(kx, ky, xorder, yorder, scale);
|
||||||
sepFilter2D(src, dst, CV_32F, kx, ky);
|
sepFilter2D(src, dst, CV_32F, kx, ky);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
/**
|
||||||
|
* @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
|
* @brief This function performs a scalar non-linear diffusion step
|
||||||
@ -300,27 +351,6 @@ namespace cv {
|
|||||||
Ld = Ld + Lstep;
|
Ld = Ld + Lstep;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
|
||||||
/**
|
|
||||||
* @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<float>(i2)+j2) = 0.5f*(*(src.ptr<float>(i1)+j1)) + 0.25f*(*(src.ptr<float>(i1)+j1 - 1) + *(src.ptr<float>(i1)+j1 + 1));
|
|
||||||
j2++;
|
|
||||||
}
|
|
||||||
|
|
||||||
i2++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
/**
|
/**
|
||||||
* @brief This function downsamples the input image using OpenCV resize
|
* @brief This function downsamples the input image using OpenCV resize
|
||||||
@ -335,57 +365,7 @@ namespace cv {
|
|||||||
resize(src, dst, dst.size(), 0, 0, cv::INTER_AREA);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
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 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 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 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);
|
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);
|
bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value, int row, int col, bool same_img);
|
||||||
|
@ -5,11 +5,6 @@
|
|||||||
//******************************************************************************
|
//******************************************************************************
|
||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
#include <iostream>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <math.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
//*************************************************************************************
|
//*************************************************************************************
|
||||||
|
@ -28,14 +28,14 @@
|
|||||||
// Namespaces
|
// Namespaces
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace cv::details::kaze;
|
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
namespace cv {
|
namespace cv {
|
||||||
namespace details {
|
namespace details {
|
||||||
namespace kaze {
|
namespace kaze {
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
/**
|
/**
|
||||||
* @brief This function smoothes an image with a Gaussian kernel
|
* @brief This function smoothes an image with a Gaussian kernel
|
||||||
* @param src Input image
|
* @param src Input image
|
||||||
@ -44,8 +44,7 @@ namespace cv {
|
|||||||
* @param ksize_y Kernel size in Y-direction (vertical)
|
* @param ksize_y Kernel size in Y-direction (vertical)
|
||||||
* @param sigma Kernel standard deviation
|
* @param sigma Kernel standard deviation
|
||||||
*/
|
*/
|
||||||
void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst,
|
void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, int ksize_x, int ksize_y, float sigma) {
|
||||||
int ksize_x, int ksize_y, float sigma) {
|
|
||||||
|
|
||||||
int ksize_x_ = 0, ksize_y_ = 0;
|
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);
|
GaussianBlur(src, dst, Size(ksize_x_, ksize_y_), sigma, sigma, cv::BORDER_REPLICATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes the Perona and Malik conductivity coefficient g1
|
* @brief This function computes the Perona and Malik conductivity coefficient g1
|
||||||
* g1 = exp(-|dL|^2/k^2)
|
* g1 = exp(-|dL|^2/k^2)
|
||||||
@ -83,9 +80,7 @@ namespace cv {
|
|||||||
cv::exp(-(Lx.mul(Lx) + Ly.mul(Ly)) / (k*k), dst);
|
cv::exp(-(Lx.mul(Lx) + Ly.mul(Ly)) / (k*k), dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes the Perona and Malik conductivity coefficient g2
|
* @brief This function computes the Perona and Malik conductivity coefficient g2
|
||||||
* g2 = 1 / (1 + dL^2 / k^2)
|
* g2 = 1 / (1 + dL^2 / k^2)
|
||||||
@ -98,9 +93,7 @@ namespace cv {
|
|||||||
dst = 1. / (1. + (Lx.mul(Lx) + Ly.mul(Ly)) / (k*k));
|
dst = 1. / (1. + (Lx.mul(Lx) + Ly.mul(Ly)) / (k*k));
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes Weickert conductivity coefficient g3
|
* @brief This function computes Weickert conductivity coefficient g3
|
||||||
* @param Lx First order image derivative in X-direction (horizontal)
|
* @param Lx First order image derivative in X-direction (horizontal)
|
||||||
@ -118,9 +111,7 @@ namespace cv {
|
|||||||
dst = 1.0f - dst;
|
dst = 1.0f - dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes a good empirical value for the k contrast factor
|
* @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
|
* given an input image, the percentile (0-1), the gradient scale and the number of
|
||||||
@ -208,9 +199,7 @@ namespace cv {
|
|||||||
return kperc;
|
return kperc;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes Scharr image derivatives
|
* @brief This function computes Scharr image derivatives
|
||||||
* @param src Input image
|
* @param src Input image
|
||||||
@ -219,16 +208,13 @@ namespace cv {
|
|||||||
* @param yorder Derivative order in Y-direction (vertical)
|
* @param yorder Derivative order in Y-direction (vertical)
|
||||||
* @param scale Scale factor or derivative size
|
* @param scale Scale factor or derivative size
|
||||||
*/
|
*/
|
||||||
void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst,
|
void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, int xorder, int yorder, int scale) {
|
||||||
int xorder, int yorder, int scale) {
|
|
||||||
Mat kx, ky;
|
Mat kx, ky;
|
||||||
compute_derivative_kernels(kx, ky, xorder, yorder, scale);
|
compute_derivative_kernels(kx, ky, xorder, yorder, scale);
|
||||||
sepFilter2D(src, dst, CV_32F, kx, ky);
|
sepFilter2D(src, dst, CV_32F, kx, ky);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compute derivative kernels for sizes different than 3
|
* @brief Compute derivative kernels for sizes different than 3
|
||||||
* @param _kx Horizontal kernel values
|
* @param _kx Horizontal kernel values
|
||||||
@ -237,8 +223,7 @@ namespace cv {
|
|||||||
* @param dy Derivative order in Y-direction (vertical)
|
* @param dy Derivative order in Y-direction (vertical)
|
||||||
* @param scale_ Scale factor or derivative size
|
* @param scale_ Scale factor or derivative size
|
||||||
*/
|
*/
|
||||||
void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky,
|
void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky, int dx, int dy, int scale) {
|
||||||
int dx, int dy, int scale) {
|
|
||||||
|
|
||||||
int ksize = 3 + 2 * (scale - 1);
|
int ksize = 3 + 2 * (scale - 1);
|
||||||
|
|
||||||
@ -273,9 +258,7 @@ namespace cv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function performs a scalar non-linear diffusion step
|
* @brief This function performs a scalar non-linear diffusion step
|
||||||
* @param Ld2 Output image in the evolution
|
* @param Ld2 Output image in the evolution
|
||||||
@ -336,9 +319,7 @@ namespace cv {
|
|||||||
Ld = Ld + Lstep;
|
Ld = Ld + Lstep;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function checks if a given pixel is a maximum in a local neighbourhood
|
* @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
|
* @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
|
* @param same_img Flag to indicate if the image value at (x,y) is in the input image
|
||||||
* @return 1->is maximum, 0->otherwise
|
* @return 1->is maximum, 0->otherwise
|
||||||
*/
|
*/
|
||||||
bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value,
|
bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value, int row, int col, bool same_img) {
|
||||||
int row, int col, bool same_img) {
|
|
||||||
|
|
||||||
bool response = true;
|
bool response = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user