ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Filtering/Thresholding/DemonstrateThresholdAlgorithms/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include <sstream>
#include <iostream>
#include <map>
#ifdef ENABLE_QUICKVIEW
# include "itksys/SystemTools.hxx"
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0];
std::cout << " inputImageFile";
std::cerr << std::endl;
return EXIT_FAILURE;
}
#ifdef ENABLE_QUICKVIEW
using InputPixelType = short;
using InputImageType = itk::Image<InputPixelType, 2>;
const auto input = itk::ReadImage<InputImageType>(argv[1]);
using OutputPixelType = unsigned char;
using OutputImageType = itk::Image<OutputPixelType, 2>;
// TODO: Fix KittlerIllingworth Filter
// using KittlerIllingworthFilterType = itk::KittlerIllingworthThresholdImageFilter<InputImageType, OutputImageType>;
QuickView viewer;
viewer.AddImage(input.GetPointer(), true, itksys::SystemTools::GetFilenameName(argv[1]));
using FilterContainerType =
FilterContainerType filterContainer;
filterContainer["Huang"] = HuangFilterType::New();
filterContainer["Intermodes"] = IntermodesFilterType::New();
filterContainer["IsoData"] = IsoDataFilterType::New();
// filterContainer["KittlerIllingworth"] = KittlerIllingworthFilterType::New();
filterContainer["Li"] = LiFilterType::New();
filterContainer["MaximumEntropy"] = MaximumEntropyFilterType::New();
filterContainer["Moments"] = MomentsFilterType::New();
filterContainer["Otsu"] = OtsuFilterType::New();
filterContainer["RenyiEntropy"] = RenyiEntropyFilterType::New();
filterContainer["Shanbhag"] = ShanbhagFilterType::New();
filterContainer["Triangle"] = TriangleFilterType::New();
filterContainer["Yen"] = YenFilterType::New();
auto it = filterContainer.begin();
for (it = filterContainer.begin(); it != filterContainer.end(); ++it)
{
(*it).second->SetInsideValue(255);
(*it).second->SetOutsideValue(0);
(*it).second->SetInput(input);
(*it).second->SetNumberOfHistogramBins(100);
(*it).second->Update();
std::stringstream desc;
desc << (*it).first << " threshold = " << (*it).second->GetThreshold();
viewer.AddImage((*it).second->GetOutput(), true, desc.str());
}
viewer.Visualize();
#else
std::cout << " Example requires compilation with ENABLE_QUICKVIEW defined." << std::endl;
#endif
return EXIT_SUCCESS;
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itkMomentsThresholdImageFilter.h
itkRenyiEntropyThresholdImageFilter.h
itk::MomentsThresholdImageFilter
Threshold an image using the Moments Threshold.
Definition: itkMomentsThresholdImageFilter.h:52
itkIntermodesThresholdImageFilter.h
itk::YenThresholdImageFilter
Threshold an image using the Yen Threshold.
Definition: itkYenThresholdImageFilter.h:51
itkImageFileReader.h
itkTriangleThresholdImageFilter.h
itkMaximumEntropyThresholdImageFilter.h
itk::OtsuThresholdImageFilter
Threshold an image using the Otsu Threshold.
Definition: itkOtsuThresholdImageFilter.h:55
itk::HuangThresholdImageFilter
Threshold an image using the Huang Threshold.
Definition: itkHuangThresholdImageFilter.h:52
itk::ShanbhagThresholdImageFilter
Threshold an image using the Shanbhag Threshold.
Definition: itkShanbhagThresholdImageFilter.h:52
QuickView.h
QuickView::AddImage
void AddImage(TImage *, bool FlipVertical=true, std::string Description="")
itk::IntermodesThresholdImageFilter
Threshold an image using the Intermodes Threshold.
Definition: itkIntermodesThresholdImageFilter.h:52
itk::TriangleThresholdImageFilter
Threshold an image using the Triangle Threshold.
Definition: itkTriangleThresholdImageFilter.h:52
itkKittlerIllingworthThresholdImageFilter.h
itkLiThresholdImageFilter.h
itk::MaximumEntropyThresholdImageFilter
Threshold an image using the MaximumEntropy Threshold.
Definition: itkMaximumEntropyThresholdImageFilter.h:52
itkOtsuThresholdImageFilter.h
itkShanbhagThresholdImageFilter.h
itkHuangThresholdImageFilter.h
itkIsoDataThresholdImageFilter.h
itk::RenyiEntropyThresholdImageFilter
Threshold an image using the RenyiEntropy Threshold.
Definition: itkRenyiEntropyThresholdImageFilter.h:52
QuickView
A convenient class to render itk images with vtk.
Definition: QuickView.h:111
itkYenThresholdImageFilter.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()
QuickView::Visualize
void Visualize(bool interact=true)
itk::LiThresholdImageFilter
Threshold an image using the Li Threshold.
Definition: itkLiThresholdImageFilter.h:56
itk::IsoDataThresholdImageFilter
Threshold an image using the IsoData Threshold.
Definition: itkIsoDataThresholdImageFilter.h:52