Skip to content

Commit 582f7e8

Browse files
committed
STYLE: Address Greptile review on TextureFeatures
itkFirstOrderTextureHistogram.h: guard the unbiased-variance estimate on count > 1 so a single-pixel window no longer divides by zero and produces NaN skewness; correct the stale \ingroup tag. itkFirstOrderTextureFeaturesImageFilter.h: correct the stale \ingroup tag from ITKTextureFeatures (old remote-module name) to TextureFeatures. itkCoocurrenceTextureFeaturesImageFilter.h: drop the unrelated itkScalarImageToRunLengthMatrixFilter.h include — neither the .h nor .hxx uses any type from it. itkCoocurrenceTextureFeaturesImageFilter.hxx: write a zero output pixel on the totalNumberOfFreq == 0 branch so the output never contains uninitialized memory; replace raw new[]/delete[] of the marginal-sums buffer with std::vector for exception safety and zero-initialization. test/CMakeLists.txt: drop the dead first set(TextureFeaturesTests …) block — it listed nonexistent ScalarImageTo* sources and was immediately overwritten by the second definition.
1 parent 8353852 commit 582f7e8

5 files changed

Lines changed: 12 additions & 27 deletions

File tree

Modules/Filtering/TextureFeatures/include/itkCoocurrenceTextureFeaturesImageFilter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define itkCoocurrenceTextureFeaturesImageFilter_h
2020

2121
#include "itkImageToImageFilter.h"
22-
#include "itkScalarImageToRunLengthMatrixFilter.h"
2322
#include "itkConstNeighborhoodIterator.h"
2423

2524
namespace itk

Modules/Filtering/TextureFeatures/include/itkCoocurrenceTextureFeaturesImageFilter.hxx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "itkBinaryFunctorImageFilter.h"
2525
#include "itkDigitizerFunctor.h"
2626

27+
#include <vector>
28+
2729
namespace itk
2830
{
2931
namespace Statistics
@@ -229,6 +231,11 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>::Dy
229231
this->ComputeFeatures(hist, totalNumberOfFreq, outputPixel);
230232
outputIt.Set(outputPixel);
231233
}
234+
else
235+
{
236+
outputPixel.Fill(0);
237+
outputIt.Set(outputPixel);
238+
}
232239

233240
++inputNIt;
234241
++outputIt;
@@ -360,12 +367,8 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>::Co
360367
// cleverly compressed to one pass, but it's not clear that that's necessary.
361368

362369
// Initialize everything
363-
auto * marginalSums = new double[m_NumberOfBinsPerAxis];
370+
std::vector<double> marginalSums(m_NumberOfBinsPerAxis, 0.0);
364371

365-
for (double * ms_It = marginalSums; ms_It < marginalSums + m_NumberOfBinsPerAxis; ms_It++)
366-
{
367-
*ms_It = 0;
368-
}
369372
pixelMean = 0;
370373

371374
// Ok, now do the first pass through the histogram to get the marginal sums
@@ -417,8 +420,6 @@ CoocurrenceTextureFeaturesImageFilter<TInputImage, TOutputImage, TMaskImage>::Co
417420
pixelVariance += (a - pixelMean) * (a - pixelMean) * (frequency);
418421
}
419422
}
420-
421-
delete[] marginalSums;
422423
}
423424

424425
template <typename TInputImage, typename TOutputImage, typename TMaskImage>

Modules/Filtering/TextureFeatures/include/itkFirstOrderTextureFeaturesImageFilter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace itk
4545
* so that the boundary pixel have lets data to compute the
4646
* statistics.
4747
*
48-
* \ingroup ITKTextureFeatures
48+
* \ingroup TextureFeatures
4949
*/
5050

5151
template <class TInputImage, class TOutputImage, class TKernel>

Modules/Filtering/TextureFeatures/include/itkFirstOrderTextureHistogram.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace Function
3434
* std::map based "histogram" during iteration and computes first
3535
* order statistics from the histogram.
3636
*
37-
* \ingroup ITKTextureFeatures
37+
* \ingroup TextureFeatures
3838
*/
3939
template <class TInputPixel, class TOutputPixel>
4040
class ITK_TEMPLATE_EXPORT FirstOrderTextureHistogram
@@ -96,8 +96,8 @@ class ITK_TEMPLATE_EXPORT FirstOrderTextureHistogram
9696

9797
const double mean = sum / count;
9898

99-
// unbiased estimate
100-
const double variance = (sum2 - (sum * sum) / count) / (count - 1);
99+
// unbiased estimate (requires at least 2 samples)
100+
const double variance = (count > 1) ? (sum2 - (sum * sum) / count) / (count - 1) : 0.0;
101101
const double sigma = std::sqrt(variance);
102102
double skewness = 0.0;
103103
double kurtosis = 0.0;

Modules/Filtering/TextureFeatures/test/CMakeLists.txt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
itk_module_test()
22

3-
set(
4-
TextureFeaturesTests
5-
ScalarImageToRunLengthFeaturesImageFilterInstantiationTest.cxx
6-
ScalarImageToRunLengthFeaturesImageFilterTest.cxx
7-
ScalarImageToRunLengthFeaturesImageFilterTestSeparateFeatures.cxx
8-
ScalarImageToRunLengthFeaturesImageFilterTestWithoutMask.cxx
9-
ScalarImageToRunLengthFeaturesImageFilterTestWithVectorImage.cxx
10-
ScalarImageToRunLengthFeaturesImageFilterTestVectorImageSeparateFeatures.cxx
11-
ScalarImageToTextureFeaturesImageFilterInstantiationTest.cxx
12-
ScalarImageToTextureFeaturesImageFilterTest.cxx
13-
ScalarImageToTextureFeaturesImageFilterTestSeparateFeatures.cxx
14-
ScalarImageToTextureFeaturesImageFilterTestWithoutMask.cxx
15-
ScalarImageToTextureFeaturesImageFilterTestWithVectorImage.cxx
16-
)
17-
183
set(
194
TextureFeaturesTests
205
RunLengthTextureFeaturesImageFilterInstantiationTest.cxx

0 commit comments

Comments
 (0)