|
21 | 21 | #include "itkRunLengthTextureFeaturesImageFilter.h" |
22 | 22 | #include "itkRegionOfInterestImageFilter.h" |
23 | 23 | #include "itkNeighborhoodAlgorithm.h" |
| 24 | +#include "itkBinaryFunctorImageFilter.h" |
| 25 | +#include "itkDigitizerFunctor.h" |
24 | 26 |
|
25 | 27 | namespace itk |
26 | 28 | { |
|
84 | 86 | RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage> |
85 | 87 | ::BeforeThreadedGenerateData() |
86 | 88 | { |
87 | | - typename TInputImage::Pointer maskPointer = TInputImage::New(); |
88 | | - maskPointer = const_cast<TInputImage *>(this->GetMaskImage()); |
89 | | - this->m_DigitizedInputImage = InputImageType::New(); |
90 | | - this->m_DigitizedInputImage->SetRegions(this->GetInput()->GetRequestedRegion()); |
91 | | - this->m_DigitizedInputImage->CopyInformation(this->GetInput()); |
92 | | - this->m_DigitizedInputImage->Allocate(); |
93 | | - typedef itk::ImageRegionIterator< InputImageType> IteratorType; |
94 | | - IteratorType digitIt( this->m_DigitizedInputImage, this->m_DigitizedInputImage->GetLargestPossibleRegion() ); |
95 | | - typedef itk::ImageRegionConstIterator< InputImageType> ConstIteratorType; |
96 | | - ConstIteratorType inputIt( this->GetInput(), this->GetInput()->GetLargestPossibleRegion() ); |
97 | | - unsigned int binNumber; |
98 | | - while( !inputIt.IsAtEnd() ) |
| 89 | + |
| 90 | + typename TInputImage::Pointer input = InputImageType::New(); |
| 91 | + input->Graft(const_cast<TInputImage *>(this->GetInput())); |
| 92 | + |
| 93 | + typedef Digitizer<PixelType, |
| 94 | + PixelType, |
| 95 | + typename DigitizedImageType::PixelType> |
| 96 | + DigitizerFunctorType; |
| 97 | + |
| 98 | + DigitizerFunctorType digitalizer(m_NumberOfBinsPerAxis, m_InsidePixelValue, m_HistogramValueMinimum, m_HistogramValueMaximum); |
| 99 | + |
| 100 | + typedef BinaryFunctorImageFilter< MaskImageType, InputImageType, InputImageType, DigitizerFunctorType> FilterType; |
| 101 | + typename FilterType::Pointer filter = FilterType::New(); |
| 102 | + if (this->GetMaskImage() != ITK_NULLPTR) |
99 | 103 | { |
100 | | - if( maskPointer && maskPointer->GetPixel( inputIt.GetIndex() ) != this->m_InsidePixelValue ) |
101 | | - { |
102 | | - digitIt.Set(-10); |
103 | | - } |
104 | | - else if(inputIt.Get() < this->m_HistogramValueMinimum || inputIt.Get() >= this->m_HistogramValueMinimum) |
105 | | - { |
106 | | - digitIt.Set(-1); |
107 | | - } |
108 | | - else |
109 | | - { |
110 | | - binNumber = ( inputIt.Get() - m_HistogramValueMinimum)/( (m_HistogramValueMaximum - m_HistogramValueMinimum) / (float)m_NumberOfBinsPerAxis ); |
111 | | - digitIt.Set(binNumber); |
112 | | - } |
113 | | - ++inputIt; |
114 | | - ++digitIt; |
| 104 | + typename TInputImage::Pointer mask = MaskImageType::New(); |
| 105 | + mask->Graft(const_cast<TInputImage *>(this->GetMaskImage())); |
| 106 | + filter->SetInput1(mask); |
115 | 107 | } |
116 | | - m_Spacing = this->GetInput()->GetSpacing(); |
| 108 | + else |
| 109 | + { |
| 110 | + filter->SetConstant1(m_InsidePixelValue); |
| 111 | + } |
| 112 | + filter->SetInput2(input); |
| 113 | + filter->SetFunctor(digitalizer); |
| 114 | + filter->SetNumberOfThreads(this->GetNumberOfThreads()); |
117 | 115 |
|
118 | | - // Support VectorImages by setting the number of components on the output. |
119 | | - typename TOutputImage::Pointer outputPtr = TOutputImage::New(); |
120 | | - outputPtr = this->GetOutput(); |
121 | | - if ( strcmp(outputPtr->GetNameOfClass(), "VectorImage") == 0 ) |
122 | | - { |
123 | | - typedef typename TOutputImage::AccessorFunctorType AccessorFunctorType; |
124 | | - AccessorFunctorType::SetVectorLength( outputPtr, 10 ); |
125 | | - } |
126 | | - outputPtr->Allocate(); |
| 116 | + filter->Update(); |
| 117 | + m_DigitizedInputImage = filter->GetOutput(); |
| 118 | + |
| 119 | + m_Spacing = this->GetInput()->GetSpacing(); |
127 | 120 | } |
128 | 121 |
|
129 | 122 |
|
|
0 commit comments