ITK  5.2.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
*
* http://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>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1]));
using FilterContainerType =
std::map<std::string, itk::HistogramThresholdImageFilter<InputImageType, OutputImageType>::Pointer>;
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(reader->GetOutput());
try
{
(*it).second->Update();
}
catch (itk::ExceptionObject & err)
{
std::cout << "Caught exception" << std::endl;
std::cout << err << std::endl;
continue;
}
ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New();
connected->SetInput((*it).second->GetOutput());
RGBFilterType::Pointer 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;
}
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:53
itkIntermodesThresholdImageFilter.h
itk::YenThresholdImageFilter
Threshold an image using the Yen Threshold.
Definition: itkYenThresholdImageFilter.h:52
itkImageFileReader.h
itkTriangleThresholdImageFilter.h
itkMaximumEntropyThresholdImageFilter.h
itk::OtsuThresholdImageFilter
Threshold an image using the Otsu Threshold.
Definition: itkOtsuThresholdImageFilter.h:56
itk::HuangThresholdImageFilter
Threshold an image using the Huang Threshold.
Definition: itkHuangThresholdImageFilter.h:53
itkLabelToRGBImageFilter.h
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
itk::ShanbhagThresholdImageFilter
Threshold an image using the Shanbhag Threshold.
Definition: itkShanbhagThresholdImageFilter.h:53
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:53
itk::TriangleThresholdImageFilter
Threshold an image using the Triangle Threshold.
Definition: itkTriangleThresholdImageFilter.h:53
itkKittlerIllingworthThresholdImageFilter.h
itkImageFileWriter.h
itkLiThresholdImageFilter.h
itk::MaximumEntropyThresholdImageFilter
Threshold an image using the MaximumEntropy Threshold.
Definition: itkMaximumEntropyThresholdImageFilter.h:53
itkOtsuThresholdImageFilter.h
itk::KittlerIllingworthThresholdImageFilter
Threshold an image using the KittlerIllingworth Threshold.
Definition: itkKittlerIllingworthThresholdImageFilter.h:53
itkShanbhagThresholdImageFilter.h
itkHuangThresholdImageFilter.h
itkConnectedComponentImageFilter.h
itkIsoDataThresholdImageFilter.h
itk::RenyiEntropyThresholdImageFilter
Threshold an image using the RenyiEntropy Threshold.
Definition: itkRenyiEntropyThresholdImageFilter.h:53
itk::LabelToRGBImageFilter
Apply a colormap to a label image.
Definition: itkLabelToRGBImageFilter.h:51
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:86
QuickView::Visualize
void Visualize(bool interact=true)
itk::LiThresholdImageFilter
Threshold an image using the Li Threshold.
Definition: itkLiThresholdImageFilter.h:57
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:53