Smooth Image Using Min Max Curvature Flow¶
Synopsis¶
Smooth an image using min/max curvature flow.
Results¶

Input image.¶

Output In VTK Window¶
Code¶
C++¶
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkMinMaxCurvatureFlowImageFilter.h"
#include "itkSubtractImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage [iterations]" << std::endl;
return EXIT_FAILURE;
}
std::string inputFileName = argv[1];
int iterations = 5;
if (argc > 2)
{
std::stringstream ss(argv[2]);
ss >> iterations;
}
std::string inputFilename = argv[1];
using PixelType = float;
constexpr unsigned int Dimension = 2;
using ImageType = itk::Image<PixelType, Dimension>;
using ReaderType = itk::ImageFileReader<ImageType>;
using MinMaxCurvatureFlowImageFilterType = itk::MinMaxCurvatureFlowImageFilter<ImageType, ImageType>;
using SubtractType = itk::SubtractImageFilter<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFilename);
MinMaxCurvatureFlowImageFilterType::Pointer minMaxCurvatureFlowImageFilter =
MinMaxCurvatureFlowImageFilterType::New();
minMaxCurvatureFlowImageFilter->SetInput(reader->GetOutput());
minMaxCurvatureFlowImageFilter->SetNumberOfIterations(iterations);
minMaxCurvatureFlowImageFilter->SetTimeStep(0.125);
SubtractType::Pointer diff = SubtractType::New();
diff->SetInput1(reader->GetOutput());
diff->SetInput2(minMaxCurvatureFlowImageFilter->GetOutput());
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFilename));
std::stringstream desc;
desc << "MinMaxCurvatureFlow, iterations = " << iterations;
viewer.AddImage(minMaxCurvatureFlowImageFilter->GetOutput(), true, desc.str());
std::stringstream desc2;
desc2 << "Original - Median";
viewer.AddImage(diff->GetOutput(), true, desc2.str());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
Classes demonstrated¶
-
template<typename
TInputImage
, typenameTOutputImage
>
classMinMaxCurvatureFlowImageFilter
: public itk::CurvatureFlowImageFilter<TInputImage, TOutputImage> Denoise an image using min/max curvature flow.
MinMaxCurvatureFlowImageFilter implements a curvature driven image denoising algorithm. Iso-brightness contours in the grayscale input image are viewed as a level set. The level set is then evolved using a curvature-based speed function:
where
if
is less than or equal to
and
, otherwise.
is the mean curvature of the iso-brightness contour at point
.
In min/max curvature flow, movement is turned on or off depending on the scale of the noise one wants to remove. Switching depends on the average image value of a region of radius
around each point. The choice of
, the stencil radius, governs the scale of the noise to be removed.
The threshold value
is the average intensity obtained in the direction perpendicular to the gradient at point
at the extrema of the local neighborhood.
This filter make use of the multi-threaded finite difference solver hierarchy. Updates are computed using a MinMaxCurvatureFlowFunction object. A zero flux Neumann boundary condition is used when computing derivatives near the data boundary.
Reference: “Level Set Methods and Fast Marching Methods”, J.A. Sethian, Cambridge Press, Chapter 16, Second edition, 1999.
- Warning
This filter assumes that the input and output types have the same dimensions. This filter also requires that the output image pixels are of a real type. This filter works for any dimensional images, however for dimensions greater than 3D, an expensive brute-force search is used to compute the local threshold.
- See
MinMaxCurvatureFlowFunction
- See
CurvatureFlowImageFilter
- See
BinaryMinMaxCurvatureFlowImageFilter
- ITK Sphinx Examples:
Subclassed by itk::BinaryMinMaxCurvatureFlowImageFilter< TInputImage, TOutputImage >