Contour Spatial Object#
Note
Wish List Still needs additional work to finish proper creation of example.
Synopsis#
Contour spatial object.
Results#
Results Coming Soon!
Code#
C++#
#include "itkSpatialObjectToImageFilter.h"
#include "itkContourSpatialObject.h"
#include "itkContourSpatialObjectPoint.h"
#include "itkImageFileWriter.h"
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int /*argc*/, char * /*argv*/[])
{
using PixelType = unsigned char;
constexpr unsigned int Dimension = 2;
using ImageType = itk::Image<PixelType, Dimension>;
using ContourType = itk::ContourSpatialObject<Dimension>;
using SpatialObjectToImageFilterType = itk::SpatialObjectToImageFilter<ContourType, ImageType>;
// Create a list of points
ContourType::ControlPointListType points;
// Add some points
ContourType::ControlPointType point;
point.SetPositionInObjectSpace(0, 0);
points.push_back(point);
point.SetPositionInObjectSpace(0, 30);
points.push_back(point);
point.SetPositionInObjectSpace(30, 30);
points.push_back(point);
point.SetPositionInObjectSpace(0, 0);
points.push_back(point);
// Create a contour from the list of points
auto contour = ContourType::New();
contour->SetControlPoints(points);
auto imageFilter = SpatialObjectToImageFilterType::New();
itk::Size<2> size;
size.Fill(50);
imageFilter->SetInsideValue(255); // white
imageFilter->SetSize(size);
imageFilter->SetInput(contour);
imageFilter->Update();
itk::WriteImage(imageFilter->GetOutput(), "contour.png");
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage(imageFilter->GetOutput());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<unsigned int TDimension = 3>
class ContourSpatialObject : public itk::PointBasedSpatialObject<TDimension, ContourSpatialObjectPoint<TDimension>> Representation of a Contour based on the spatial object classes.
The Contour is basically defined by a set of points which are inside this blob
- See
SpatialObjectPoint
- ITK Sphinx Examples:
-
\sphinxexample{Core/SpatialObjects/{{
ContourSpatialObject,Contour Spacial Object} \endsphinx