From d58f6b51493c7931cbc02feb3ffeb0eca6ea3a4e Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 5 Jul 2018 16:13:37 +0200 Subject: Refactor a few filter-related functions out of cuda code --- .../astra/CudaFilteredBackProjectionAlgorithm.h | 3 +- include/astra/Filters.h | 71 ++++++++++++++++++++++ include/astra/cuda/2d/astra.h | 1 - include/astra/cuda/2d/fbp.h | 2 +- include/astra/cuda/2d/fbp_filters.h | 61 ------------------- include/astra/cuda/2d/fft.h | 8 +-- 6 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 include/astra/Filters.h delete mode 100644 include/astra/cuda/2d/fbp_filters.h (limited to 'include') diff --git a/include/astra/CudaFilteredBackProjectionAlgorithm.h b/include/astra/CudaFilteredBackProjectionAlgorithm.h index 1280e9a..974914a 100644 --- a/include/astra/CudaFilteredBackProjectionAlgorithm.h +++ b/include/astra/CudaFilteredBackProjectionAlgorithm.h @@ -33,6 +33,7 @@ along with the ASTRA Toolbox. If not, see . #include "Float32ProjectionData2D.h" #include "Float32VolumeData2D.h" #include "CudaReconstructionAlgorithm2D.h" +#include "Filters.h" #include "cuda/2d/astra.h" @@ -52,8 +53,6 @@ private: float m_fFilterD; // frequency cut-off bool m_bShortScan; // short-scan mode for fan beam - static E_FBPFILTER _convertStringToFilter(const char * _filterType); - public: CCudaFilteredBackProjectionAlgorithm(); virtual ~CCudaFilteredBackProjectionAlgorithm(); diff --git a/include/astra/Filters.h b/include/astra/Filters.h new file mode 100644 index 0000000..ff3f5c8 --- /dev/null +++ b/include/astra/Filters.h @@ -0,0 +1,71 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _INC_ASTRA_FILTERS_H +#define _INC_ASTRA_FILTERS_H + +namespace astra { + +enum E_FBPFILTER +{ + FILTER_ERROR, //< not a valid filter + FILTER_NONE, //< no filter (regular BP) + FILTER_RAMLAK, //< default FBP filter + FILTER_SHEPPLOGAN, //< Shepp-Logan + FILTER_COSINE, //< Cosine + FILTER_HAMMING, //< Hamming filter + FILTER_HANN, //< Hann filter + FILTER_TUKEY, //< Tukey filter + FILTER_LANCZOS, //< Lanczos filter + FILTER_TRIANGULAR, //< Triangular filter + FILTER_GAUSSIAN, //< Gaussian filter + FILTER_BARTLETTHANN, //< Bartlett-Hann filter + FILTER_BLACKMAN, //< Blackman filter + FILTER_NUTTALL, //< Nuttall filter, continuous first derivative + FILTER_BLACKMANHARRIS, //< Blackman-Harris filter + FILTER_BLACKMANNUTTALL, //< Blackman-Nuttall filter + FILTER_FLATTOP, //< Flat top filter + FILTER_KAISER, //< Kaiser filter + FILTER_PARZEN, //< Parzen filter + FILTER_PROJECTION, //< all projection directions share one filter + FILTER_SINOGRAM, //< every projection direction has its own filter + FILTER_RPROJECTION, //< projection filter in real space (as opposed to fourier space) + FILTER_RSINOGRAM, //< sinogram filter in real space + +}; + +// Generate filter of given size and parameters. Returns newly allocated array. +float *genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, + int _iFFTRealDetectorCount, + int _iFFTFourierDetectorCount, float _fParameter = -1.0f); + +// Convert string to filter type. Returns FILTER_ERROR if unrecognized. +E_FBPFILTER convertStringToFilter(const char * _filterType); + +} + +#endif diff --git a/include/astra/cuda/2d/astra.h b/include/astra/cuda/2d/astra.h index 6f0e2f0..a2f2219 100644 --- a/include/astra/cuda/2d/astra.h +++ b/include/astra/cuda/2d/astra.h @@ -28,7 +28,6 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_ASTRA_H #define _CUDA_ASTRA_H -#include "fbp_filters.h" #include "dims.h" #include "algo.h" diff --git a/include/astra/cuda/2d/fbp.h b/include/astra/cuda/2d/fbp.h index 8666646..7febe69 100644 --- a/include/astra/cuda/2d/fbp.h +++ b/include/astra/cuda/2d/fbp.h @@ -26,7 +26,7 @@ along with the ASTRA Toolbox. If not, see . */ #include "algo.h" -#include "fbp_filters.h" +#include "astra/Filters.h" namespace astraCUDA { diff --git a/include/astra/cuda/2d/fbp_filters.h b/include/astra/cuda/2d/fbp_filters.h deleted file mode 100644 index 7c1121a..0000000 --- a/include/astra/cuda/2d/fbp_filters.h +++ /dev/null @@ -1,61 +0,0 @@ -/* ------------------------------------------------------------------------ -Copyright: 2010-2018, imec Vision Lab, University of Antwerp - 2014-2018, CWI, Amsterdam - -Contact: astra@astra-toolbox.com -Website: http://www.astra-toolbox.com/ - -This file is part of the ASTRA Toolbox. - - -The ASTRA Toolbox is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -The ASTRA Toolbox is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with the ASTRA Toolbox. If not, see . - ------------------------------------------------------------------------ -*/ - -#ifndef FBP_FILTERS_H -#define FBP_FILTERS_H - -namespace astra { - -enum E_FBPFILTER -{ - FILTER_NONE, //< no filter (regular BP) - FILTER_RAMLAK, //< default FBP filter - FILTER_SHEPPLOGAN, //< Shepp-Logan - FILTER_COSINE, //< Cosine - FILTER_HAMMING, //< Hamming filter - FILTER_HANN, //< Hann filter - FILTER_TUKEY, //< Tukey filter - FILTER_LANCZOS, //< Lanczos filter - FILTER_TRIANGULAR, //< Triangular filter - FILTER_GAUSSIAN, //< Gaussian filter - FILTER_BARTLETTHANN, //< Bartlett-Hann filter - FILTER_BLACKMAN, //< Blackman filter - FILTER_NUTTALL, //< Nuttall filter, continuous first derivative - FILTER_BLACKMANHARRIS, //< Blackman-Harris filter - FILTER_BLACKMANNUTTALL, //< Blackman-Nuttall filter - FILTER_FLATTOP, //< Flat top filter - FILTER_KAISER, //< Kaiser filter - FILTER_PARZEN, //< Parzen filter - FILTER_PROJECTION, //< all projection directions share one filter - FILTER_SINOGRAM, //< every projection direction has its own filter - FILTER_RPROJECTION, //< projection filter in real space (as opposed to fourier space) - FILTER_RSINOGRAM, //< sinogram filter in real space -}; - -} - -#endif /* FBP_FILTERS_H */ diff --git a/include/astra/cuda/2d/fft.h b/include/astra/cuda/2d/fft.h index d36cae2..f5f8477 100644 --- a/include/astra/cuda/2d/fft.h +++ b/include/astra/cuda/2d/fft.h @@ -31,7 +31,7 @@ along with the ASTRA Toolbox. If not, see . #include #include -#include "fbp_filters.h" +#include "astra/Filters.h" namespace astraCUDA { @@ -60,9 +60,9 @@ void applyFilter(int _iProjectionCount, int _iFreqBinCount, int calcFFTFourierSize(int _iFFTRealSize); -void genFilter(astra::E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, - cufftComplex * _pFilter, int _iFFTRealDetectorCount, - int _iFFTFourierDetectorCount, float _fParameter = -1.0f); +void genCuFFTFilter(astra::E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, + cufftComplex * _pFilter, int _iFFTRealDetectorCount, + int _iFFTFourierDetectorCount, float _fParameter = -1.0f); void genIdenFilter(int _iProjectionCount, cufftComplex * _pFilter, int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); -- cgit v1.2.3 From d32df3bcd1910f56195e828a0f7fba8fc04b90ab Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 12 Jul 2018 12:11:52 +0200 Subject: Refactor filter config --- include/astra/CudaFilteredBackProjectionAlgorithm.h | 6 +----- include/astra/Filters.h | 21 +++++++++++++++++++-- include/astra/cuda/2d/fbp.h | 4 +--- include/astra/cuda/2d/fft.h | 4 ++-- 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/astra/CudaFilteredBackProjectionAlgorithm.h b/include/astra/CudaFilteredBackProjectionAlgorithm.h index 974914a..8ef5a57 100644 --- a/include/astra/CudaFilteredBackProjectionAlgorithm.h +++ b/include/astra/CudaFilteredBackProjectionAlgorithm.h @@ -46,11 +46,7 @@ public: static std::string type; private: - E_FBPFILTER m_eFilter; - float * m_pfFilter; - int m_iFilterWidth; // number of elements per projection direction in filter - float m_fFilterParameter; // some filters allow for parameterization (value < 0.0f -> no parameter) - float m_fFilterD; // frequency cut-off + SFilterConfig m_filterConfig; bool m_bShortScan; // short-scan mode for fan beam public: diff --git a/include/astra/Filters.h b/include/astra/Filters.h index ff3f5c8..eec2ba2 100644 --- a/include/astra/Filters.h +++ b/include/astra/Filters.h @@ -30,6 +30,9 @@ along with the ASTRA Toolbox. If not, see . namespace astra { +struct Config; +class CAlgorithm; + enum E_FBPFILTER { FILTER_ERROR, //< not a valid filter @@ -58,14 +61,28 @@ enum E_FBPFILTER }; +struct SFilterConfig { + E_FBPFILTER m_eType; + float m_fD; + float m_fParameter; + + float *m_pfCustomFilter; + int m_iCustomFilterWidth; + + SFilterConfig() : m_eType(FILTER_ERROR), m_fD(1.0f), m_fParameter(-1.0f), + m_pfCustomFilter(0), m_iCustomFilterWidth(0) { }; +}; + // Generate filter of given size and parameters. Returns newly allocated array. -float *genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, +float *genFilter(const SFilterConfig &_cfg, int _iProjectionCount, int _iFFTRealDetectorCount, - int _iFFTFourierDetectorCount, float _fParameter = -1.0f); + int _iFFTFourierDetectorCount); // Convert string to filter type. Returns FILTER_ERROR if unrecognized. E_FBPFILTER convertStringToFilter(const char * _filterType); +SFilterConfig getFilterConfigForAlgorithm(const Config& _cfg, CAlgorithm *_alg); + } #endif diff --git a/include/astra/cuda/2d/fbp.h b/include/astra/cuda/2d/fbp.h index 7febe69..1adf3b1 100644 --- a/include/astra/cuda/2d/fbp.h +++ b/include/astra/cuda/2d/fbp.h @@ -75,9 +75,7 @@ public: // FILTER_COSINE, FILTER_HAMMING, and FILTER_HANN) // have a D variable, which gives the cutoff point in the frequency domain. // Setting this value to 1.0 will include the whole filter - bool setFilter(astra::E_FBPFILTER _eFilter, - const float * _pfHostFilter = NULL, - int _iFilterWidth = 0, float _fD = 1.0f, float _fFilterParameter = -1.0f); + bool setFilter(const astra::SFilterConfig &_cfg); bool setShortScan(bool ss) { m_bShortScan = ss; return true; } diff --git a/include/astra/cuda/2d/fft.h b/include/astra/cuda/2d/fft.h index f5f8477..33612a0 100644 --- a/include/astra/cuda/2d/fft.h +++ b/include/astra/cuda/2d/fft.h @@ -60,9 +60,9 @@ void applyFilter(int _iProjectionCount, int _iFreqBinCount, int calcFFTFourierSize(int _iFFTRealSize); -void genCuFFTFilter(astra::E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, +void genCuFFTFilter(const astra::SFilterConfig &_cfg, int _iProjectionCount, cufftComplex * _pFilter, int _iFFTRealDetectorCount, - int _iFFTFourierDetectorCount, float _fParameter = -1.0f); + int _iFFTFourierDetectorCount); void genIdenFilter(int _iProjectionCount, cufftComplex * _pFilter, int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); -- cgit v1.2.3 From da434892133fe0979c5e8ef8be277673452e7728 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 13 Jul 2018 14:48:19 +0200 Subject: Add filter size error reporting --- include/astra/Filters.h | 10 +++++++++- include/astra/cuda/2d/fft.h | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/astra/Filters.h b/include/astra/Filters.h index eec2ba2..bf0fb48 100644 --- a/include/astra/Filters.h +++ b/include/astra/Filters.h @@ -32,6 +32,7 @@ namespace astra { struct Config; class CAlgorithm; +class CProjectionGeometry2D; enum E_FBPFILTER { @@ -68,9 +69,11 @@ struct SFilterConfig { float *m_pfCustomFilter; int m_iCustomFilterWidth; + int m_iCustomFilterHeight; SFilterConfig() : m_eType(FILTER_ERROR), m_fD(1.0f), m_fParameter(-1.0f), - m_pfCustomFilter(0), m_iCustomFilterWidth(0) { }; + m_pfCustomFilter(0), m_iCustomFilterWidth(0), + m_iCustomFilterHeight(0) { }; }; // Generate filter of given size and parameters. Returns newly allocated array. @@ -83,6 +86,11 @@ E_FBPFILTER convertStringToFilter(const char * _filterType); SFilterConfig getFilterConfigForAlgorithm(const Config& _cfg, CAlgorithm *_alg); +bool checkCustomFilterSize(const SFilterConfig &_cfg, const CProjectionGeometry2D &_geom); + +int calcFFTFourierSize(int _iFFTRealSize); + + } #endif diff --git a/include/astra/cuda/2d/fft.h b/include/astra/cuda/2d/fft.h index 33612a0..f77cbde 100644 --- a/include/astra/cuda/2d/fft.h +++ b/include/astra/cuda/2d/fft.h @@ -58,8 +58,6 @@ bool runCudaIFFT(int _iProjectionCount, const cufftComplex* _pDevSourceComplex, void applyFilter(int _iProjectionCount, int _iFreqBinCount, cufftComplex * _pSinogram, cufftComplex * _pFilter); -int calcFFTFourierSize(int _iFFTRealSize); - void genCuFFTFilter(const astra::SFilterConfig &_cfg, int _iProjectionCount, cufftComplex * _pFilter, int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); -- cgit v1.2.3 From bc65a0395e6c3930bac0440cc894990dd04cb704 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 13 Jul 2018 16:20:07 +0200 Subject: Reorganize more filter size functions --- include/astra/Filters.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/astra/Filters.h b/include/astra/Filters.h index bf0fb48..a1dec97 100644 --- a/include/astra/Filters.h +++ b/include/astra/Filters.h @@ -77,7 +77,7 @@ struct SFilterConfig { }; // Generate filter of given size and parameters. Returns newly allocated array. -float *genFilter(const SFilterConfig &_cfg, int _iProjectionCount, +float *genFilter(const SFilterConfig &_cfg, int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); @@ -88,6 +88,8 @@ SFilterConfig getFilterConfigForAlgorithm(const Config& _cfg, CAlgorithm *_alg); bool checkCustomFilterSize(const SFilterConfig &_cfg, const CProjectionGeometry2D &_geom); + +int calcNextPowerOfTwo(int _iValue); int calcFFTFourierSize(int _iFFTRealSize); -- cgit v1.2.3 From fa83c8a76fa19862de5c68914a5ef81397ae89a2 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 13 Jul 2018 16:21:01 +0200 Subject: Move CPU FBP to common filter code --- include/astra/FilteredBackProjectionAlgorithm.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/astra/FilteredBackProjectionAlgorithm.h b/include/astra/FilteredBackProjectionAlgorithm.h index 1cd4296..a234845 100644 --- a/include/astra/FilteredBackProjectionAlgorithm.h +++ b/include/astra/FilteredBackProjectionAlgorithm.h @@ -35,6 +35,7 @@ along with the ASTRA Toolbox. If not, see . #include "Projector2D.h" #include "Float32ProjectionData2D.h" #include "Float32VolumeData2D.h" +#include "Filters.h" namespace astra { @@ -144,6 +145,10 @@ public: */ virtual std::string description() const; +protected: + + SFilterConfig m_filterConfig; + }; // inline functions -- cgit v1.2.3