Sharpen Image#

Synopsis#

Sharpen an image.

Results#

Warning

Fix Errors Example contains errors needed to be fixed for proper output.

Code#

C++#

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkLaplacianSharpeningImageFilter.h"
#include "itkSubtractImageFilter.h"

#ifdef ENABLE_QUICKVIEW
#  include "QuickView.h"
#endif

int
main(int argc, char * argv[])
{
  // Verify command line arguments
  if (argc < 2)
  {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile" << std::endl;
    return EXIT_FAILURE;
  }

  // Parse command line arguments
  std::string inputFileName = argv[1];

  // Setup types
  using FloatImageType = itk::Image<float, 2>;

  const auto input = itk::ReadImage<FloatImageType>(inputFileName);

  using LaplacianSharpeningImageFilterType = itk::LaplacianSharpeningImageFilter<FloatImageType, FloatImageType>;
  LaplacianSharpeningImageFilterType::Pointer laplacianSharpeningImageFilter =
    LaplacianSharpeningImageFilterType::New();
  laplacianSharpeningImageFilter->SetInput(input);

  using SubtractType = itk::SubtractImageFilter<FloatImageType>;
  auto diff = SubtractType::New();
  diff->SetInput1(input);
  diff->SetInput2(laplacianSharpeningImageFilter->GetOutput());

#ifdef ENABLE_QUICKVIEW
  QuickView viewer;
  viewer.AddImage(input.GetPointer(), true, itksys::SystemTools::GetFilenameName(argv[1]));

  std::stringstream desc;
  desc << "LaplacianSharpeningImageFilter";
  viewer.AddImage(laplacianSharpeningImageFilter->GetOutput(), true, desc.str());

  std::stringstream desc2;
  desc2 << "Original - LaplacianSharpening";
  viewer.AddImage(diff->GetOutput(), true, desc2.str());

  viewer.Visualize();
#endif
  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage>
class LaplacianSharpeningImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>

This filter sharpens an image using a Laplacian. LaplacianSharpening highlights regions of rapid intensity change and therefore highlights or enhances the edges. The result is an image that appears more in focus.

The LaplacianSharpening at each pixel location is computed by

convolution with the itk::LaplacianOperator.

Inputs and Outputs

The input to this filter is a scalar-valued itk::Image of arbitrary dimension. The output is a scalar-valued itk::Image.

See

Image

See

Neighborhood

See

NeighborhoodOperator

See

NeighborhoodIterator

See

LaplacianOperator

ITK Sphinx Examples:

See itk::LaplacianSharpeningImageFilter for additional documentation.