Skip to content

Commit 0d94ab5

Browse files
committed
ENH: Use BinaryFunctor for "digitializing" input image
Use a threaded filter to perform digitizing and masking of the input image into histograms bins. Reuse the Digitizer functor.
1 parent 74af5b5 commit 0d94ab5

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

include/itkRunLengthTextureFeaturesImageFilter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter:public ImageToImag
113113

114114
typedef TInputImage InputImageType;
115115
typedef TOutputImage OutputImageType;
116+
typedef TInputImage MaskImageType;
117+
typedef TInputImage DigitizedImageType;
116118

117119
typedef typename InputImageType::PixelType PixelType;
118120
typedef typename InputImageType::IndexType IndexType;

include/itkRunLengthTextureFeaturesImageFilter.hxx

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "itkRunLengthTextureFeaturesImageFilter.h"
2222
#include "itkRegionOfInterestImageFilter.h"
2323
#include "itkNeighborhoodAlgorithm.h"
24+
#include "itkBinaryFunctorImageFilter.h"
25+
#include "itkDigitizerFunctor.h"
2426

2527
namespace itk
2628
{
@@ -84,46 +86,37 @@ void
8486
RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
8587
::BeforeThreadedGenerateData()
8688
{
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)
99103
{
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);
115107
}
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());
117115

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();
127120
}
128121

129122

0 commit comments

Comments
 (0)