ITK/Examples/Smoothing/AntiAliasBinaryImageFilter
From KitwarePublic
Contents |
AntiAliasBinaryImageFilter.cxx
#include "itkImage.h" #include "itkImageFileWriter.h" #include "itkAntiAliasBinaryImageFilter.h" #include "QuickView.h" typedef itk::Image<unsigned char, 2> UnsignedCharImageType; typedef itk::Image<float, 2> FloatImageType; static void CreateImage(UnsignedCharImageType::Pointer image); int main(int, char *[]) { UnsignedCharImageType::Pointer image = UnsignedCharImageType::New(); CreateImage(image); // Take the absolute value of the image typedef itk::AntiAliasBinaryImageFilter <UnsignedCharImageType, FloatImageType> AntiAliasBinaryImageFilterType; AntiAliasBinaryImageFilterType::Pointer antiAliasFilter = AntiAliasBinaryImageFilterType::New (); antiAliasFilter->SetInput(image); QuickView viewer; viewer.AddImage<UnsignedCharImageType>(image); viewer.AddImage<FloatImageType>(antiAliasFilter->GetOutput()); viewer.Visualize(); return EXIT_SUCCESS; } void CreateImage(UnsignedCharImageType::Pointer image) { UnsignedCharImageType::IndexType start; start.Fill(0); UnsignedCharImageType::SizeType size; size.Fill(200); UnsignedCharImageType::RegionType region; region.SetSize(size); region.SetIndex(start); image->SetRegions(region); image->Allocate(); itk::ImageRegionIterator<UnsignedCharImageType> imageIterator(image,region); while(!imageIterator.IsAtEnd()) { if(imageIterator.GetIndex()[0] - imageIterator.GetIndex()[1] > 5) // some pixels white, some black { imageIterator.Set(255); } else { imageIterator.Set(0); } ++imageIterator; } }
CMakeLists.txt
cmake_minimum_required(VERSION 2.8) project(AntiAliasBinaryImageFilter) find_package(ItkVtkGlue REQUIRED) include(${ItkVtkGlue_USE_FILE}) add_executable(AntiAliasBinaryImageFilter AntiAliasBinaryImageFilter.cxx) target_link_libraries(AntiAliasBinaryImageFilter ItkVtkGlue ${VTK_LIBRARIES} ${ITK_LIBRARIES})
Building All of the Examples
Many of the examples in the ITK Wiki Examples Collection require VTK. You can build all of the the examples by following these instructions. If you are a new VTK user, you may want to try the Superbuild which will build a proper ITK and VTK.
ItkVtkGlue
If you download the entire ITK Wiki Examples Collection, the ItkVtkGlue directory will be included and configured. If you wish to just build a few examples, then you will need to download ItkVtkGlue and build it. When you run cmake it will ask you to specify the location of the ItkVtkGlue binary directory.
