4 #include <itkObjectFactory.h> 5 #include <itkImageLinearIteratorWithIndex.h> 6 #include <itkImageLinearConstIteratorWithIndex.h> 7 #include <itkProgressReporter.h> 14 template <
typename TInputImage,
typename TOutputImage>
19 this->SetNumberOfRequiredOutputs( 1 );
20 this->SetNumberOfRequiredInputs( 1 );
28 template <
typename TInputImage,
typename TOutputImage>
34 itk::ProcessObject::SetNthInput(0, const_cast< TInputImage * >(input) );
41 template <
typename TInputImage,
typename TOutputImage>
46 return dynamic_cast<const TInputImage *
>((itk::ProcessObject::GetInput(0)));
52 template <
typename TInputImage,
typename TOutputImage>
62 q = 0.9804 * (sigmad - 3.556) + 2.5091;
66 std::cerr <<
"Too low sigma value (< 0.5), computation will not be precise." << std::endl;
68 q = 0.0561 * sigmad * sigmad + 0.5784 * sigmad - 0.2568;
75 ScalarRealType scale = (m0 + q) * (m1 * m1 + m2 * m2 + 2 * m1 * q + q * q);
77 m_B1 = q * (2 * m0 * m1 + m1 * m1 + m2 * m2 + (2 * m0 + 4 * m1) * q + 3 * q * q) / scale;
79 m_B2 = - q * q * (m0 + 2 * m1 + 3 * q) / scale;
81 m_B3 = q * q * q / scale;
87 m_MMatrix = vnl_matrix <ScalarRealType> (3,3);
89 m_MMatrix(0,0) = - m_B3 * m_B1 + 1 - m_B3 * m_B3 - m_B2;
90 m_MMatrix(0,1) = (m_B3 + m_B1) * (m_B2 + m_B3 * m_B1);
91 m_MMatrix(0,2) = m_B3 * (m_B1 + m_B3 * m_B2);
93 m_MMatrix(1,0) = m_B1 + m_B3 * m_B2;
94 m_MMatrix(1,1) = (1 - m_B2) * (m_B2 + m_B3 * m_B1);
95 m_MMatrix(1,2) = - m_B3 * (m_B3 * m_B1 + m_B3 * m_B3 + m_B2 - 1);
97 m_MMatrix(2,0) = m_B3 * m_B1 + m_B2 + m_B1 * m_B1 - m_B2 * m_B2;
98 m_MMatrix(2,1) = m_B1 * m_B2 + m_B3 * m_B2 * m_B2 - m_B1 * m_B3 * m_B3 - m_B3 * m_B3 * m_B3 - m_B3 * m_B2 + m_B3;
99 m_MMatrix(2,2) = m_B3 * (m_B1 + m_B3 * m_B2);
101 m_MMatrix /= (1 + m_B1 - m_B2 + m_B3) * (1 - m_B1 - m_B2 - m_B3) * (1 + m_B2 + (m_B1 - m_B3) * m_B3);
107 template <
typename TInputImage,
typename TOutputImage>
118 this->ComputeCausalBase(data[0],sV0,sV1,sV2);
123 for(
unsigned int i=0; i<ln; i++ )
124 this->ComputeCausalPart(outs[i],data[i],sV0,sV1,sV2);
129 this->ComputeAntiCausalBase(data[ln-1],outs,sV0,sV1,sV2,ln);
135 for (
int i=ln-2; i >= 0; i--)
136 this->ComputeAntiCausalPart(outs[i],outs[i],sV0,sV1,sV2);
143 template <
typename TInputImage,
typename TOutputImage>
148 TOutputImage *out =
dynamic_cast<TOutputImage*
>(output);
156 if ( this->m_Direction >= outputRegion.GetImageDimension() )
158 itkExceptionMacro(
"Direction selected for filtering is greater than ImageDimension")
162 outputRegion.SetIndex( m_Direction, largestOutputRegion.GetIndex(m_Direction) );
163 outputRegion.SetSize( m_Direction, largestOutputRegion.GetSize(m_Direction) );
165 out->SetRequestedRegion( outputRegion );
169 template <
typename TInputImage,
typename TOutputImage>
174 typedef itk::ImageRegion< TInputImage::ImageDimension > RegionType;
176 typename TInputImage::ConstPointer inputImage( this->GetInputImage () );
177 typename TOutputImage::Pointer outputImage( this->GetOutput() );
179 const unsigned int imageDimension = inputImage->GetImageDimension();
181 if( this->m_Direction >= imageDimension )
183 itkExceptionMacro(
"Direction selected for filtering is greater than ImageDimension");
186 const typename InputImageType::SpacingType & pixelSize = inputImage->GetSpacing();
187 this->SetUp(pixelSize[m_Direction]);
189 RegionType region = outputImage->GetRequestedRegion();
191 const unsigned int ln = region.GetSize()[ this->m_Direction ];
195 itkExceptionMacro(
"The number of pixels along direction " << this->m_Direction <<
" is less than 4. This filter requires a minimum of four pixels along the dimension to be processed.");
199 template <
typename TInputImage,
typename TOutputImage>
204 this->AllocateOutputs();
205 this->BeforeThreadedGenerateData();
207 using RegionType = itk::ImageRegion <TInputImage::ImageDimension>;
208 typename TOutputImage::Pointer outputImage(this->GetOutput());
209 const RegionType region = outputImage->GetRequestedRegion();
211 this->GetMultiThreader()->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
212 this->GetMultiThreader()->template ParallelizeImageRegionRestrictDirection<TOutputImage::ImageDimension>(
213 this->m_Direction, region, [
this](
const RegionType & lambdaRegion) { this->DynamicThreadedGenerateData(lambdaRegion); },
this);
220 template <
typename TInputImage,
typename TOutputImage>
225 typedef typename TOutputImage::PixelType OutputPixelType;
227 typedef itk::ImageLinearConstIteratorWithIndex< TInputImage > InputConstIteratorType;
228 typedef itk::ImageLinearIteratorWithIndex< TOutputImage > OutputIteratorType;
230 typedef itk::ImageRegion< TInputImage::ImageDimension > RegionType;
232 typename TInputImage::ConstPointer inputImage( this->GetInputImage () );
233 typename TOutputImage::Pointer outputImage( this->GetOutput() );
235 RegionType region = outputRegionForThread;
237 InputConstIteratorType inputIterator( inputImage, region );
238 OutputIteratorType outputIterator( outputImage, region );
240 inputIterator.SetDirection( this->m_Direction );
241 outputIterator.SetDirection( this->m_Direction );
244 const unsigned int ln = region.GetSize()[ this->m_Direction ];
248 RealType workData0, workData1, workData2;
255 inputIterator.GoToBegin();
256 outputIterator.GoToBegin();
258 while( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
261 while( !inputIterator.IsAtEndOfLine() )
263 inps[i++] = inputIterator.Get();
267 this->FilterDataArray( outs, inps, ln, workData0, workData1, workData2 );
270 while( !outputIterator.IsAtEndOfLine() )
272 outputIterator.Set( static_cast<OutputPixelType>( outs[j++] ) );
276 inputIterator.NextLine();
277 outputIterator.NextLine();
280 catch( itk::ProcessAborted & )
299 template <
typename TInputImage,
typename TOutputImage>
304 Superclass::PrintSelf(os,indent);
306 os << indent <<
"Direction: " << m_Direction << std::endl;
void EnlargeOutputRequestedRegion(itk::DataObject *output) ITK_OVERRIDE
const TInputImage * GetInputImage(void)
itk::NumericTraits< InputPixelType >::ScalarRealType ScalarRealType
void GenerateData() ITK_OVERRIDE
itk::NumericTraits< InputPixelType >::RealType RealType
RecursiveLineYvvGaussianImageFilter()
void FilterDataArray(RealType *outs, const RealType *data, unsigned int ln, RealType &sV0, RealType &sV1, RealType &sV2)
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void SetInputImage(const TInputImage *)
TOutputImage::RegionType OutputImageRegionType
void BeforeThreadedGenerateData() ITK_OVERRIDE
virtual void SetUp(ScalarRealType spacing)
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE