Binary Min and Max Curvature Flow of Binary Image¶
Synopsis¶
BinaryMinMaxCurvatureFlow a binary image.
Results¶
![input image](../../../../_images/Yinyang15.png)
Input image.¶
![../../../../_images/BinaryMinMaxCurvatureFlow.png](../../../../_images/BinaryMinMaxCurvatureFlow.png)
Output In VTK Window¶
Code¶
C++¶
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkBinaryMinMaxCurvatureFlowImageFilter.h"
#include "itkSubtractImageFilter.h"
#include "itksys/SystemTools.hxx"
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << argv[0] << " InputFileName [NumberOfIterations]" << std ::endl;
return EXIT_FAILURE;
}
std::string inputFileName = argv[1];
unsigned int numberOfIterations = 2;
if (argc > 2)
{
numberOfIterations = std::stoi(argv[2]);
}
constexpr unsigned int Dimension = 2;
using InputPixelType = float;
using OutputPixelType = float;
using InputImageType = itk::Image<InputPixelType, Dimension>;
using ReaderType = itk::ImageFileReader<InputImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
using OutputImageType = itk::Image<OutputPixelType, Dimension>;
using FilterType = itk::BinaryMinMaxCurvatureFlowImageFilter<InputImageType, OutputImageType>;
FilterType::Pointer filter = FilterType::New();
filter->SetInput(reader->GetOutput());
filter->SetThreshold(255);
filter->SetNumberOfIterations(numberOfIterations);
using SubtractType = itk::SubtractImageFilter<OutputImageType>;
SubtractType::Pointer diff = SubtractType::New();
diff->SetInput1(reader->GetOutput());
diff->SetInput2(filter->GetOutput());
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFileName));
std::stringstream desc;
desc << "BinaryMinMaxCurvature, iterations = " << numberOfIterations;
viewer.AddImage(filter->GetOutput(), true, desc.str());
std::stringstream desc2;
desc2 << "Original - BinaryMinMaxCurvatureFlow";
viewer.AddImage(diff->GetOutput(), true, desc2.str());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
Classes demonstrated¶
-
template<typename
TInputImage
, typenameTOutputImage
>
classBinaryMinMaxCurvatureFlowImageFilter
: public itk::MinMaxCurvatureFlowImageFilter<TInputImage, TOutputImage> Denoise a binary image using min/max curvature flow.
BinaryMinMaxCurvatureFlowImageFilter implements a curvature driven image denoising algorithm. This filter assumes that the image is essentially binary: consisting of two classes. Iso-brightness contours in the 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 a user specified value which discriminates between the two pixel classes.
This filter make use of the multi-threaded finite difference solver hierarchy. Updates are computed using a BinaryMinMaxCurvatureFlowFunction 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.
- See
BinaryMinMaxCurvatureFlowFunction
- See
CurvatureFlowImageFilter
- See
MinMaxCurvatureFlowImageFilter
- ITK Sphinx Examples: