ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Segmentation/ConnectedComponents/LabelConnectComponentsInBinaryImage/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 "itksys/SystemTools.hxx"
#include <sstream>
#include <map>
#ifdef ENABLE_QUICKVIEW
# 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;
}
using InputPixelType = short;
using OutputPixelType = int;
using RGBPixelType = itk::RGBPixel<unsigned char>;
using InputImageType = itk::Image<InputPixelType, 2>;
using OutputImageType = itk::Image<OutputPixelType, 2>;
using RGBImageType = itk::Image<RGBPixelType, 2>;
const auto input = itk::ReadImage<InputImageType>(argv[1]);
#ifdef ENABLE_QUICKVIEW
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->SetNumberOfHistogramBins(25);
(*it).second->SetInput(input);
try
{
(*it).second->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cout << "Caught exception" << std::endl;
std::cout << err << std::endl;
continue;
}
connected->SetInput((*it).second->GetOutput());
auto rgbFilter = RGBFilterType::New();
rgbFilter->SetInput(connected->GetOutput());
std::stringstream desc;
desc << (*it).first << " threshold = " << (*it).second->GetThreshold();
viewer.AddRGBImage(rgbFilter->GetOutput(), true, desc.str());
}
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
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
itkLabelToRGBImageFilter.h
itk::ShanbhagThresholdImageFilter
Threshold an image using the Shanbhag Threshold.
Definition: itkShanbhagThresholdImageFilter.h:52
QuickView::AddRGBImage
void AddRGBImage(TImage *, bool FlipVertical=true, std::string Description="")
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
itk::KittlerIllingworthThresholdImageFilter
Threshold an image using the KittlerIllingworth Threshold.
Definition: itkKittlerIllingworthThresholdImageFilter.h:52
itkShanbhagThresholdImageFilter.h
itkHuangThresholdImageFilter.h
itkConnectedComponentImageFilter.h
itkIsoDataThresholdImageFilter.h
itk::RenyiEntropyThresholdImageFilter
Threshold an image using the RenyiEntropy Threshold.
Definition: itkRenyiEntropyThresholdImageFilter.h:52
itk::LabelToRGBImageFilter
Apply a colormap to a label image.
Definition: itkLabelToRGBImageFilter.h:50
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::ConnectedComponentImageFilter
Label the objects in a binary image.
Definition: itkConnectedComponentImageFilter.h:59
itk::IsoDataThresholdImageFilter
Threshold an image using the IsoData Threshold.
Definition: itkIsoDataThresholdImageFilter.h:52