Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Modules/Core/Common/include/itkSobelOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class ITK_TEMPLATE_EXPORT SobelOperator : public NeighborhoodOperator<TPixel, VD
using Self = SobelOperator;
using Superclass = NeighborhoodOperator<TPixel, VDimension, TAllocator>;

/** Additional type alias. */
using typename Superclass::SizeType;

itkOverrideGetNameOfClassMacro(SobelOperator);

static_assert(
Expand Down
46 changes: 16 additions & 30 deletions Modules/Core/Common/include/itkSobelOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef itkSobelOperator_hxx
#define itkSobelOperator_hxx

#include "itkIndexRange.h"
#include "itkObject.h"

namespace itk
Expand All @@ -32,41 +33,26 @@ SobelOperator<TPixel, VDimension, TAllocator>::Fill(const CoefficientVector & co
// coefficients in the exact center of the neighborhood
const unsigned int center = this->GetCenterNeighborhoodIndex();

if constexpr (VDimension == 2)
{
unsigned int coeff_index = 0;
for (int y = -1; y <= 1; ++y)
{
for (int x = -1; x <= 1; ++x)
{
const int pos = center + y * this->GetStride(1) + x * this->GetStride(0);
// Note, The following line copies the double precision
// coefficients of SobelOperator to the pixel type
// of the neighborhood operator which may not support
// negative numbers, or floating point numbers.
this->operator[](pos) = static_cast<TPixel>(coeff[coeff_index]);
using IndexType = Index<VDimension>;

++coeff_index;
}
}
}
if constexpr (VDimension == 3)
unsigned int coeff_index = 0;
for (const IndexType & index :
ImageRegionIndexRange<VDimension>(ImageRegion{ IndexType::Filled(-1), SizeType::Filled(3) }))
{
unsigned int coeff_index = 0;
for (int z = -1; z <= 1; ++z)
auto pos = static_cast<int>(center);

for (unsigned int i{}; i < VDimension; ++i)
{
for (int y = -1; y <= 1; ++y)
{
for (int x = -1; x <= 1; ++x)
{
const int pos = center + z * this->GetStride(2) + y * this->GetStride(1) + x * this->GetStride(0);
pos += static_cast<int>(index[i] * this->GetStride(i));
}

this->operator[](pos) = static_cast<TPixel>(coeff[coeff_index]);
// Note, The following line copies the double precision
// coefficients of SobelOperator to the pixel type
// of the neighborhood operator which may not support
// negative numbers, or floating point numbers.
this->operator[](pos) = static_cast<TPixel>(coeff[coeff_index]);

++coeff_index;
}
}
}
++coeff_index;
}
}

Expand Down
Loading