Skip to content

Commit

Permalink
ENH: Restore integer support for laplacian sharpening
Browse files Browse the repository at this point in the history
Revert to using the a laplacian neighborhood operator over
the recursive laplacian filter which requires real pixel types for
input and output.
  • Loading branch information
blowekamp authored and hjmjohnson committed Jun 20, 2023
1 parent 14816ad commit 6a5060b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
8 changes: 3 additions & 5 deletions Examples/Filtering/LaplacianSharpeningImageFilter.cxx
Expand Up @@ -34,21 +34,19 @@ main(int argc, char * argv[])
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];

using PixelType = float;
using CharPixelType = unsigned char;
constexpr unsigned int Dimension = 2;

using ImageType = itk::Image<PixelType, Dimension>;
using CharImageType = itk::Image<CharPixelType, Dimension>;

using ReaderType = itk::ImageFileReader<ImageType>;
using ReaderType = itk::ImageFileReader<CharImageType>;
using WriterType = itk::ImageFileWriter<CharImageType>;

using RescaleFilter =
itk::RescaleIntensityImageFilter<ImageType, CharImageType>;
itk::RescaleIntensityImageFilter<CharImageType, CharImageType>;

using LaplacianSharpeningFilter =
itk::LaplacianSharpeningImageFilter<ImageType, ImageType>;
itk::LaplacianSharpeningImageFilter<CharImageType, CharImageType>;


// Setting the IO
Expand Down
Expand Up @@ -93,8 +93,6 @@ class ITK_TEMPLATE_EXPORT LaplacianSharpeningImageFilter : public ImageToImageFi
#ifdef ITK_USE_CONCEPT_CHECKING
// Begin concept checking
itkConceptMacro(SameDimensionCheck, (Concept::SameDimension<InputImageDimension, ImageDimension>));
itkConceptMacro(InputPixelTypeIsFloatingPointCheck, (Concept::IsFloatingPoint<InputPixelType>));
itkConceptMacro(OutputPixelTypeIsFloatingPointCheck, (Concept::IsFloatingPoint<OutputPixelType>));
// End concept checking
#endif

Expand Down
Expand Up @@ -69,10 +69,41 @@ LaplacianSharpeningImageFilter<TInputImage, TOutputImage>::GenerateData()

using RealImageType = Image<RealType, ImageDimension>;

using LaplacianImageFilter = LaplacianImageFilter<InputImageType, RealImageType>;
typename LaplacianImageFilter::Pointer laplacianFilter = LaplacianImageFilter::New();
// Create the Laplacian operator
LaplacianOperator<RealType, ImageDimension> oper;
double s[ImageDimension];
for (unsigned int i = 0; i < ImageDimension; ++i)
{
if (localInput->GetSpacing()[i] == 0.0)
{
itkExceptionMacro("Image spacing cannot be zero");
}
else if (this->m_UseImageSpacing)
{
s[i] = 1.0 / localInput->GetSpacing()[i];
}
else
{
s[i] = 1.0;
}
}
oper.SetDerivativeScalings(s);
oper.CreateOperator();
// Calculate the Laplacian filtered image

// do calculations in floating point
using RealImageType = Image<RealType, ImageDimension>;
using NOIF = NeighborhoodOperatorImageFilter<InputImageType, RealImageType>;
ZeroFluxNeumannBoundaryCondition<InputImageType> nbc;

auto laplacianFilter = NOIF::New();
laplacianFilter->OverrideBoundaryCondition(static_cast<typename NOIF::ImageBoundaryConditionPointerType>(&nbc));

//
// set up the mini-pipeline
//
laplacianFilter->SetOperator(oper);
laplacianFilter->SetInput(localInput);
laplacianFilter->SetUseImageSpacing(m_UseImageSpacing);
laplacianFilter->Update();

auto filteredMinMaxFilter = MinimumMaximumImageFilter<RealImageType>::New();
Expand Down

0 comments on commit 6a5060b

Please sign in to comment.