Helpful methods for working with contours and images. More...
#include <mitkContourUtils.h>
Public Types | |
typedef ContourUtils | Self |
typedef itk::Object | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
Contour::Pointer | ProjectContourTo2DSlice (Image *slice, Contour *contourIn3D, bool correctionForIpSegmentation, bool constrainToInside) |
Projects a contour onto an image point by point. Converts from world to index coordinates. | |
Contour::Pointer | BackProjectContourFrom2DSlice (Image *slice, Contour *contourIn2D, bool correctionForIpSegmentation=false) |
Projects a slice index coordinates of a contour back into world coordinates. | |
void | FillContourInSlice (Contour *projectedContour, Image *sliceImage, int paintingPixelValue=1) |
Fill a contour in a 2D slice with a specified pixel value. | |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
ContourUtils () | |
virtual | ~ContourUtils () |
template<typename TPixel , unsigned int VImageDimension> | |
void | ItkCopyFilledContourToSlice (itk::Image< TPixel, VImageDimension > *originalSlice, const Image *filledContourSlice, int overwritevalue=1) |
Paint a filled contour (e.g. of an ipSegmentation pixel type) into a mitk::Image (or arbitraty pixel type). Will not copy the whole filledContourSlice, but only set those pixels in originalSlice to overwritevalue, where the corresponding pixel in filledContourSlice is non-zero. |
Helpful methods for working with contours and images.
Originally copied from FeedbackContourTool
Definition at line 35 of file mitkContourUtils.h.
typedef itk::SmartPointer<const Self> mitk::ContourUtils::ConstPointer |
Definition at line 39 of file mitkContourUtils.h.
typedef itk::SmartPointer<Self> mitk::ContourUtils::Pointer |
Definition at line 39 of file mitkContourUtils.h.
typedef ContourUtils mitk::ContourUtils::Self |
Definition at line 39 of file mitkContourUtils.h.
typedef itk::Object mitk::ContourUtils::Superclass |
Definition at line 39 of file mitkContourUtils.h.
mitk::ContourUtils::ContourUtils | ( | ) | [protected] |
Definition at line 25 of file mitkContourUtils.cpp.
{ }
mitk::ContourUtils::~ContourUtils | ( | ) | [protected, virtual] |
Definition at line 29 of file mitkContourUtils.cpp.
{ }
mitk::Contour::Pointer mitk::ContourUtils::BackProjectContourFrom2DSlice | ( | Image * | slice, |
Contour * | contourIn2D, | ||
bool | correctionForIpSegmentation = false |
||
) |
Projects a slice index coordinates of a contour back into world coordinates.
correctionForIpSegmentation | subtracts 0.5 to x and y index coordinates (difference between ipSegmentation and MITK contours) |
Definition at line 65 of file mitkContourUtils.cpp.
References mitk::Contour::GetContourPath(), mitk::BaseData::GetGeometry(), mitk::Geometry3D::IndexToWorld(), MITK_DEBUG, and mitk::Contour::New().
{ if ( !slice || !contourIn2D ) return NULL; Contour::Pointer worldContour = Contour::New(); const Contour::PathType::VertexListType* pointsIn2D = contourIn2D->GetContourPath()->GetVertexList(); const Geometry3D* sliceGeometry = slice->GetGeometry(); for ( Contour::PathType::VertexListType::const_iterator iter = pointsIn2D->begin(); iter != pointsIn2D->end(); ++iter ) { Contour::PathType::VertexType currentPointIn3DITK = *iter; Point3D currentPointIn2D; for (int i = 0; i < 3; ++i) currentPointIn2D[i] = currentPointIn3DITK[i]; Point3D worldPointIn3D; worldPointIn3D.Fill(0.0); sliceGeometry->IndexToWorld( currentPointIn2D, worldPointIn3D ); MITK_DEBUG << "index " << currentPointIn2D << " world " << worldPointIn3D << std::endl; worldContour->AddVertex( worldPointIn3D ); } return worldContour; }
void mitk::ContourUtils::FillContourInSlice | ( | Contour * | projectedContour, |
Image * | sliceImage, | ||
int | paintingPixelValue = 1 |
||
) |
Fill a contour in a 2D slice with a specified pixel value.
Definition at line 94 of file mitkContourUtils.cpp.
References AccessFixedDimensionByItk_2, mitk::Contour::GetContourPath(), mitk::Contour::GetNumberOfPoints(), mitk::Image::GetSliceData(), ipMITKSegmentationClear(), ipMITKSegmentationCombineRegion(), ipMITKSegmentationFree(), ipMITKSegmentationNew(), IPSEGMENTATION_OR, MITK_DEBUG, mitkIpPicDescriptor, and mitk::Image::New().
{ // 1. Use ipSegmentation to draw a filled(!) contour into a new 8 bit 2D image, which will later be copied back to the slice. // We don't work on the "real" working data, because ipSegmentation would restrict us to 8 bit images // convert the projected contour into a ipSegmentation format mitkIpInt4_t* picContour = new mitkIpInt4_t[2 * projectedContour->GetNumberOfPoints()]; const Contour::PathType::VertexListType* pointsIn2D = projectedContour->GetContourPath()->GetVertexList(); unsigned int index(0); for ( Contour::PathType::VertexListType::const_iterator iter = pointsIn2D->begin(); iter != pointsIn2D->end(); ++iter, ++index ) { picContour[ 2 * index + 0 ] = static_cast<mitkIpInt4_t>( (*iter)[0] + 0.5); picContour[ 2 * index + 1 ] = static_cast<mitkIpInt4_t>( (*iter)[1] + 0.5); MITK_DEBUG << "mitk 2d [" << (*iter)[0] << ", " << (*iter)[1] << "] pic [" << picContour[ 2*index+0] << ", " << picContour[ 2*index+1] << "]"; } assert( sliceImage->GetSliceData() ); mitkIpPicDescriptor* originalPicSlice = sliceImage->GetSliceData()->GetPicDescriptor(); mitkIpPicDescriptor* picSlice = ipMITKSegmentationNew( originalPicSlice ); ipMITKSegmentationClear( picSlice ); assert( originalPicSlice && picSlice ); // here comes the actual contour filling algorithm (from ipSegmentation/Graphics Gems) ipMITKSegmentationCombineRegion ( picSlice, picContour, projectedContour->GetNumberOfPoints(), NULL, IPSEGMENTATION_OR, 1); // set to 1 delete[] picContour; // 2. Copy the filled contour to the working data slice // copy all pixels that are non-zero to the original image (not caring for the actual type of the working image). perhaps make the replace value a parameter ( -> general painting tool ). // make the pic slice an mitk/itk image (as little ipPic code as possible), call a templated method with accessbyitk, iterate over the original and the modified slice Image::Pointer ipsegmentationModifiedSlice = Image::New(); ipsegmentationModifiedSlice->Initialize( picSlice ); ipsegmentationModifiedSlice->SetPicSlice( picSlice ); AccessFixedDimensionByItk_2( sliceImage, ItkCopyFilledContourToSlice, 2, ipsegmentationModifiedSlice, paintingPixelValue ); ipsegmentationModifiedSlice = NULL; // free MITK header information ipMITKSegmentationFree( picSlice ); // free actual memory }
virtual const char* mitk::ContourUtils::GetClassName | ( | ) | const [virtual] |
void mitk::ContourUtils::ItkCopyFilledContourToSlice | ( | itk::Image< TPixel, VImageDimension > * | originalSlice, |
const Image * | filledContourSlice, | ||
int | overwritevalue = 1 |
||
) | [protected] |
Paint a filled contour (e.g. of an ipSegmentation pixel type) into a mitk::Image (or arbitraty pixel type). Will not copy the whole filledContourSlice, but only set those pixels in originalSlice to overwritevalue, where the corresponding pixel in filledContourSlice is non-zero.
Definition at line 139 of file mitkContourUtils.cpp.
References mitk::CastToItkImage().
{ typedef itk::Image<TPixel,VImageDimension> SliceType; typename SliceType::Pointer filledContourSliceITK; CastToItkImage( filledContourSlice, filledContourSliceITK ); // now the original slice and the ipSegmentation-painted slice are in the same format, and we can just copy all pixels that are non-zero typedef itk::ImageRegionIterator< SliceType > OutputIteratorType; typedef itk::ImageRegionConstIterator< SliceType > InputIteratorType; InputIteratorType inputIterator( filledContourSliceITK, filledContourSliceITK->GetLargestPossibleRegion() ); OutputIteratorType outputIterator( originalSlice, originalSlice->GetLargestPossibleRegion() ); outputIterator.GoToBegin(); inputIterator.GoToBegin(); while ( !outputIterator.IsAtEnd() ) { if ( inputIterator.Get() != 0 ) { outputIterator.Set( overwritevalue ); } ++outputIterator; ++inputIterator; } }
static Pointer mitk::ContourUtils::New | ( | ) | [static] |
Referenced by mitk::CorrectorAlgorithm::TobiasHeimannCorrectionAlgorithm().
mitk::Contour::Pointer mitk::ContourUtils::ProjectContourTo2DSlice | ( | Image * | slice, |
Contour * | contourIn3D, | ||
bool | correctionForIpSegmentation, | ||
bool | constrainToInside | ||
) |
Projects a contour onto an image point by point. Converts from world to index coordinates.
correctionForIpSegmentation | adds 0.5 to x and y index coordinates (difference between ipSegmentation and MITK contours) |
Definition at line 33 of file mitkContourUtils.cpp.
References mitk::Contour::GetContourPath(), mitk::BaseData::GetGeometry(), mitk::Geometry3D::IsIndexInside(), MITK_DEBUG, MITK_INFO, mitk::Contour::New(), and mitk::Geometry3D::WorldToIndex().
{ if ( !slice || !contourIn3D ) return NULL; Contour::Pointer projectedContour = Contour::New(); const Contour::PathType::VertexListType* pointsIn3D = contourIn3D->GetContourPath()->GetVertexList(); const Geometry3D* sliceGeometry = slice->GetGeometry(); for ( Contour::PathType::VertexListType::const_iterator iter = pointsIn3D->begin(); iter != pointsIn3D->end(); ++iter ) { Contour::PathType::VertexType currentPointIn3DITK = *iter; Point3D currentPointIn3D; for (int i = 0; i < 3; ++i) currentPointIn3D[i] = currentPointIn3DITK[i]; Point3D projectedPointIn2D; projectedPointIn2D.Fill(0.0); sliceGeometry->WorldToIndex( currentPointIn3D, projectedPointIn2D ); MITK_DEBUG << "world point " << currentPointIn3D << " in index is " << projectedPointIn2D; if ( !sliceGeometry->IsIndexInside( projectedPointIn2D ) && constrainToInside ) { MITK_INFO << "**" << currentPointIn3D << " is " << projectedPointIn2D << " --> correct it (TODO)" << std::endl; } projectedContour->AddVertex( projectedPointIn2D ); } return projectedContour; }