Skip to content

Commit 9eaa9a5

Browse files
authored
Merge pull request #48 from jbvimort/AllowingFloat
Allowing the usage of input image of type float
2 parents 4813277 + b9e7332 commit 9eaa9a5

16 files changed

+85
-56
lines changed

example/computeGLCMFeatures.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@
66
"<PixelValueMax> <NeighborhoodRadius>")
77
sys.exit(1)
88

9-
im = itk.imread(sys.argv[1])
10-
mask = itk.imread(sys.argv[2])
9+
10+
Dimension = 3
11+
12+
#Input scan reader
13+
InputPixelType = itk.ctype('signed short')
14+
InputImageType = itk.Image[InputPixelType, Dimension]
15+
imReader = itk.ImageFileReader[InputImageType].New()
16+
imReader.SetFileName(sys.argv[1])
17+
18+
#Input mask reader
19+
MaskPixelType = itk.ctype('unsigned char')
20+
MaskImageType = itk.Image[MaskPixelType, Dimension]
21+
maskReader = itk.ImageFileReader[MaskImageType].New()
22+
maskReader.SetFileName(sys.argv[2])
23+
24+
im = imReader.GetOutput()
25+
mask = maskReader.GetOutput()
1126

1227
filtr = itk.CoocurrenceTextureFeaturesImageFilter.New(im)
1328
filtr.SetMaskImage(mask)

example/computeGLRLMFeatures.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,29 @@
77
"<DistanceValueMax> <NeighborhoodRadius>")
88
sys.exit(1)
99

10-
im = itk.imread(sys.argv[1])
11-
mask = itk.imread(sys.argv[2])
10+
11+
Dimension = 3
12+
13+
#Input scan reader
14+
InputPixelType = itk.ctype('signed short')
15+
InputImageType = itk.Image[InputPixelType, Dimension]
16+
imReader = itk.ImageFileReader[InputImageType].New()
17+
imReader.SetFileName(sys.argv[1])
18+
19+
#Input mask reader
20+
MaskPixelType = itk.ctype('unsigned char')
21+
MaskImageType = itk.Image[MaskPixelType, Dimension]
22+
maskReader = itk.ImageFileReader[MaskImageType].New()
23+
maskReader.SetFileName(sys.argv[2])
24+
25+
im = imReader.GetOutput()
26+
mask = maskReader.GetOutput()
1227

1328
filtr = itk.RunLengthTextureFeaturesImageFilter.New(im)
1429
filtr.SetMaskImage(mask)
1530
filtr.SetNumberOfBinsPerAxis(int(sys.argv[3]))
16-
filtr.SetSetHistogramValueMinimum(int(sys.argv[4]))
17-
filtr.SetSetHistogramValueMaximum( int(sys.argv[5]))
31+
filtr.SetHistogramValueMinimum(int(sys.argv[4]))
32+
filtr.SetHistogramValueMaximum( int(sys.argv[5]))
1833
filtr.SetHistogramDistanceMinimum(float(sys.argv[6]))
1934
filtr.SetHistogramDistanceMaximum(float(sys.argv[7]))
2035
filtr.SetNeighborhoodRadius([int(sys.argv[8]),int(sys.argv[8]),int(sys.argv[8])])

include/itkCoocurrenceTextureFeaturesImageFilter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class ITK_TEMPLATE_EXPORT CoocurrenceTextureFeaturesImageFilter
103103
typedef TInputImage InputImageType;
104104
typedef TOutputImage OutputImageType;
105105
typedef TMaskImage MaskImageType;
106-
typedef TInputImage DigitizedImageType;
107106

108107
typedef typename InputImageType::PixelType PixelType;
109108
typedef typename MaskImageType::PixelType MaskPixelType;
@@ -118,9 +117,7 @@ class ITK_TEMPLATE_EXPORT CoocurrenceTextureFeaturesImageFilter
118117
typedef typename InputImageType::RegionType InputRegionType;
119118
typedef typename OutputImageType::RegionType OutputRegionType;
120119

121-
typedef typename itk::ConstNeighborhoodIterator< InputImageType > NeighborhoodIteratorType;
122-
typedef typename NeighborhoodIteratorType::RadiusType NeighborhoodRadiusType;
123-
typedef typename NeighborhoodIteratorType::NeighborIndexType NeighborIndexType;
120+
typedef typename itk::ConstNeighborhoodIterator< InputImageType >::RadiusType NeighborhoodRadiusType;
124121

