Merge KAZE and AKAZE features with most recent version
This commit is contained in:
parent
d27ed856f2
commit
6d500cc6f7
File diff suppressed because it is too large
Load Diff
@ -6,148 +6,84 @@
|
|||||||
* @author Pablo F. Alcantarilla, Jesus Nuevo
|
* @author Pablo F. Alcantarilla, Jesus Nuevo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _AKAZE_H_
|
#pragma once
|
||||||
#define _AKAZE_H_
|
|
||||||
|
|
||||||
//*************************************************************************************
|
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
// Includes
|
// Includes
|
||||||
#include "config.h"
|
#include "precomp.hpp"
|
||||||
#include "fed.h"
|
#include "AKAZEConfig.h"
|
||||||
#include "nldiffusion_functions.h"
|
|
||||||
|
|
||||||
//*************************************************************************************
|
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
// AKAZE Class Declaration
|
// AKAZE Class Declaration
|
||||||
class AKAZEFeatures {
|
class AKAZEFeatures {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Parameters of the AKAZE class
|
AKAZEOptions options_; ///< Configuration options for AKAZE
|
||||||
int omax_; // Maximum octave level
|
std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution
|
||||||
int noctaves_; // Number of octaves
|
|
||||||
int nsublevels_; // Number of sublevels per octave level
|
|
||||||
int img_width_; // Width of the original image
|
|
||||||
int img_height_; // Height of the original image
|
|
||||||
float soffset_; // Base scale offset
|
|
||||||
float factor_size_; // Factor for the multiscale derivatives
|
|
||||||
float sderivatives_; // Standard deviation of the Gaussian for the nonlinear diff. derivatives
|
|
||||||
float kcontrast_; // The contrast parameter for the scalar nonlinear diffusion
|
|
||||||
float dthreshold_; // Feature detector threshold response
|
|
||||||
int diffusivity_; // Diffusivity type, 0->PM G1, 1->PM G2, 2-> Weickert, 3->Charbonnier
|
|
||||||
int descriptor_; // Descriptor mode:
|
|
||||||
// 0-> SURF_UPRIGHT, 1->SURF
|
|
||||||
// 2-> M-SURF_UPRIGHT, 3->M-SURF
|
|
||||||
// 4-> M-LDB_UPRIGHT, 5->M-LDB
|
|
||||||
int descriptor_size_; // Size of the descriptor in bits. Use 0 for the full descriptor
|
|
||||||
int descriptor_pattern_size_; // Size of the pattern. Actual size sampled is 2*pattern_size
|
|
||||||
int descriptor_channels_; // Number of channels to consider in the M-LDB descriptor
|
|
||||||
bool save_scale_space_; // For saving scale space images
|
|
||||||
bool verbosity_; // Verbosity level
|
|
||||||
std::vector<tevolution> evolution_; // Vector of nonlinear diffusion evolution
|
|
||||||
|
|
||||||
// FED parameters
|
/// FED parameters
|
||||||
int ncycles_; // Number of cycles
|
int ncycles_; ///< Number of cycles
|
||||||
bool reordering_; // Flag for reordering time steps
|
bool reordering_; ///< Flag for reordering time steps
|
||||||
std::vector<std::vector<float > > tsteps_; // Vector of FED dynamic time steps
|
std::vector<std::vector<float > > tsteps_; ///< Vector of FED dynamic time steps
|
||||||
std::vector<int> nsteps_; // Vector of number of steps per cycle
|
std::vector<int> nsteps_; ///< Vector of number of steps per cycle
|
||||||
|
|
||||||
// Some matrices for the M-LDB descriptor computation
|
/// Matrices for the M-LDB descriptor computation
|
||||||
cv::Mat descriptorSamples_; // List of positions in the grids to sample LDB bits from.
|
cv::Mat descriptorSamples_; // List of positions in the grids to sample LDB bits from.
|
||||||
cv::Mat descriptorBits_;
|
cv::Mat descriptorBits_;
|
||||||
cv::Mat bitMask_;
|
cv::Mat bitMask_;
|
||||||
|
|
||||||
// Computation times variables in ms
|
/// Computation times variables in ms
|
||||||
double tkcontrast_; // Kcontrast factor computation
|
AKAZETiming timing_;
|
||||||
double tscale_; // Nonlinear Scale space generation
|
|
||||||
double tderivatives_; // Multiscale derivatives
|
|
||||||
double tdetector_; // Feature detector
|
|
||||||
double textrema_; // Scale Space extrema
|
|
||||||
double tsubpixel_; // Subpixel refinement
|
|
||||||
double tdescriptor_; // Feature descriptors
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructor
|
/// Constructor with input arguments
|
||||||
AKAZEFeatures(const AKAZEOptions& options);
|
AKAZEFeatures(const AKAZEOptions& options);
|
||||||
|
|
||||||
// Destructor
|
/// Destructor
|
||||||
~AKAZEFeatures(void);
|
~AKAZEFeatures();
|
||||||
|
|
||||||
// Setters
|
/// Scale Space methods
|
||||||
void Set_Octave_Max(const int& omax) {
|
void Allocate_Memory_Evolution();
|
||||||
omax_ = omax;
|
|
||||||
}
|
|
||||||
void Set_NSublevels(const int& nsublevels) {
|
|
||||||
nsublevels_ = nsublevels;
|
|
||||||
}
|
|
||||||
void Set_Save_Scale_Space_Flag(const bool& save_scale_space) {
|
|
||||||
save_scale_space_ = save_scale_space;
|
|
||||||
}
|
|
||||||
void Set_Image_Width(const int& img_width) {
|
|
||||||
img_width_ = img_width;
|
|
||||||
}
|
|
||||||
void Set_Image_Height(const int& img_height) {
|
|
||||||
img_height_ = img_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
int Get_Image_Width(void) {
|
|
||||||
return img_width_;
|
|
||||||
}
|
|
||||||
int Get_Image_Height(void) {
|
|
||||||
return img_height_;
|
|
||||||
}
|
|
||||||
double Get_Time_KContrast(void) {
|
|
||||||
return tkcontrast_;
|
|
||||||
}
|
|
||||||
double Get_Time_Scale_Space(void) {
|
|
||||||
return tscale_;
|
|
||||||
}
|
|
||||||
double Get_Time_Derivatives(void) {
|
|
||||||
return tderivatives_;
|
|
||||||
}
|
|
||||||
double Get_Time_Detector(void) {
|
|
||||||
return tdetector_;
|
|
||||||
}
|
|
||||||
double Get_Time_Descriptor(void) {
|
|
||||||
return tdescriptor_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scale Space methods
|
|
||||||
void Allocate_Memory_Evolution(void);
|
|
||||||
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
||||||
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
||||||
void Compute_Determinant_Hessian_Response(void);
|
void Compute_Determinant_Hessian_Response(void);
|
||||||
void Compute_Multiscale_Derivatives(void);
|
void Compute_Multiscale_Derivatives(void);
|
||||||
void Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts);
|
void Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts);
|
||||||
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
||||||
void Feature_Suppression_Distance(std::vector<cv::KeyPoint>& kpts, float mdist);
|
void Feature_Suppression_Distance(std::vector<cv::KeyPoint>& kpts, float mdist) const;
|
||||||
|
|
||||||
// Feature description methods
|
// Feature description methods
|
||||||
void Compute_Descriptors(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
void Compute_Descriptors(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
||||||
void Compute_Main_Orientation_SURF(cv::KeyPoint& kpt);
|
void Compute_Main_Orientation(cv::KeyPoint& kpt) const;
|
||||||
|
|
||||||
// SURF Pattern Descriptor
|
// SURF Pattern Descriptor
|
||||||
void Get_SURF_Descriptor_Upright_64(const cv::KeyPoint& kpt, float *desc);
|
void Get_SURF_Descriptor_Upright_64(const cv::KeyPoint& kpt, float* desc) const;
|
||||||
void Get_SURF_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
|
void Get_SURF_Descriptor_64(const cv::KeyPoint& kpt, float* desc) const;
|
||||||
|
|
||||||
// M-SURF Pattern Descriptor
|
// M-SURF Pattern Descriptor
|
||||||
void Get_MSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
|
void Get_MSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float* desc) const;
|
||||||
void Get_MSURF_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
|
void Get_MSURF_Descriptor_64(const cv::KeyPoint& kpt, float* desc) const;
|
||||||
|
|
||||||
// M-LDB Pattern Descriptor
|
// M-LDB Pattern Descriptor
|
||||||
void Get_Upright_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char *desc);
|
void Get_Upright_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char* desc) const;
|
||||||
void Get_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char *desc);
|
void Get_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char* desc) const;
|
||||||
void Get_Upright_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char* desc);
|
void Get_Upright_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char* desc);
|
||||||
void Get_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char* desc);
|
void Get_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char* desc);
|
||||||
|
|
||||||
|
// Methods for saving some results and showing computation times
|
||||||
|
void Save_Scale_Space();
|
||||||
|
void Save_Detector_Responses();
|
||||||
|
void Show_Computation_Times() const;
|
||||||
|
|
||||||
|
/// Return the computation times
|
||||||
|
AKAZETiming Get_Computation_Times() const {
|
||||||
|
return timing_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
// Inline functions
|
// Inline functions
|
||||||
/**
|
/**
|
||||||
* @brief This function sets default parameters for the A-KAZE detector.
|
* @brief This function sets default parameters for the A-KAZE detector.
|
||||||
@ -160,10 +96,5 @@ void generateDescriptorSubsample(cv::Mat& sampleList, cv::Mat& comparisons,
|
|||||||
int nbits, int pattern_size, int nchannels);
|
int nbits, int pattern_size, int nchannels);
|
||||||
float get_angle(float x, float y);
|
float get_angle(float x, float y);
|
||||||
float gaussian(float x, float y, float sigma);
|
float gaussian(float x, float y, float sigma);
|
||||||
void check_descriptor_limits(int& x, int& y, const int width, const int height);
|
void check_descriptor_limits(int& x, int& y, int width, int height);
|
||||||
int fRound(float flt);
|
int fRound(float flt);
|
||||||
|
|
||||||
//*************************************************************************************
|
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -9,13 +9,7 @@
|
|||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// OpenCV
|
// OpenCV
|
||||||
#include <opencv2/opencv.hpp>
|
#include "precomp.hpp"
|
||||||
#include <opencv2/features2d/features2d.hpp>
|
|
||||||
|
|
||||||
// OpenMP
|
|
||||||
#ifdef _OPENMP
|
|
||||||
# include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// System Includes
|
// System Includes
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -24,9 +24,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
@ -59,9 +57,7 @@ void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, const size_t& ksi
|
|||||||
GaussianBlur(src, dst, Size(ksize_x_, ksize_y_), sigma, sigma, BORDER_REPLICATE);
|
GaussianBlur(src, dst, Size(ksize_x_, ksize_y_), sigma, sigma, BORDER_REPLICATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes image derivatives with Scharr kernel
|
* @brief This function computes image derivatives with Scharr kernel
|
||||||
* @param src Input image
|
* @param src Input image
|
||||||
@ -78,9 +74,7 @@ void image_derivatives_scharr(const cv::Mat& src, cv::Mat& dst,
|
|||||||
Scharr(src, dst, CV_32F, xorder, yorder, 1.0, 0, BORDER_DEFAULT);
|
Scharr(src, dst, CV_32F, xorder, yorder, 1.0, 0, BORDER_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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)
|
||||||
@ -93,9 +87,7 @@ void pm_g1(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k) {
|
|||||||
exp(-(Lx.mul(Lx) + Ly.mul(Ly)) / (k*k), dst);
|
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)
|
||||||
@ -108,9 +100,7 @@ void pm_g2(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k) {
|
|||||||
dst = 1.0 / (1.0 + (Lx.mul(Lx) + Ly.mul(Ly)) / (k*k));
|
dst = 1.0 / (1.0 + (Lx.mul(Lx) + Ly.mul(Ly)) / (k*k));
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes Weickert conductivity coefficient gw
|
* @brief This function computes Weickert conductivity coefficient gw
|
||||||
* @param Lx First order image derivative in X-direction (horizontal)
|
* @param Lx First order image derivative in X-direction (horizontal)
|
||||||
@ -128,9 +118,7 @@ void weickert_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, co
|
|||||||
dst = 1.0 - dst;
|
dst = 1.0 - dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function computes Charbonnier conductivity coefficient gc
|
* @brief This function computes Charbonnier conductivity coefficient gc
|
||||||
* gc = 1 / sqrt(1 + dL^2 / k^2)
|
* gc = 1 / sqrt(1 + dL^2 / k^2)
|
||||||
@ -148,9 +136,7 @@ void charbonnier_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst,
|
|||||||
dst = 1.0 / den;
|
dst = 1.0 / den;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
@ -163,8 +149,8 @@ void charbonnier_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst,
|
|||||||
* @param ksize_y Kernel size in Y-direction (vertical) for the Gaussian smoothing kernel
|
* @param ksize_y Kernel size in Y-direction (vertical) for the Gaussian smoothing kernel
|
||||||
* @return k contrast factor
|
* @return k contrast factor
|
||||||
*/
|
*/
|
||||||
float compute_k_percentile(const cv::Mat& img, const float& perc, const float& gscale,
|
float compute_k_percentile(const cv::Mat& img, float perc, float gscale,
|
||||||
const size_t& nbins, const size_t& ksize_x, const size_t& ksize_y) {
|
size_t nbins, size_t ksize_x, size_t ksize_y) {
|
||||||
|
|
||||||
size_t nbin = 0, nelements = 0, nthreshold = 0, k = 0;
|
size_t nbin = 0, nelements = 0, nthreshold = 0, k = 0;
|
||||||
float kperc = 0.0, modg = 0.0, lx = 0.0, ly = 0.0;
|
float kperc = 0.0, modg = 0.0, lx = 0.0, ly = 0.0;
|
||||||
@ -175,14 +161,13 @@ float compute_k_percentile(const cv::Mat& img, const float& perc, const float& g
|
|||||||
float *hist = new float[nbins];
|
float *hist = new float[nbins];
|
||||||
|
|
||||||
// Create the matrices
|
// Create the matrices
|
||||||
Mat gaussian = Mat::zeros(img.rows,img.cols,CV_32F);
|
cv::Mat gaussian = cv::Mat::zeros(img.rows, img.cols, CV_32F);
|
||||||
Mat Lx = Mat::zeros(img.rows,img.cols,CV_32F);
|
cv::Mat Lx = cv::Mat::zeros(img.rows, img.cols, CV_32F);
|
||||||
Mat Ly = Mat::zeros(img.rows,img.cols,CV_32F);
|
cv::Mat Ly = cv::Mat::zeros(img.rows, img.cols, CV_32F);
|
||||||
|
|
||||||
// Set the histogram to zero, just in case
|
// Set the histogram to zero
|
||||||
for (size_t i = 0; i < nbins; i++) {
|
for (size_t i = 0; i < nbins; i++)
|
||||||
hist[i] = 0.0;
|
hist[i] = 0.0;
|
||||||
}
|
|
||||||
|
|
||||||
// Perform the Gaussian convolution
|
// Perform the Gaussian convolution
|
||||||
gaussian_2D_convolution(img, gaussian, ksize_x, ksize_y, gscale);
|
gaussian_2D_convolution(img, gaussian, ksize_x, ksize_y, gscale);
|
||||||
@ -244,9 +229,7 @@ float compute_k_percentile(const cv::Mat& img, const float& perc, const float& g
|
|||||||
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
|
||||||
@ -263,9 +246,7 @@ void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, const size_t&
|
|||||||
sepFilter2D(src, dst, CV_32F, kx, ky);
|
sepFilter2D(src, dst, CV_32F, kx, ky);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
@ -285,10 +266,8 @@ void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float&
|
|||||||
for (int j = 1; j < Lstep.cols - 1; j++) {
|
for (int j = 1; j < Lstep.cols - 1; j++) {
|
||||||
float xpos = ((*(c.ptr<float>(i)+j)) + (*(c.ptr<float>(i)+j + 1)))*((*(Ld.ptr<float>(i)+j + 1)) - (*(Ld.ptr<float>(i)+j)));
|
float xpos = ((*(c.ptr<float>(i)+j)) + (*(c.ptr<float>(i)+j + 1)))*((*(Ld.ptr<float>(i)+j + 1)) - (*(Ld.ptr<float>(i)+j)));
|
||||||
float xneg = ((*(c.ptr<float>(i)+j - 1)) + (*(c.ptr<float>(i)+j)))*((*(Ld.ptr<float>(i)+j)) - (*(Ld.ptr<float>(i)+j - 1)));
|
float xneg = ((*(c.ptr<float>(i)+j - 1)) + (*(c.ptr<float>(i)+j)))*((*(Ld.ptr<float>(i)+j)) - (*(Ld.ptr<float>(i)+j - 1)));
|
||||||
|
|
||||||
float ypos = ((*(c.ptr<float>(i)+j)) + (*(c.ptr<float>(i + 1) + j)))*((*(Ld.ptr<float>(i + 1) + j)) - (*(Ld.ptr<float>(i)+j)));
|
float ypos = ((*(c.ptr<float>(i)+j)) + (*(c.ptr<float>(i + 1) + j)))*((*(Ld.ptr<float>(i + 1) + j)) - (*(Ld.ptr<float>(i)+j)));
|
||||||
float yneg = ((*(c.ptr<float>(i - 1) + j)) + (*(c.ptr<float>(i)+j)))*((*(Ld.ptr<float>(i)+j)) - (*(Ld.ptr<float>(i - 1) + j)));
|
float yneg = ((*(c.ptr<float>(i - 1) + j)) + (*(c.ptr<float>(i)+j)))*((*(Ld.ptr<float>(i)+j)) - (*(Ld.ptr<float>(i - 1) + j)));
|
||||||
|
|
||||||
*(Lstep.ptr<float>(i)+j) = 0.5*stepsize*(xpos - xneg + ypos - yneg);
|
*(Lstep.ptr<float>(i)+j) = 0.5*stepsize*(xpos - xneg + ypos - yneg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,49 +275,37 @@ void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float&
|
|||||||
for (int j = 1; j < Lstep.cols - 1; j++) {
|
for (int j = 1; j < Lstep.cols - 1; j++) {
|
||||||
float xpos = ((*(c.ptr<float>(0) + j)) + (*(c.ptr<float>(0) + j + 1)))*((*(Ld.ptr<float>(0) + j + 1)) - (*(Ld.ptr<float>(0) + j)));
|
float xpos = ((*(c.ptr<float>(0) + j)) + (*(c.ptr<float>(0) + j + 1)))*((*(Ld.ptr<float>(0) + j + 1)) - (*(Ld.ptr<float>(0) + j)));
|
||||||
float xneg = ((*(c.ptr<float>(0) + j - 1)) + (*(c.ptr<float>(0) + j)))*((*(Ld.ptr<float>(0) + j)) - (*(Ld.ptr<float>(0) + j - 1)));
|
float xneg = ((*(c.ptr<float>(0) + j - 1)) + (*(c.ptr<float>(0) + j)))*((*(Ld.ptr<float>(0) + j)) - (*(Ld.ptr<float>(0) + j - 1)));
|
||||||
|
|
||||||
float ypos = ((*(c.ptr<float>(0) + j)) + (*(c.ptr<float>(1) + j)))*((*(Ld.ptr<float>(1) + j)) - (*(Ld.ptr<float>(0) + j)));
|
float ypos = ((*(c.ptr<float>(0) + j)) + (*(c.ptr<float>(1) + j)))*((*(Ld.ptr<float>(1) + j)) - (*(Ld.ptr<float>(0) + j)));
|
||||||
float yneg = ((*(c.ptr<float>(0)+j))+(*(c.ptr<float>(0)+j)))*((*(Ld.ptr<float>(0)+j))-(*(Ld.ptr<float>(0)+j)));
|
*(Lstep.ptr<float>(0) + j) = 0.5*stepsize*(xpos - xneg + ypos);
|
||||||
|
|
||||||
*(Lstep.ptr<float>(0)+j) = 0.5*stepsize*(xpos-xneg + ypos-yneg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 1; j < Lstep.cols - 1; j++) {
|
for (int j = 1; j < Lstep.cols - 1; j++) {
|
||||||
float xpos = ((*(c.ptr<float>(Lstep.rows - 1) + j)) + (*(c.ptr<float>(Lstep.rows - 1) + j + 1)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j + 1)) - (*(Ld.ptr<float>(Lstep.rows - 1) + j)));
|
float xpos = ((*(c.ptr<float>(Lstep.rows - 1) + j)) + (*(c.ptr<float>(Lstep.rows - 1) + j + 1)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j + 1)) - (*(Ld.ptr<float>(Lstep.rows - 1) + j)));
|
||||||
float xneg = ((*(c.ptr<float>(Lstep.rows - 1) + j - 1)) + (*(c.ptr<float>(Lstep.rows - 1) + j)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j)) - (*(Ld.ptr<float>(Lstep.rows - 1) + j - 1)));
|
float xneg = ((*(c.ptr<float>(Lstep.rows - 1) + j - 1)) + (*(c.ptr<float>(Lstep.rows - 1) + j)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j)) - (*(Ld.ptr<float>(Lstep.rows - 1) + j - 1)));
|
||||||
|
|
||||||
float ypos = ((*(c.ptr<float>(Lstep.rows - 1) + j)) + (*(c.ptr<float>(Lstep.rows - 1) + j)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j)) - (*(Ld.ptr<float>(Lstep.rows - 1) + j)));
|
float ypos = ((*(c.ptr<float>(Lstep.rows - 1) + j)) + (*(c.ptr<float>(Lstep.rows - 1) + j)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j)) - (*(Ld.ptr<float>(Lstep.rows - 1) + j)));
|
||||||
float yneg = ((*(c.ptr<float>(Lstep.rows - 2) + j)) + (*(c.ptr<float>(Lstep.rows - 1) + j)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j)) - (*(Ld.ptr<float>(Lstep.rows - 2) + j)));
|
float yneg = ((*(c.ptr<float>(Lstep.rows - 2) + j)) + (*(c.ptr<float>(Lstep.rows - 1) + j)))*((*(Ld.ptr<float>(Lstep.rows - 1) + j)) - (*(Ld.ptr<float>(Lstep.rows - 2) + j)));
|
||||||
|
|
||||||
*(Lstep.ptr<float>(Lstep.rows - 1) + j) = 0.5*stepsize*(xpos - xneg + ypos - yneg);
|
*(Lstep.ptr<float>(Lstep.rows - 1) + j) = 0.5*stepsize*(xpos - xneg + ypos - yneg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < Lstep.rows - 1; i++) {
|
for (int i = 1; i < Lstep.rows - 1; i++) {
|
||||||
float xpos = ((*(c.ptr<float>(i))) + (*(c.ptr<float>(i)+1)))*((*(Ld.ptr<float>(i)+1)) - (*(Ld.ptr<float>(i))));
|
float xpos = ((*(c.ptr<float>(i))) + (*(c.ptr<float>(i)+1)))*((*(Ld.ptr<float>(i)+1)) - (*(Ld.ptr<float>(i))));
|
||||||
float xneg = ((*(c.ptr<float>(i))) + (*(c.ptr<float>(i))))*((*(Ld.ptr<float>(i))) - (*(Ld.ptr<float>(i))));
|
float xneg = ((*(c.ptr<float>(i))) + (*(c.ptr<float>(i))))*((*(Ld.ptr<float>(i))) - (*(Ld.ptr<float>(i))));
|
||||||
|
|
||||||
float ypos = ((*(c.ptr<float>(i))) + (*(c.ptr<float>(i + 1))))*((*(Ld.ptr<float>(i + 1))) - (*(Ld.ptr<float>(i))));
|
float ypos = ((*(c.ptr<float>(i))) + (*(c.ptr<float>(i + 1))))*((*(Ld.ptr<float>(i + 1))) - (*(Ld.ptr<float>(i))));
|
||||||
float yneg = ((*(c.ptr<float>(i - 1))) + (*(c.ptr<float>(i))))*((*(Ld.ptr<float>(i))) - (*(Ld.ptr<float>(i - 1))));
|
float yneg = ((*(c.ptr<float>(i - 1))) + (*(c.ptr<float>(i))))*((*(Ld.ptr<float>(i))) - (*(Ld.ptr<float>(i - 1))));
|
||||||
|
|
||||||
*(Lstep.ptr<float>(i)) = 0.5*stepsize*(xpos - xneg + ypos - yneg);
|
*(Lstep.ptr<float>(i)) = 0.5*stepsize*(xpos - xneg + ypos - yneg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < Lstep.rows - 1; i++) {
|
for (int i = 1; i < Lstep.rows - 1; i++) {
|
||||||
float xpos = ((*(c.ptr<float>(i)+Lstep.cols-1))+(*(c.ptr<float>(i)+Lstep.cols-1)))*((*(Ld.ptr<float>(i)+Lstep.cols-1))-(*(Ld.ptr<float>(i)+Lstep.cols-1)));
|
|
||||||
float xneg = ((*(c.ptr<float>(i)+Lstep.cols - 2)) + (*(c.ptr<float>(i)+Lstep.cols - 1)))*((*(Ld.ptr<float>(i)+Lstep.cols - 1)) - (*(Ld.ptr<float>(i)+Lstep.cols - 2)));
|
float xneg = ((*(c.ptr<float>(i)+Lstep.cols - 2)) + (*(c.ptr<float>(i)+Lstep.cols - 1)))*((*(Ld.ptr<float>(i)+Lstep.cols - 1)) - (*(Ld.ptr<float>(i)+Lstep.cols - 2)));
|
||||||
|
|
||||||
float ypos = ((*(c.ptr<float>(i)+Lstep.cols - 1)) + (*(c.ptr<float>(i + 1) + Lstep.cols - 1)))*((*(Ld.ptr<float>(i + 1) + Lstep.cols - 1)) - (*(Ld.ptr<float>(i)+Lstep.cols - 1)));
|
float ypos = ((*(c.ptr<float>(i)+Lstep.cols - 1)) + (*(c.ptr<float>(i + 1) + Lstep.cols - 1)))*((*(Ld.ptr<float>(i + 1) + Lstep.cols - 1)) - (*(Ld.ptr<float>(i)+Lstep.cols - 1)));
|
||||||
float yneg = ((*(c.ptr<float>(i - 1) + Lstep.cols - 1)) + (*(c.ptr<float>(i)+Lstep.cols - 1)))*((*(Ld.ptr<float>(i)+Lstep.cols - 1)) - (*(Ld.ptr<float>(i - 1) + Lstep.cols - 1)));
|
float yneg = ((*(c.ptr<float>(i - 1) + Lstep.cols - 1)) + (*(c.ptr<float>(i)+Lstep.cols - 1)))*((*(Ld.ptr<float>(i)+Lstep.cols - 1)) - (*(Ld.ptr<float>(i - 1) + Lstep.cols - 1)));
|
||||||
|
*(Lstep.ptr<float>(i)+Lstep.cols - 1) = 0.5*stepsize*(-xneg + ypos - yneg);
|
||||||
*(Lstep.ptr<float>(i)+Lstep.cols-1) = 0.5*stepsize*(xpos-xneg + ypos-yneg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ld = Ld + Lstep;
|
Ld = Ld + Lstep;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function downsamples the input image with the kernel [1/4,1/2,1/4]
|
* @brief This function downsamples the input image with the kernel [1/4,1/2,1/4]
|
||||||
* @param img Input image to be downsampled
|
* @param img Input image to be downsampled
|
||||||
@ -359,9 +326,7 @@ void downsample_image(const cv::Mat& src, cv::Mat& dst) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************************
|
/* ************************************************************************* */
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function downsamples the input image using OpenCV resize
|
* @brief This function downsamples the input image using OpenCV resize
|
||||||
* @param img Input image to be downsampled
|
* @param img Input image to be downsampled
|
||||||
@ -375,9 +340,7 @@ void halfsample_image(const cv::Mat& src, cv::Mat& dst) {
|
|||||||
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
|
* @brief Compute Scharr derivative kernels for sizes different than 3
|
||||||
* @param kx_ The derivative kernel in x-direction
|
* @param kx_ The derivative kernel in x-direction
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
#ifndef _NLDIFFUSION_FUNCTIONS_H_
|
/**
|
||||||
#define _NLDIFFUSION_FUNCTIONS_H_
|
* @file nldiffusion_functions.h
|
||||||
|
* @brief Functions for nonlinear diffusion filtering applications
|
||||||
|
* @date Sep 15, 2013
|
||||||
|
* @author Pablo F. Alcantarilla, Jesus Nuevo
|
||||||
|
*/
|
||||||
|
|
||||||
//******************************************************************************
|
#pragma once
|
||||||
//******************************************************************************
|
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
// Includes
|
// Includes
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
// OpenMP Includes
|
/* ************************************************************************* */
|
||||||
#ifdef _OPENMP
|
|
||||||
# include <omp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//*************************************************************************************
|
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
// Declaration of functions
|
// Declaration of functions
|
||||||
void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, const size_t& ksize_x,
|
void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, const size_t& ksize_x,
|
||||||
const size_t& ksize_y, const float& sigma);
|
const size_t& ksize_y, const float& sigma);
|
||||||
@ -24,8 +21,8 @@ void pm_g1(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
|||||||
void pm_g2(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
void pm_g2(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
||||||
void weickert_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
void weickert_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
||||||
void charbonnier_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
void charbonnier_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
|
||||||
float compute_k_percentile(const cv::Mat& img, const float& perc, const float& gscale,
|
float compute_k_percentile(const cv::Mat& img, float perc, float gscale,
|
||||||
const size_t& nbins, const size_t& ksize_x, const size_t& ksize_y);
|
size_t nbins, size_t ksize_x, size_t ksize_y);
|
||||||
void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, const size_t& xorder,
|
void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, const size_t& xorder,
|
||||||
const size_t& yorder, const size_t& scale);
|
const size_t& yorder, const size_t& 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);
|
||||||
@ -33,9 +30,5 @@ 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_,
|
void compute_derivative_kernels(cv::OutputArray kx_, cv::OutputArray ky_,
|
||||||
const size_t& dx, const size_t& dy, const size_t& scale);
|
const size_t& dx, const size_t& dy, const size_t& scale);
|
||||||
|
bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value,
|
||||||
//*************************************************************************************
|
int row, int col, bool same_img);
|
||||||
//*************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -262,11 +262,7 @@ void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky,
|
|||||||
for (int k = 0; k < 2; k++) {
|
for (int k = 0; k < 2; k++) {
|
||||||
Mat* kernel = k == 0 ? &kx : &ky;
|
Mat* kernel = k == 0 ? &kx : &ky;
|
||||||
int order = k == 0 ? dx : dy;
|
int order = k == 0 ? dx : dy;
|
||||||
std::vector<float> kerI(ksize);
|
std::vector<float> kerI(ksize, 0.0f);
|
||||||
|
|
||||||
for (int t=0; t<ksize; t++) {
|
|
||||||
kerI[t] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (order == 0) {
|
if (order == 0) {
|
||||||
kerI[0] = norm, kerI[ksize/2] = w*norm, kerI[ksize-1] = norm;
|
kerI[0] = norm, kerI[ksize/2] = w*norm, kerI[ksize-1] = norm;
|
||||||
|
0
modules/features2d/src/kaze/nldiffusion_functions.h
Executable file → Normal file
0
modules/features2d/src/kaze/nldiffusion_functions.h
Executable file → Normal file
Loading…
x
Reference in New Issue
Block a user