STIRA
0.1
|
A class with some handy mathematical functions. More...
#include <MathUtils.h>
Public Member Functions | |
MathUtils () | |
Constructor. | |
~MathUtils () | |
Destructor. | |
bool | SolveQuadraticEquation (double a, double b, double c, double &outSolution1, double &outSolution2) |
solves a quadratic equation a * x * x + b * x + c = 0 (real-valued case) More... | |
Static Public Member Functions | |
static void | SwitchValues (double &a, double &b) |
switches the values for the variables a and b More... | |
static void | SwitchValues (int &a, int &b) |
switches the values for the variables a and b More... | |
static double | GetMin (double value1, double value2) |
returns the smallest of both input values More... | |
static double | GetMax (double value1, double value2) |
returns the largest of both input values More... | |
static int | CompareDoubles (const void *a, const void *b) |
compare method for two doubles, as needed by qsort More... | |
static int | CompareFloats (const void *a, const void *b) |
compare method for two floats, as needed by qsort More... | |
static int | CompareIntegers (const void *a, const void *b) |
compare method for two doubles, as needed by qsort More... | |
static int | ClipValue (int value, int min=0, int max=255) |
Clips value to be in the range [min, max] if the user by accident switches the maximum and minimum values, this method corrects this. More... | |
static double | ClipValue (double value, double min=0.0, double max=255.0) |
Clips value to be in the range [min, max] if the user by accident switches the maximum and minimum values, this method corrects this. More... | |
static bool | IsBetween (double testValue, double underLimit, double upperLimit) |
Checks if a value is between a lower and an upper value. More... | |
static double | ApplyModulo (double input, double modulo) |
applies modulo to number While number is larger than number, subtract modulo; While number is smaller than 0, add modulo More... | |
static void | PrintBitsInInt (unsigned int i) |
prints to stdout the bits in a 32bit unsigned integer More... | |
static void | PrintBitsInChar (unsigned char c) |
prints to stdout the bits in an unsigned char More... | |
static unsigned int | CombineCharsInInt (unsigned char i0, unsigned char i1, unsigned char i2, unsigned char i3) |
combine 4 unsigned in one 32 bit unsigned integer [ 1 1 1 1 1 1 1 1 ] [ 1 1 1 1 1 1 1 1 ] [ 1 1 1 1 1 1 1 1 ] [ 1 1 1 1 1 1 1 1 ] unsigned char c0 unsigned char c1 unsigned char c2 unsigned char c3 More... | |
static std::vector< unsigned char > | SplitIntInChars (int value) |
splits a 32bit unsigned integer in a vector of 4 unsigned chars More... | |
static double | ComputeArgument (double x, double y) |
computes the angle of the line from the origin to the point (x,y) More... | |
static double | ToRadians (double degrees) |
converts degrees to radians More... | |
static double | ToDegrees (double radians) |
converts radians to degrees More... | |
static bool | SolveLinearEquation (double a, double b, double &solution) |
solves a linear equation ax + b = 0 More... | |
static bool | SolveQuadraticEquation (std::complex< double > a, std::complex< double > b, std::complex< double > c, std::complex< double > &outSolution1, std::complex< double > &outSolution2) |
solves a quadratic equation a * x * x + b * x + c = 0 (complex-valued case) More... | |
static double | LinearInterpolate (double x0, double y0, double x1, double y1, double x) |
Computes y value according to linear interpolation. | |
static double | ComputePSNR (double MSE, double peakValue=255.0) |
Computes PSNR (Peak Signal to Noise Ratio) given the MSE (Mean Square Error) Ref: http://en.wikipedia.org/wiki/PSNR. More... | |
static double | GammaCorrect (double inValue, double gamma, double rangeMin=0.0, double rangeMax=255.0) |
applies gamma correction to input value Data is for gamma correction first normalized between 0 and 1 More... | |
static double | GetSteerableInterPolationCoefficient (int i, int K, double theta) |
computes steerable interpolation coefficient for angle theta Suppose B_theta(x,y) = k1(theta) * B1(x,y)) + k2(theta) * B2(x,y)) + k3(theta) * B1(x,y), with B_theta the interpolated band, ki(theta) the interpolation coefficients (i=1,2,3) and Bi(x,y) the basis bands (i=1,2,3). then this function computes ki(theta) This formulation is a generalization of the expression of Freeman and Adelson by Bart Goossens for an arbitrary number of orientations More... | |
static double | Factorial (const double &inputNumber) |
help function to have an exact factorial in case the input number is a casted integer More... | |
static int | ComputeIntegerPower (int myNumber, int myExponent) |
computes myNumber to the power myExponent, to prevent all that messy casting that pow() otherwise requires More... | |
static std::vector< double > | GenerateGaussianSamples (double sigma) |
computes a set of points sampled regularly from the Gauss function (NOT random variables with Gaussian distribution!!) More... | |
static std::vector< Point< double > > | GenerateGaussianPoints (int gaussCenterX, double sigma, bool scaleAmplitude=false, double amplitude=1) |
computes a set of Gaussian sample points The Gaussian has the peak at gaussCenterX, unity sample distance and half width 2 times sigma More... | |
static std::vector< Point< double > > | GenerateGaussianPoints (std::vector< Point< double > > inPoints, int gaussCenterX, double sigma, bool scaleAmplitude, double amplitude) |
computes a set of Gaussian sample points It uses the x coordinates of inPoints to compute the function value with the peak at gaussCenterX More... | |
static double | Gaussian (double x, double mu, double sigma) |
computes for a value x the value G(x) with G the Gaussian function (as used in probabilities) Reference: http://mathworld.wolfram.com/GaussianFunction.html G(x) = 1/sqrt(2*sigma*pi) * exp( (x - mu) / 2 sigma^2 ) More... | |
static double | Gaussian (double x, double y, double muX, double muY, double sigmaX, double sigmaY) |
computes for a point (x,y) the value G(x,y) with G the 2D Gaussian function (as used in probabilities) Reference: http://mathworld.wolfram.com/GaussianFunction.html G(x) = 1/(2*pi*sigmaX*sigmaY) * exp( (x - muX) / (2 sigmaX^2) + (y - muY) / (2 sigmaY^2) ) More... | |
static double | GaussianFirstDerivativeX1D (double x, double mu, double sigma) |
computes for a value x the value G'(x) with G' the first derivative of the Gaussian function More... | |
static double | GaussianSecondDerivateX1D (double x, double mu, double sigma) |
computes for a value x the value G''(x) with G'' the second derivative of the Gaussian function More... | |
static double | GaussianDx (double x, double y, double muX, double muY, double sigmaX, double sigmaY) |
computes for a point (x,y) the value of the first derivative to x of the 2D Gaussian function More... | |
static double | GaussianDy (double x, double y, double muX, double muY, double sigmaX, double sigmaY) |
computes for a point (x,y) the value of the first derivative to y of the 2D Gaussian function More... | |
static double | GaussianSecondDerivateX1D (double x, double y, double muX, double muY, double sigmaX, double sigmaY) |
computes for a point (x,y) the value of the second derivative to x of the 2D Gaussian function More... | |
static double | GaussianD2y (double x, double y, double muX, double muY, double sigmaX, double sigmaY) |
computes for a point (x,y) the value of the second derivative to y of the 2D Gaussian function More... | |
static double | GaussianDxDy (double x, double y, double muX, double muY, double sigmaX, double sigmaY) |
computes for a point (x,y) the value of the mixed first derivatives to x and y of the 2D Gaussian function More... | |
static double * | ComputeCrossCorrelation (double *x, double *y, int nrSamples, int maxDelay) |
Computes cross-correlation between two signals x and y Reference: code + explanation: http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/correlate/ general: http://en.wikipedia.org/wiki/Cross-correlation. More... | |
static void | NormalizeVector (std::vector< double > &inVector) |
normalizes all elements of the vector passed as argument, overwriting the original values More... | |
A class with some handy mathematical functions.
|
static |
applies modulo to number While number is larger than number, subtract modulo; While number is smaller than 0, add modulo
input | input number |
modulo | modulo |
Referenced by stira::imagetools::FractalGenerator::GetMathWidth(), and stira::imagedata::TransformColorSpace::LabtoLCH().
|
static |
Clips value to be in the range [min, max] if the user by accident switches the maximum and minimum values, this method corrects this.
min | the minimum value allowed value after clipping |
value | the value to be clipped |
max | the maximum value allowed after clipping |
Referenced by stira::imagedata::Image::AddGaussianNoise(), stira::imagedata::TransformColorSpace::AdobeRGBtoXYZ(), stira::imagetools::FisheyeCorrector::ApplyCorrect(), stira::imagedata::Image::ApplyPoissonNoise(), stira::imagetools::NumberGridTools< T >::ClipValues(), stira::imagedata::GridStatistics< T >::ComputeLocalAbsoluteMean(), stira::imagedata::GridStatistics< T >::ComputeLocalCovariance(), stira::imagedata::GridStatistics< T >::ComputeLocalKurtosis(), stira::imagedata::GridStatistics< T >::ComputeLocalMean(), stira::imagedata::GridStatistics< T >::ComputeLocalVariance(), stira::filter::LocalBinaryPattern::ComputePointLBPSymHistogram(), stira::imagedata::Image::CopyImageValues(), stira::imagetools::NumberGridTools< T >::CopyValues(), stira::contrastenhance::HistogramTools::MatchHistogramValue(), stira::imagetools::NumberGridTools< T >::ProjectGridOnY(), stira::contrastenhance::HistogramTools::RemapHistogramInROI(), stira::contrastenhance::HistogramTools::RobustLinearRescaleNoNew(), stira::contrastenhance::AdaptiveHistogramEqualizer::Run(), stira::deconvolve::RichardsonLucyDeconvolve::Run(), stira::imageanalysis::Thinning< T >::RunPruning(), stira::imageanalysis::Thinning< T >::RunThinning(), stira::contrastenhance::AdaptiveEnhanceLuong::SetWindowSize(), stira::histogram::IntHistogram::Write(), stira::imagedata::TransformColorSpace::XYZtoAdobeRGB(), and stira::deconvolve::SimulateDegradation::~SimulateDegradation().
|
static |
Clips value to be in the range [min, max] if the user by accident switches the maximum and minimum values, this method corrects this.
min | the minimum value allowed value after clipping |
value | the value to be clipped |
max | the maximum value allowed after clipping |
|
static |
combine 4 unsigned in one 32 bit unsigned integer [ 1 1 1 1 1 1 1 1 ] [ 1 1 1 1 1 1 1 1 ] [ 1 1 1 1 1 1 1 1 ] [ 1 1 1 1 1 1 1 1 ] unsigned char c0 unsigned char c1 unsigned char c2 unsigned char c3
c0 | first input unsigned char, will be placed at the most significant bits of the integer |
c1 | second input unsigned char, will be placed at the next 8 less significant bits of the integer |
c2 | third input unsigned char, will be placed at the next 8 less significant bits of the integer |
c3 | fourth input unsigned char, will be placed at the least significant bits of the integer |
Referenced by stira::imagetools::ImageTools::CreateIntArrayFromColorImage().
|
static |
compare method for two doubles, as needed by qsort
a | first number to compare |
b | second number to compare |
Referenced by stira::filter::MedianFilter::RunHybridMedian(), and stira::filter::MedianFilter::RunMedian().
|
static |
compare method for two floats, as needed by qsort
a | first number to compare |
b | second number to compare |
|
static |
compare method for two doubles, as needed by qsort
a | first number to compare |
b | second number to compare |
Referenced by stira::filter::MedianFilter::RunMedian().
|
static |
computes the angle of the line from the origin to the point (x,y)
x | x coordinate |
y | y coordinate |
Referenced by stira::steerable::ComputeOrientation::ComputeDominantOrientationInputComplexPyramidLevel(), stira::steerable::ComputeOrientation::ComputeDominantOrientationInputFreemanAdelson(), and stira::imageanalysis::StegerLineDetector::Run().
|
static |
Computes cross-correlation between two signals x and y Reference: code + explanation: http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/correlate/ general: http://en.wikipedia.org/wiki/Cross-correlation.
x | array of values of first function |
y | array of values of second function |
nrSamples | number of elements in x and y |
maxDelay | maximum delay to compute cross-correlation for |
|
static |
computes myNumber to the power myExponent, to prevent all that messy casting that pow() otherwise requires
myNumber | the number to be raised to the power myExponent |
myExponent | the exponent to be used |
Referenced by stira::filter::LocalBinaryPattern::ComputePointLBPSym(), stira::imagedata::Pyramid< T >::CreateBands(), stira::imagedata::Pyramid< T >::GetAverageConeRatioRedundant(), stira::imagedata::Pyramid< T >::GetAverageConeRatioSubSampled(), stira::wavelet::NonSubsampledTransform::Reconstruct(), stira::filter::LocalBinaryPattern::RunHistogram(), stira::filter::LocalBinaryPattern::SignComparison(), and stira::pyramidapplications::PyramidKeyPointDetector::~PyramidKeyPointDetector().
|
static |
Computes PSNR (Peak Signal to Noise Ratio) given the MSE (Mean Square Error) Ref: http://en.wikipedia.org/wiki/PSNR.
MSE | the MSE (Mean Square Error) |
peakValue | maximum possible value of the data range |
Referenced by stira::imagetools::NumberGridTools< T >::ComputePSNR(), stira::imagetools::NumberGridTools< T >::ComputePSNRinROI(), and stira::imagetools::NumberGridTools< T >::CreateSquaredErrorGrid().
|
static |
help function to have an exact factorial in case the input number is a casted integer
inputNumber | number of which to compute the factorial |
Referenced by stira::fouriertools::TransferFunctionGenerator::GenerateOrientedTransferFunction().
|
static |
applies gamma correction to input value Data is for gamma correction first normalized between 0 and 1
inValue | incoming value |
gamma | value of gamma |
rangeMin | minimum of data range of incoming value |
rangeMax | maximum of data range of incoming value |
Referenced by stira::imagetools::ImageTools::ApplyGamma().
|
static |
computes for a value x the value G(x) with G the Gaussian function (as used in probabilities) Reference: http://mathworld.wolfram.com/GaussianFunction.html G(x) = 1/sqrt(2*sigma*pi) * exp( (x - mu) / 2 sigma^2 )
x | value for which to compute the function value |
mu | mu of the function (related to the position of the peak of the function ) |
sigma | sigma of the function (related to the width) |
Referenced by stira::filter::GaussConvolve::CreateBlurredBars(), and stira::imagetools::GridGenerator::GenerateGaussian().
|
static |
computes for a point (x,y) the value G(x,y) with G the 2D Gaussian function (as used in probabilities) Reference: http://mathworld.wolfram.com/GaussianFunction.html G(x) = 1/(2*pi*sigmaX*sigmaY) * exp( (x - muX) / (2 sigmaX^2) + (y - muY) / (2 sigmaY^2) )
x | x coordinate of point for which to compute the function value |
y | y coordinate of point for which to compute the function value |
muX | muX of the function (related to the x coordinate of the position of the peak of the function ) |
muY | muY of the function (related to the y coordinate of the position of the peak of the function ) |
sigmaX | sigmaX of the function (related to the width in the x-direction) |
sigmaY | sigmaY of the function (related to the width in the y-direction) |
|
static |
computes for a point (x,y) the value of the second derivative to y of the 2D Gaussian function
x | x coordinate of point for which to compute the function value |
y | y coordinate of point for which to compute the function value |
muX | muX of the function (related to the x coordinate of the position of the peak of the function ) |
muY | muY of the function (related to the y coordinate of the position of the peak of the function ) |
sigmaX | sigmaX of the function (related to the width in the x-direction) |
sigmaY | sigmaY of the function (related to the width in the y-direction) |
Referenced by stira::imagetools::GridGenerator::GenerateGaussianSecondDerivativeY().
|
static |
computes for a point (x,y) the value of the first derivative to x of the 2D Gaussian function
x | x coordinate of point for which to compute the function value |
y | y coordinate of point for which to compute the function value |
muX | muX of the function (related to the x coordinate of the position of the peak of the function ) |
muY | muY of the function (related to the y coordinate of the position of the peak of the function ) |
sigmaX | sigmaX of the function (related to the width in the x-direction) |
sigmaY | sigmaY of the function (related to the width in the y-direction) |
Referenced by stira::imagetools::GridGenerator::GenerateGaussianFirstDerivativeX().
|
static |
computes for a point (x,y) the value of the mixed first derivatives to x and y of the 2D Gaussian function
x | x coordinate of point for which to compute the function value |
y | y coordinate of point for which to compute the function value |
muX | muX of the function (related to the x coordinate of the position of the peak of the function ) |
muY | muY of the function (related to the y coordinate of the position of the peak of the function ) |
sigmaX | sigmaX of the function (related to the width in the x-direction) |
sigmaY | sigmaY of the function (related to the width in the y-direction) |
Referenced by stira::imagetools::GridGenerator::GenerateGaussianMixedDerivativesXY().
|
static |
computes for a point (x,y) the value of the first derivative to y of the 2D Gaussian function
x | x coordinate of point for which to compute the function value |
y | y coordinate of point for which to compute the function value |
muX | muX of the function (related to the x coordinate of the position of the peak of the function ) |
muY | muY of the function (related to the y coordinate of the position of the peak of the function ) |
sigmaX | sigmaX of the function (related to the width in the x-direction) |
sigmaY | sigmaY of the function (related to the width in the y-direction) |
Referenced by stira::imagetools::GridGenerator::GenerateGaussianFirstDerivativeY().
|
static |
computes for a value x the value G'(x) with G' the first derivative of the Gaussian function
x | value for which to compute the function value |
mu | mu of the function |
sigma | sigma of the function |
Referenced by stira::filter::GaussConvolve::CreateBlurredBars().
|
static |
computes for a value x the value G''(x) with G'' the second derivative of the Gaussian function
x | value for which to compute the function value |
mu | mu of the function |
sigma | sigma of the function |
Referenced by stira::filter::GaussConvolve::CreateBlurredBars(), and stira::imagetools::GridGenerator::GenerateGaussianSecondDerivativeX().
|
static |
computes for a point (x,y) the value of the second derivative to x of the 2D Gaussian function
x | x coordinate of point for which to compute the function value |
y | y coordinate of point for which to compute the function value |
muX | muX of the function (related to the x coordinate of the position of the peak of the function ) |
muY | muY of the function (related to the y coordinate of the position of the peak of the function ) |
sigmaX | sigmaX of the function (related to the width in the x-direction) |
sigmaY | sigmaY of the function (related to the width in the y-direction) |
|
static |
computes a set of Gaussian sample points The Gaussian has the peak at gaussCenterX, unity sample distance and half width 2 times sigma
gaussCenterX | x coordinate cooresponding with the center (i.e., the peak) |
sigma | sigma of the gaussian profile |
scaleAmplitude | flag whether or not the values are rescaled so the peak has a predefined value |
amplitude | predefined value for the peak |
|
static |
computes a set of Gaussian sample points It uses the x coordinates of inPoints to compute the function value with the peak at gaussCenterX
gaussCenterX | x coordinate cooresponding with the center (i.e., the peak) |
sigma | sigma of the gaussian profile |
scaleAmplitude | flag whether or not the values are rescaled so the peak has a predefined value |
amplitude | predefined value for the peak |
|
static |
computes a set of points sampled regularly from the Gauss function (NOT random variables with Gaussian distribution!!)
sigma | sigma of the function |
|
static |
returns the largest of both input values
value1 | first input value |
value2 | second input value |
Referenced by stira::imagetools::ImageTools::ApplyJetColorMap(), and stira::contrastenhance::HazeRemover::Run().
|
static |
returns the smallest of both input values
value1 | first input value |
value2 | second input value |
Referenced by stira::imagetools::ImageTools::ApplyJetColorMap(), and stira::deconvolve::RichardsonLucyDeconvolve::Run().
|
static |
computes steerable interpolation coefficient for angle theta Suppose B_theta(x,y) = k1(theta) * B1(x,y)) + k2(theta) * B2(x,y)) + k3(theta) * B1(x,y), with B_theta the interpolated band, ki(theta) the interpolation coefficients (i=1,2,3) and Bi(x,y) the basis bands (i=1,2,3). then this function computes ki(theta) This formulation is a generalization of the expression of Freeman and Adelson by Bart Goossens for an arbitrary number of orientations
i | the number of the band with which the interpolation coefficient corresponds (see above) |
K | the total number of oriented bands (in our example above, K=3) |
theta | the angle under which to interpolate |
|
static |
Checks if a value is between a lower and an upper value.
testValue | the value to be checked |
underLimit | the lower limit for the value |
upperLimit | the upper limit for the value |
|
static |
normalizes all elements of the vector passed as argument, overwriting the original values
inVector | vector to normalize |
Referenced by stira::imageanalysis::HOG::ComputeHogDescriptor().
|
static |
prints to stdout the bits in an unsigned char
c | input unigned char |
|
static |
prints to stdout the bits in a 32bit unsigned integer
i | input unigned integer |
|
static |
solves a linear equation ax + b = 0
a | slope coefficient |
b | offset |
solution | the solution of the equation |
Referenced by stira::imageanalysis::StegerLineDetector::Run().
bool stira::common::MathUtils::SolveQuadraticEquation | ( | double | a, |
double | b, | ||
double | c, | ||
double & | outSolution1, | ||
double & | outSolution2 | ||
) |
solves a quadratic equation a * x * x + b * x + c = 0 (real-valued case)
a | quadratic coefficient |
b | linear coefficient |
c | constant |
outSolution1 | the first solution of the equation |
outSolution2 | the second solution of the equation |
|
static |
solves a quadratic equation a * x * x + b * x + c = 0 (complex-valued case)
a | quadratic coefficient |
b | linear coefficient |
c | constant |
outSolution1 | the first solution of the equation |
outSolution2 | the second solution of the equation |
|
static |
splits a 32bit unsigned integer in a vector of 4 unsigned chars
value | input unsigned integer |
Referenced by stira::imagetools::ImageTools::CreateColorImageFromIntArray().
|
static |
switches the values for the variables a and b
a | the first value; gets the value of b after switch |
b | the second value; gets the value of a after switch |
|
static |
switches the values for the variables a and b
a | the first value; gets the value of b after switch |
b | the second value; gets the value of a after switch |
|
static |
converts radians to degrees
radians | value in radians to convert to degrees |
Referenced by stira::imagedata::OrientationGrid::GetMagnitude(), and stira::imagedata::TransformColorSpace::LabtoLCH().
|
static |
converts degrees to radians
degrees | value in degrees to convert to radians |
Referenced by stira::imagedata::TransformColorSpace::LCHtoLab(), and stira::imageanalysis::CannyEdgeDetector::~CannyEdgeDetector().