125122
typedef typename NumericTraits<PixelType>::RealType MeasurementType;
126123
typedef typename NumericTraits<PixelType>::RealType RealType;
@@ -198,15 +195,18 @@ class ITK_TEMPLATE_EXPORT CoocurrenceTextureFeaturesImageFilter
198195

199196
#ifdef ITK_USE_CONCEPT_CHECKING
200197
// Begin concept checking
201-
itkConceptMacro( InputPixelTypeCheck,
202-
( Concept::IsInteger< typename InputImageType::PixelType>) );
203198
itkConceptMacro( OutputPixelTypeCheck,
204199
( Concept::IsFloatingPoint< OutputRealType > ) );
205200
// End concept checking
206201
#endif
207202

208203
protected:
209204

205+
typedef int HistogramIndexType;
206+
typedef itk::Image< HistogramIndexType, TInputImage::ImageDimension > DigitizedImageType;
207+
typedef typename itk::ConstNeighborhoodIterator< DigitizedImageType > NeighborhoodIteratorType;
208+
typedef typename NeighborhoodIteratorType::NeighborIndexType NeighborIndexType;
209+
210210
CoocurrenceTextureFeaturesImageFilter();
211211
virtual ~CoocurrenceTextureFeaturesImageFilter() {}
212212

include/itkCoocurrenceTextureFeaturesImageFilter.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
9696

9797
DigitizerFunctorType digitalizer(m_NumberOfBinsPerAxis, m_InsidePixelValue, m_HistogramMinimum, m_HistogramMaximum);
9898

99-
typedef BinaryFunctorImageFilter< MaskImageType, InputImageType, InputImageType, DigitizerFunctorType> FilterType;
99+
typedef BinaryFunctorImageFilter< MaskImageType, InputImageType, DigitizedImageType, DigitizerFunctorType> FilterType;
100100
typename FilterType::Pointer filter = FilterType::New();
101101
if (this->GetMaskImage() != ITK_NULLPTR)
102102
{
@@ -143,10 +143,10 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
143143
typename TOutputImage::PixelType outputPixel;
144144

145145
// Separation of the non-boundary region that will be processed in a different way
146-
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TInputImage > boundaryFacesCalculator;
147-
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< InputImageType >::FaceListType
146+
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< DigitizedImageType > boundaryFacesCalculator;
147+
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< DigitizedImageType >::FaceListType
148148
faceList = boundaryFacesCalculator( this->m_DigitizedInputImage, outputRegionForThread, m_NeighborhoodRadius );
149-
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< InputImageType >::FaceListType::iterator fit = faceList.begin();
149+
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< DigitizedImageType>::FaceListType::iterator fit = faceList.begin();
150150

151151
// Declaration of the variables useful to iterate over the all image region
152152
bool isInImage;
@@ -166,10 +166,10 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
166166
vnl_matrix<unsigned int> hist(m_NumberOfBinsPerAxis, m_NumberOfBinsPerAxis);
167167

168168
// Declaration of the variables useful to iterate over the all neighborhood region
169-
PixelType currentInNeighborhoodPixelIntensity;
169+
HistogramIndexType currentInNeighborhoodPixelIntensity;
170170

171171
// Declaration of the variables useful to iterate over the run
172-
PixelType pixelIntensity( NumericTraits<PixelType>::ZeroValue() );
172+
HistogramIndexType pixelIntensity( NumericTraits<HistogramIndexType>::ZeroValue() );
173173
OffsetType tempOffset;
174174

175175
/// ***** Non-boundary Region *****

include/itkDigitizerFunctor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Digitizer
7676
}
7777
else
7878
{
79-
return ((inputPixel - m_Min)/((m_Max-m_Min)/ (float)m_NumberOfBinsPerAxis));
79+
return Math::Floor< TOutput >((inputPixel - m_Min)/((m_Max-m_Min)/ (float)m_NumberOfBinsPerAxis));
8080
}
8181
}
8282

include/itkRunLengthTextureFeaturesImageFilter.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter
116116
typedef TInputImage InputImageType;
117117
typedef TOutputImage OutputImageType;
118118
typedef TMaskImage MaskImageType;
119-
typedef TInputImage DigitizedImageType;
120119

