11 #ifndef __itkScalarMapFromSPFImageFilter_hxx 12 #define __itkScalarMapFromSPFImageFilter_hxx 14 #include <itkProgressReporter.h> 23 template<
class TInputImage,
class TOutputImage >
28 Superclass::GenerateOutputInformation();
29 typename TInputImage::ConstPointer inputPtr = this->GetInput();
30 typename TOutputImage::Pointer outputPtr = this->GetOutput();
34 template<
class TInputImage,
class TOutputImage >
35 typename LightObject::Pointer
39 typename LightObject::Pointer loPtr = Superclass::InternalClone();
44 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
46 rval->m_SumWeight = m_SumWeight;
47 rval->m_MapType = m_MapType;
51 template<
class TInputImage,
class TOutputImage >
57 m_SumWeight.ReSize(this->m_RadialRank+1);
60 for (
int i = 0; i <= this->m_RadialRank ; ++i )
65 m_SumWeight %= 4*std::sqrt(
M_PI);
67 else if (m_MapType==MSD)
69 for (
int n = 0; n <= this->m_RadialRank; ++n )
78 else if (m_MapType==PFA)
83 Superclass::BeforeThreadedGenerateData();
86 template <
class TInputImage,
class TOutputImage>
92 typename TInputImage::ConstPointer inputPtr = this->GetInput();
93 typename TOutputImage::Pointer outputPtr = this->GetOutput();
96 ImageRegionConstIteratorWithIndex<TInputImage> inputIt(inputPtr, outputRegionForThread);
97 ImageRegionIteratorWithIndex<TOutputImage> outputIt(outputPtr, outputRegionForThread);
98 ImageRegionIteratorWithIndex<MaskImageType> maskIt;
99 if (this->IsMaskUsed())
100 maskIt = ImageRegionIteratorWithIndex<MaskImageType>(this->m_MaskImage, outputRegionForThread);
102 ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
103 typename TInputImage::PixelType inputPixel;
104 typename TInputImage::IndexType inputIndex;
105 typename TOutputImage::PixelType outputPixel;
106 ScalarImagePointer scaleImage = this->GetScaleImage();
108 unsigned int inputDim = inputPtr->GetNumberOfComponentsPerPixel();
109 inputPixel.SetSize(inputDim);
112 outputIt.GoToBegin();
114 double scale = this->m_BasisScale;
117 while( !inputIt.IsAtEnd() )
119 if (!this->IsMaskUsed() || (this->IsMaskUsed() && maskIt.Get()>0))
121 inputPixel = inputIt.Get();
122 if (inputPixel.GetSquaredNorm()>1e-8)
124 inputIndex = inputIt.GetIndex();
125 if (this->GetDebug())
126 std::cout <<
"index = " << inputIndex << std::endl << std::flush;
129 scale = scaleImage->GetPixel(inputIndex);
134 for (
int i = 0; i <= this->m_RadialRank; ++i )
135 outputPixel += inputPixel[i*dimSH]*m_SumWeight[i];
136 outputPixel *= std::pow(scale, 0.75);
138 else if (m_MapType==MSD)
141 for (
int n = 0; n <= this->m_RadialRank; n += 1 )
144 scaleWeight[n] = std::sqrt(scaleWeight[n])/scale;
147 for (
int i = 0; i <= this->m_RadialRank; ++i )
148 outputPixel += inputPixel[i*dimSH]*m_SumWeight[i]*scaleWeight[i];
150 else if (m_MapType==PFA)
153 for (
int i = 0; i <= this->m_RadialRank; ++i )
154 sum += inputPixel[i*dimSH]*inputPixel[i*dimSH];
155 outputPixel = std::sqrt(1- sum/inputPixel.GetSquaredNorm() );
165 outputIt.Set(outputPixel);
166 progress.CompletedPixel();
167 if (this->IsMaskUsed())
171 progress.CompletedPixel();
175 template<
class TInputImage,
class TOutputImage >
180 Superclass::PrintSelf(os, indent);
NDArray is a N-Dimensional array class (row-major, c version)
helper functions specifically used in dmritool
bool IsImageEmpty(const SmartPointer< ImageType > &image)
bool IsEven(const int value)
void GenerateOutputInformation() ITK_OVERRIDE
unsigned long Factorial(const int n)
void CopyImageInformation(const SmartPointer< ImageWithInfoType > &imageFrom, SmartPointer< ImageType > &imageTo)
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
T Lagurre(const int n, const double a, const T x)
LightObject::Pointer InternalClone() const ITK_OVERRIDE
int RankToDimSH(const int shRank)
double GammaHalfInteger(const double x)
void BeforeThreadedGenerateData() ITK_OVERRIDE
void ThreadedGenerateData(const typename TOutputImage::RegionType &outputRegionForThread, ThreadIdType threadId) ITK_OVERRIDE
void PrintUtlVector(const NDArray< T, 1 > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
int sign(const T &x)
Return the sign of x.
Compute some features (DWI/EAP profile, ODFs, scalar indices) from SPF coefficients.
SmartPointer< Self > Pointer
double Gamma(const double x)
gamma function.