| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- // Description : A collection of window functions with Finite Impulse Response FIR
- // and some helper window functions with Infinite Impulse Response IIR
- #pragma once
- #include <math.h>
- #include <ImageProcessing_Traits_Platform.h>
- #include <AzCore/Math/MathUtils.h>
- /* ####################################################################################################################
- */
- #ifndef M_PI
- #define M_PI 3.14159265358979323846 /* pi */
- #endif
- //the original file was from cry's RC.exe with all the filters. We decided we would only use few of them for users
- namespace ImageProcessingAtom
- {
- template<class F>
- F cube(const F& op) { return op * op * op; }
- template<class F>
- F square(F fOp) { return(fOp * fOp); }
- enum EWindowFunction
- {
- eWindowFunction_Combiner = 0,
- /*--------------- unit-area filters for unit-spaced samples ----------------*/
- eWindowFunction_Point = 1,
- eWindowFunction_Box = 2, // box, pulse, Fourier window, 1st order (constant) b-spline
- eWindowFunction_Triangle = 3, // triangle, Bartlett window, 2nd order (linear) b-spline
- eWindowFunction_Linear = eWindowFunction_Triangle,
- eWindowFunction_Bartlett = eWindowFunction_Triangle,
- eWindowFunction_Quadric = 4, // 3rd order (quadratic) b-spline
- eWindowFunction_Bilinear = eWindowFunction_Quadric,
- eWindowFunction_Welch = eWindowFunction_Quadric,
- eWindowFunction_Cubic = 5, // 4th order (cubic) b-spline
- eWindowFunction_Hermite = 6, // 4th order (cubic hermite) b-spline
- eWindowFunction_Catrom = 7, // Catmull-Rom spline, Overhauser spline
- eWindowFunction_Sine = 8, // IIR
- eWindowFunction_Sinc = 9, // Sinc, perfect lowpass filter (infinite)
- eWindowFunction_Bessel = 10, // Bessel (for circularly symm. 2-d filt, inf)
- eWindowFunction_Lanczos = 11, // Lanczos filtering, windowed Sinc
- /*------------------ filters for non-unit spaced samples -------------------*/
- eWindowFunction_Gaussian = 12, // Gaussian (infinite)
- eWindowFunction_Normal = 13, // Normal distribution (infinite)
- /*------------------------- parameterized filters --------------------------*/
- eWindowFunction_Mitchell = 14, // Mitchell & Netravali's two-param cubic
- /*--------------------------- window functions -----------------------------*/
- eWindowFunction_Hann = 15, // Hanning window
- eWindowFunction_BartlettHann = 16,
- eWindowFunction_Hamming = 17, // Hamming window
- eWindowFunction_Blackman = 18, // Blackman window
- eWindowFunction_BlackmanHarris = 19,
- eWindowFunction_BlackmanNuttall = 20,
- eWindowFunction_Flattop = 21,
- /*------------------------- parameterized windows --------------------------*/
- eWindowFunction_Kaiser = 22, // parameterized Kaiser window
- /*---------------------------- custom windows ------------------------------*/
- eWindowFunction_SigmaSix = 23, // two Normal distributions
- eWindowFunction_KaiserSinc = 24, // Kaiser and Sinc
- eWindowFunction_Num = eWindowFunction_KaiserSinc + 1,
- };
- enum EWindowEvaluation
- {
- eWindowEvaluation_Sum,
- eWindowEvaluation_Max,
- eWindowEvaluation_Min,
- };
- /* ####################################################################################################################
- */
- template<typename T = float>
- class IWindowFunction
- {
- public:
- virtual ~IWindowFunction() {}
- virtual const char* getName() const = 0;
- virtual T getLength() const = 0;
- virtual bool isCardinal() const = 0;
- virtual bool isInfinite() const = 0;
- virtual bool isUnitSpaced() const = 0;
- virtual bool isCentered() const = 0;
- public:
- virtual T operator () (T pos) const = 0;
- };
- /* ####################################################################################################################
- * box, pulse, Fourier window,
- * box function also know as rectangle function
- * 1st order (constant) b-spline
- */
- template<typename T = double>
- class BoxWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Box-window";
- }
- virtual T getLength() const
- {
- return 0.5;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos <= 0.5)
- {
- return 1.0;
- }
- return 0.0;
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * triangle, Bartlett window,
- * triangle function also known as lambda function
- * 2nd order (linear) b-spline
- */
- template<typename T = double>
- class TriangleWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Triangle-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < 1.0)
- {
- return 1.0 - pos;
- }
- return 0.0;
- }
- };
- /* ####################################################################################################################
- * 3rd order (quadratic) b-spline
- */
- template<typename T = double>
- class QuadricWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Quadric-window";
- }
- virtual T getLength() const
- {
- return 1.5;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < 0.5)
- {
- return 0.75 - square(pos);
- }
- if (pos < 1.5)
- {
- return 0.50 * square(pos - 1.5);
- }
- return 0.0;
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * 4th order (cubic) b-spline
- */
- template<typename T = double>
- class CubicWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Cubic-window";
- }
- virtual T getLength() const
- {
- return 2.0;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < 1.0)
- {
- return 0.5 * cube(pos) - square(pos) + 2.0 / 3.0;
- }
- if (pos < 2.0)
- {
- return cube(2.0 - pos) / 6.0;
- }
- return 0.0;
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Hermite filter
- * f(x) = 2|x|^3 - 3|x|^2 + 1, -1 <= x <= 1
- */
- template<typename T = double>
- class HermiteWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Hermite-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < 1.0)
- {
- return 2.0 * cube(pos) - 3.0 * square(pos) + 1.0;
- }
- return 0.0;
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Catmull-Rom spline, Overhauser spline
- */
- template<typename T = double>
- class CatromWindowFunction
- : public IWindowFunction<T>
- {
- public:
- CatromWindowFunction() { }
- public:
- virtual const char* getName() const
- {
- return "Catrom-window";
- }
- virtual T getLength() const
- {
- return 2.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < 1.0)
- {
- return 1.5 * cube(pos) - 2.5 * square(pos) + 1.0;
- }
- if (pos < 2.0)
- {
- return -0.5 * cube(pos) + 2.5 * square(pos) - 4.0 * pos + 2.0;
- }
- return 0.0;
- }
- };
- /* ####################################################################################################################
- */
- template<typename T = double>
- class SineWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Sine-window";
- }
- virtual T getLength() const
- {
- return 0.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return sin(pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * sinc, perfect lowpass filter (infinite)
- *
- * Note: Some people say sinc(x) is sin(x)/x. Others say it's
- * sin(PI*x)/(PI*x), a horizontal compression of the former which is
- * zero at integer values. We use the latter, whose Fourier transform
- * is a canonical rectangle function (edges at -1/2, +1/2, height 1).
- */
- template<typename T = double>
- class SincWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Sinc-window";
- }
- virtual T getLength() const
- {
- return 4.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos == 0.0)
- {
- return 1.0;
- }
- return sin(M_PI * pos) / (M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Bessel (for circularly symm. 2-d filt, infinite)
- * See Pratt "Digital Image Processing" p. 97 for Bessel functions
- */
- template<typename T = double>
- class BesselWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Bessel-window";
- }
- virtual T getLength() const
- {
- return 3.2383;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos == 0.0)
- {
- return M_PI / 4.0;
- }
- return AZ_TRAIT_IMAGEPROCESSING_BESSEL_FUNCTION_FIRST_ORDER(M_PI * pos) / (2.0 * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Lanczos filter
- */
- template<typename T = double>
- class LanczosWindowFunction
- : public SincWindowFunction<T>
- {
- public:
- LanczosWindowFunction(T tap = 3.0)
- {
- this->tap = AZ::GetMax(3.0, tap);
- }
- protected:
- T tap;
- public:
- virtual const char* getName() const
- {
- return "Lanczos-window";
- }
- virtual T getLength() const
- {
- return tap;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < tap)
- {
- return ((SincWindowFunction<T>) * this)(pos) * ((SincWindowFunction<T>) * this)(pos / tap);
- }
- return 0.0;
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Gaussian filter (infinite)
- */
- template<typename T = double>
- class GaussianWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Gaussian-window";
- }
- virtual T getLength() const
- {
- return 1.25;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return exp(-2.0 * square(pos)) * sqrt(2.0 / M_PI);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * normal distribution (infinite)
- * Normal(x) = Gaussian(x/2)/2
- */
- template<typename T = double>
- class NormalWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Normal-window";
- }
- virtual T getLength() const
- {
- return 2.5;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return exp(-square(pos) / 2.0) / sqrt(2.0 * M_PI);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- */
- template<typename T = double>
- class SigmaSixWindowFunction
- : public IWindowFunction<T>
- {
- public:
- SigmaSixWindowFunction(T diameter = 1.0, T negative = 0.0)
- {
- // we aim for 6 * sigma = 99,99996% of all values
- const T sigma = 1.0 / 3.0;
- s2 = sigma * sigma * 2.0;
- d2 = s2 / (diameter * diameter);
- d = diameter;
- n = negative;
- }
- protected:
- T s2, d2, d, n;
- public:
- virtual const char* getName() const
- {
- return "SigmaSix-window";
- }
- virtual T getLength() const
- {
- return 1.44;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- T o = exp(-square(pos) / s2) - (1.0 - 0.9999996);
- T i = exp(-square(pos) / d2) - (1.0 - 0.9999996);
- return (pos >= d ? 0.0 : i) - o * n;
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Mitchell & Netravali's two-param cubic
- * see Mitchell & Netravali,
- * "Reconstruction Filters in Computer Graphics", SIGGRAPH 88
- */
- template<typename T = double>
- class MitchellWindowFunction
- : public IWindowFunction<T>
- {
- public:
- MitchellWindowFunction(T b = 1.0 / 3.0, T c = 1.0 / 3.0)
- {
- p0 = (6. - 2. * b) / 6.;
- p2 = (-18. + 12. * b + 6. * c) / 6.;
- p3 = (12. - 9. * b - 6. * c) / 6.;
- q0 = (8. * b + 24. * c) / 6.;
- q1 = (-12. * b - 48. * c) / 6.;
- q2 = (6. * b + 30. * c) / 6.;
- q3 = (-b - 6. * c) / 6.;
- }
- protected:
- T p0, p2, p3, q0, q1, q2, q3;
- public:
- virtual const char* getName() const
- {
- return "Mitchell-window";
- }
- virtual T getLength() const
- {
- return 2.0;
- }
- virtual bool isCardinal() const
- {
- return false;
- }
- virtual bool isInfinite() const
- {
- return false;
- }
- virtual bool isUnitSpaced() const
- {
- return false;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- if (pos < 0.0)
- {
- pos = -pos;
- }
- if (pos < 1.0)
- {
- return p3 * cube(pos) + p2 * square(pos) + p0;
- }
- if (pos < 2.0)
- {
- return q3 * cube(pos) + q2 * square(pos) + q1 * pos + q0;
- }
- return 0.0;
- }
- };
- /* ####################################################################################################################
- * Hanning window (infinite)
- */
- template<typename T = double>
- class HannWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Hann-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.5 + 0.5 * cos(M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * BartlettHanning window (infinite)
- */
- template<typename T = double>
- class BartlettHannWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Bartlett-Hann-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.62 + 0.48 * (1.0 - pos) + 0.38 * cos(M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Hamming window (infinite)
- */
- template<typename T = double>
- class HammingWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Hamming-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.53836 + 0.46164 * cos(M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * Blackman window (infinite)
- */
- template<typename T = double>
- class BlackmanWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Blackman-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.42659
- + 0.49656 * cos(M_PI * pos)
- + 0.07685 * cos(2.0 * M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * BlackmanHarris window (infinite)
- */
- template<typename T = double>
- class BlackmanHarrisWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Blackman-Harris-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.35875
- + 0.48829 * cos(M_PI * pos)
- + 0.14128 * cos(2.0 * M_PI * pos)
- + 0.01168 * cos(3.0 * M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * BlackmanNuttall window (infinite)
- */
- template<typename T = double>
- class BlackmanNuttallWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Blackman-Nuttall-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.3635819
- + 0.4891775 * cos(M_PI * pos)
- + 0.1365995 * cos(2.0 * M_PI * pos)
- + 0.0106411 * cos(3.0 * M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * FlatTop window (infinite)
- */
- template<typename T = double>
- class FlatTopWindowFunction
- : public IWindowFunction<T>
- {
- public:
- virtual const char* getName() const
- {
- return "Flat-Top-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return 0.215578948
- + 0.416631580 * cos(M_PI * pos)
- + 0.277263158 * cos(2.0 * M_PI * pos)
- + 0.083578947 * cos(3.0 * M_PI * pos)
- + 0.006947368 * cos(4.0 * M_PI * pos);
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- * parameterized Kaiser window (infinite)
- * from Oppenheim & Schafer, Hamming
- */
- template<typename T = double>
- class KaiserWindowFunction
- : public IWindowFunction<T>
- {
- public:
- KaiserWindowFunction(T a = 6.5)
- {
- /* typically 4<a<9 */
- /* param a trades off main lobe width (sharpness) */
- /* for side lobe amplitude (ringing) */
- this->a = a;
- this->i0a = 1. / bessel_i0(a);
- }
- protected:
- T a, i0a;
- /* modified zeroth order Bessel function of the first kind. */
- static T bessel_i0(T x)
- {
- #define EPSILON 1e-7
- const T y = square(x) / 4.0;
- T sum = 1.0;
- T t = y;
- for (int i = 2; t > EPSILON; i++)
- {
- sum += t;
- t *= y / square(i);
- }
- return sum;
- #undef EPSILON
- }
- public:
- virtual const char* getName() const
- {
- return "Kaiser-window";
- }
- virtual T getLength() const
- {
- return 1.0;
- }
- virtual bool isCardinal() const
- {
- return true;
- }
- virtual bool isInfinite() const
- {
- return true;
- }
- virtual bool isUnitSpaced() const
- {
- return true;
- }
- virtual bool isCentered() const
- {
- return true;
- }
- public:
- virtual T operator () (T pos) const
- {
- return i0a * bessel_i0(a * sqrt(1.0 - square(pos)));
- }
- };
- /* ####################################################################################################################
- */
- template<typename T = double>
- class CombinerWindowFunction
- : public IWindowFunction<T>
- {
- public:
- CombinerWindowFunction(IWindowFunction<T>* fu, IWindowFunction<T>* wi)
- {
- shaper = fu;
- restrictor = wi;
- }
- protected:
- IWindowFunction<T>* shaper;
- IWindowFunction<T>* restrictor;
- public:
- virtual const char* getName() const
- {
- return "Combiner of two window-generators";
- }
- virtual T getLength() const
- {
- return shaper->getLength();
- }
- virtual bool isCardinal() const
- {
- return shaper->isCardinal() && restrictor->isCardinal();
- }
- virtual bool isInfinite() const
- {
- return shaper->isInfinite() && restrictor->isInfinite();
- }
- virtual bool isUnitSpaced() const
- {
- return shaper->isUnitSpaced() && restrictor->isUnitSpaced();
- }
- virtual bool isCentered() const
- {
- return shaper->isCentered() && restrictor->isCentered();
- }
- public:
- virtual T operator () (T pos) const
- {
- return (*shaper)(pos) * (*restrictor)(pos / shaper->getLength());
- }
- };
- /* --------------------------------------------------------------------------------------------------------------------
- */
- template<typename T = double>
- class PointWindowFunction
- : public BoxWindowFunction<T>
- {
- public:
- PointWindowFunction()
- : BoxWindowFunction<T>() { }
- public:
- virtual const char* getName() const
- {
- return "Point-window";
- }
- virtual T getLength() const
- {
- return 0.0;
- }
- };
- } //end namespace ImageProcessingAtom
|