121120
typedef typename InputImageType::PixelType PixelType;
122121
typedef typename MaskImageType::PixelType MaskPixelType;
@@ -131,9 +130,7 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter
131130
typedef typename InputImageType::RegionType InputRegionType;
132131
typedef typename OutputImageType::RegionType OutputRegionType;
133132

134-
typedef typename itk::ConstNeighborhoodIterator< InputImageType > NeighborhoodIteratorType;
135-
typedef typename NeighborhoodIteratorType::RadiusType NeighborhoodRadiusType;
136-
typedef typename NeighborhoodIteratorType::NeighborIndexType NeighborIndexType;
133+
typedef typename itk::ConstNeighborhoodIterator< InputImageType >::RadiusType NeighborhoodRadiusType;
137134

138135
typedef typename NumericTraits<PixelType>::RealType MeasurementType;
139136
typedef typename NumericTraits<PixelType>::RealType RealType;
@@ -222,22 +219,25 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter
222219

223220
#ifdef ITK_USE_CONCEPT_CHECKING
224221
// Begin concept checking
225-
itkConceptMacro( InputPixelTypeCheck,
226-
( Concept::IsInteger< typename InputImageType::PixelType>) );
227222
itkConceptMacro( OutputPixelTypeCheck,
228223
( Concept::IsFloatingPoint< OutputRealType > ) );
229224
// End concept checking
230225
#endif
231226

232227
protected:
233228

229+
typedef int HistogramIndexType;
230+
typedef itk::Image< HistogramIndexType, TInputImage::ImageDimension > DigitizedImageType;
231+
typedef typename itk::ConstNeighborhoodIterator< DigitizedImageType > NeighborhoodIteratorType;
232+
typedef typename NeighborhoodIteratorType::NeighborIndexType NeighborIndexType;
233+
234234
RunLengthTextureFeaturesImageFilter();
235235
virtual ~RunLengthTextureFeaturesImageFilter() {}
236236

237237
void NormalizeOffsetDirection(OffsetType &offset);
238238
bool IsInsideNeighborhood(const OffsetType &iteratedOffset);
239239
void IncreaseHistogram(vnl_matrix<unsigned int> &hist, unsigned int &totalNumberOfRuns,
240-
const PixelType &currentInNeighborhoodPixelIntensity,
240+
const HistogramIndexType &currentInNeighborhoodPixelIntensity,
241241
const OffsetType &offset, const unsigned int &pixelDistance);
242242
void ComputeFeatures( vnl_matrix<unsigned int> &hist, const unsigned int &totalNumberOfRuns,
243243
typename TOutputImage::PixelType &outputPixel);
@@ -251,16 +251,16 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter
251251
virtual void GenerateOutputInformation() ITK_OVERRIDE;
252252

253253
private:
254-
typename InputImageType::Pointer m_DigitizedInputImage;
255-
NeighborhoodRadiusType m_NeighborhoodRadius;
256-
OffsetVectorPointer m_Offsets;
257-
unsigned int m_NumberOfBinsPerAxis;
258-
PixelType m_HistogramValueMinimum;
259-
PixelType m_HistogramValueMaximum;
260-
RealType m_HistogramDistanceMinimum;
261-
RealType m_HistogramDistanceMaximum;
262-
MaskPixelType m_InsidePixelValue;
263-
typename TInputImage::SpacingType m_Spacing;
254+
typename DigitizedImageType::Pointer m_DigitizedInputImage;
255+
NeighborhoodRadiusType m_NeighborhoodRadius;
256+
OffsetVectorPointer m_Offsets;
257+
unsigned int m_NumberOfBinsPerAxis;
258+
PixelType m_HistogramValueMinimum;
259+
PixelType m_HistogramValueMaximum;
260+
RealType m_HistogramDistanceMinimum;
261+
RealType m_HistogramDistanceMaximum;
262+
MaskPixelType m_InsidePixelValue;
263+
typename TInputImage::SpacingType m_Spacing;
264264
};
265265
} // end of namespace Statistics
266266
} // end of namespace itk

include/itkRunLengthTextureFeaturesImageFilter.hxx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
9797

9898
DigitizerFunctorType digitalizer(m_NumberOfBinsPerAxis, m_InsidePixelValue, m_HistogramValueMinimum, m_HistogramValueMaximum);
9999

100-
typedef BinaryFunctorImageFilter< MaskImageType, InputImageType, InputImageType, DigitizerFunctorType> FilterType;
100+
typedef BinaryFunctorImageFilter< MaskImageType, InputImageType, DigitizedImageType, DigitizerFunctorType> FilterType;
101101
typename FilterType::Pointer filter = FilterType::New();
102102
if (this->GetMaskImage() != ITK_NULLPTR)
103103
{
@@ -168,10 +168,10 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
168168
alreadyVisitedImage->Allocate();
169169

170170
// Separation of the non-boundary region that will be processed in a different way
171-
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TInputImage > boundaryFacesCalculator;
172-
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< InputImageType >::FaceListType
171+
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< DigitizedImageType > boundaryFacesCalculator;
172+
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< DigitizedImageType >::FaceListType
173173
faceList = boundaryFacesCalculator( this->m_DigitizedInputImage, outputRegionForThread, m_NeighborhoodRadius );
174-
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< InputImageType >::FaceListType::iterator fit = faceList.begin();
174+
typename NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< DigitizedImageType >::FaceListType::iterator fit = faceList.begin();
175175

176176
// Declaration of the variables useful to iterate over the all image region
177177
bool isInImage;
@@ -186,10 +186,10 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
186186

187187

188188
// Declaration of the variables useful to iterate over the all neighborhood region
189-
PixelType currentInNeighborhoodPixelIntensity;
189+
HistogramIndexType currentInNeighborhoodPixelIntensity;
190190

191191
// Declaration of the variables useful to iterate over the run
192-
PixelType pixelIntensity( NumericTraits<PixelType>::ZeroValue() );
192+
HistogramIndexType pixelIntensity( NumericTraits<HistogramIndexType>::ZeroValue() );
193193
OffsetType iteratedOffset;
194194
OffsetType tempOffset;
195195
unsigned int pixelDistance;
@@ -263,7 +263,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
263263
// Special attention paid to boundaries of bins.
264264
// For the last bin, it is left close and right close (following the previous
265265
// gerrit patch). For all other bins, the bin is left close and right open.
266-
if ( pixelIntensity == currentInNeighborhoodPixelIntensity )
266+
if (pixelIntensity == currentInNeighborhoodPixelIntensity )
267267
{
268268
alreadyVisitedImage->SetPixel( boolCurentInNeighborhoodIndex + iteratedOffset, true );
269269
++pixelDistance;
@@ -359,7 +359,7 @@ template<typename TInputImage, typename TOutputImage, typename TMaskImage>
359359
void
360360
RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
361361
::IncreaseHistogram(vnl_matrix<unsigned int> &histogram, unsigned int &totalNumberOfRuns,
362-
const PixelType &currentInNeighborhoodPixelIntensity,
362+
const HistogramIndexType &currentInNeighborhoodPixelIntensity,
363363
const OffsetType &offset, const unsigned int &pixelDistance)
364364
{
365365
float offsetDistance = 0;
@@ -428,7 +428,6 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>
428428
shortRunHighGreyLevelEmphasis += ( frequency * i2 / j2 );
429429
longRunLowGreyLevelEmphasis += ( frequency * j2 / i2 );
430430
longRunHighGreyLevelEmphasis += ( frequency * i2 * j2 );
431-
432431
}
433432
}
434433
greyLevelNonuniformity =

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='itk-texturefeatures',
15-
version='3.0.0',
15+
version='3.1.0',
1616
author='Insight Software Consortium',
1717
author_email='[email protected]',
1818
packages=['itk'],

test/CoocurrenceTextureFeaturesImageFilterTest.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int CoocurrenceTextureFeaturesImageFilterTest( int argc, char *argv[] )
3939
const unsigned int VectorComponentDimension = 8;
4040

4141
// Declare types
42-
typedef int InputPixelType;
42+
typedef float InputPixelType;
4343
typedef float OutputPixelComponentType;
4444
typedef itk::Vector< OutputPixelComponentType, VectorComponentDimension >
4545
OutputPixelType;

test/CoocurrenceTextureFeaturesImageFilterTestVectorImageSeparateFeatures.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int CoocurrenceTextureFeaturesImageFilterTestVectorImageSeparateFeatures( int ar
4747
const unsigned int VectorComponentDimension = 8;
4848

4949
// Declare types
50-
typedef int InputPixelType;
50+
typedef float InputPixelType;
5151
typedef float OutputPixelType;
5252

5353
typedef itk::Image< InputPixelType, ImageDimension > InputImageType;

0 commit comments

Comments
 (0)