From 410ea1ad6bfd20e6df12b7e4ac643e0dd42fc244 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Fri, 27 Apr 2012 11:25:13 +0200 Subject: [PATCH] option to auto-detect motion mask's initial ellipse --- segmentation/clitkMotionMask.ggo | 6 +- segmentation/clitkMotionMaskGenericFilter.h | 2 +- segmentation/clitkMotionMaskGenericFilter.txx | 103 +++++++++++++----- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/segmentation/clitkMotionMask.ggo b/segmentation/clitkMotionMask.ggo index f879a36..b9e9d1c 100644 --- a/segmentation/clitkMotionMask.ggo +++ b/segmentation/clitkMotionMask.ggo @@ -32,10 +32,12 @@ option "writeFeature" - "Write the combined feature image" string no section "Ellipsoide initialization" option "ellips" - "Input ellipsoide image (=1, at half resolution)" string no -option "offset" - "Offset for ellips center from body center of gravity (default= 0,-50,0 mm)" double no multiple -option "axes" - "Half axes of the ellips (default= 100,30,150)" double no multiple option "writeEllips" - "Write the initial ellipsoide image" string no option "writeDistMap" - "Write the distance map" string no +#defgroup "EllipseParams" groupdesc="an option of this group is required" required +option "ellipseAutoDetect" - "Auto-detect offset and axes of initial ellipse" flag off +option "offset" - "Offset for ellips center from body center of gravity (default= 0,-50,0 mm)" double no multiple +option "axes" - "Half axes of the ellips (default= 100,30,150)" double no multiple section "Ellipsoide growing" diff --git a/segmentation/clitkMotionMaskGenericFilter.h b/segmentation/clitkMotionMaskGenericFilter.h index dfab428..2a89fc7 100644 --- a/segmentation/clitkMotionMaskGenericFilter.h +++ b/segmentation/clitkMotionMaskGenericFilter.h @@ -118,7 +118,7 @@ protected: template typename itk::Image::Pointer Resample(typename itk::Image::Pointer input ); template - typename itk::Image::Pointer InitializeEllips( typename itk::Vector center, typename itk::Image::Pointer bones_low); + typename itk::Image::Pointer InitializeEllips( typename itk::Vector center, typename itk::Image::Pointer bones_low, typename itk::Image::Pointer lungs_low); template void UpdateWithDim(std::string PixelType); diff --git a/segmentation/clitkMotionMaskGenericFilter.txx b/segmentation/clitkMotionMaskGenericFilter.txx index 56fadac..992b6b8 100644 --- a/segmentation/clitkMotionMaskGenericFilter.txx +++ b/segmentation/clitkMotionMaskGenericFilter.txx @@ -27,6 +27,8 @@ * ===================================================*/ +#include "itkLabelImageToShapeLabelMapFilter.h" +#include "itkShapeLabelObject.h" namespace clitk { @@ -480,7 +482,7 @@ MotionMaskGenericFilter::Resample( typename itk::Image typename itk::Image::Pointer -MotionMaskGenericFilter::InitializeEllips( typename itk::Vector center, typename itk::Image::Pointer bones_low ) +MotionMaskGenericFilter::InitializeEllips( typename itk::Vector center, typename itk::Image::Pointer bones_low, typename itk::Image::Pointer lungs_low ) { // ImageTypes @@ -511,24 +513,72 @@ MotionMaskGenericFilter::InitializeEllips( typename itk::Vector offset; - if(m_ArgsInfo.offset_given== Dimension) { - for(unsigned int i=0; i centerEllips; + typename itk::Vector axes; + if (m_ArgsInfo.ellipseAutoDetect_flag) { + if(m_Verbose) { + std::cout<<"Auto-detecting intial ellipse..."< LabelImageToShapeLabelMapFilter; + typename LabelImageToShapeLabelMapFilter::Pointer label_filter = LabelImageToShapeLabelMapFilter::New(); + label_filter->SetInput(lungs_low); + label_filter->Update(); + + typename InternalImageType::SpacingType spacing = lungs_low->GetSpacing(); + typedef typename LabelImageToShapeLabelMapFilter::OutputImageType::LabelObjectType LabelType; + const LabelType* label = dynamic_cast(label_filter->GetOutput()->GetNthLabelObject(0)); + + + // try to guess ideal ellipse axes from the lungs' bounding box + typename LabelType::RegionType lung_bbox = label->GetRegion(); + axes[0] = 0.95*lung_bbox.GetSize()[0]*spacing[0]/2; + axes[1] = 0.3*lung_bbox.GetSize()[1]*spacing[1]/2; + axes[2] = 0.95*lung_bbox.GetSize()[2]*spacing[2]/2; + + // ellipse's center is the center of the lungs' bounding box + typename InternalImageType::PointType origin = lungs_low->GetOrigin(); + centerEllips[0] = origin[0] + (lung_bbox.GetIndex()[0] + lung_bbox.GetSize()[0]/2)*spacing[0]; + centerEllips[1] = origin[1] + (lung_bbox.GetIndex()[1] + lung_bbox.GetSize()[1]/2)*spacing[1]; + centerEllips[2] = origin[2] + (lung_bbox.GetIndex()[2] + lung_bbox.GetSize()[2]/2)*spacing[2]; + + if(m_Verbose) { + std::cout << "Ellipse center at " << centerEllips << std::endl; + std::cout << "Ellipse axes as " << axes << std::endl; + std::cout << "Lung's bounding box (index,size) " << lung_bbox.GetIndex() << lung_bbox.GetSize() << std::endl; + } } - itk::Vector centerEllips=center+offset; - if (m_Verbose) { - std::cout<<"Placing the center of the initial ellipsoide at (mm) "< offset; + if(m_ArgsInfo.offset_given== Dimension) { + for(unsigned int i=0; iAllocate(); ellips->FillBuffer(0); - // Axes - typename itk::Vector axes; - if (m_ArgsInfo.axes_given==Dimension) - for(unsigned int i=0; iGetLargestPossibleRegion()); itEllips.GoToBegin(); @@ -727,7 +766,7 @@ MotionMaskGenericFilter::UpdateWithDimAndPixelType() //---------------------------------------------------------------------------------------------------- // Ellipsoide initialization //---------------------------------------------------------------------------------------------------- - typename InternalImageType::Pointer m_Ellips= InitializeEllips(center,bones_low); + typename InternalImageType::Pointer m_Ellips= InitializeEllips(center,bones_low,lungs_low); //---------------------------------------------------------------------------------------------------- // Grow ellips @@ -1075,6 +1114,10 @@ MotionMaskGenericFilter::UpdateWithDimAndPixelType() distanceMapImageFilter->SetInsideIsPositive(false); if (m_Verbose) std::cout<<"Calculating distance map..."<Update(); + if (m_ArgsInfo.writeDistMap_given) { + writeImage(distanceMapImageFilter->GetOutput(), m_ArgsInfo.writeDistMap_arg, m_Verbose); + + } //--------------------------------- // Grow while monitoring lung volume coverage -- 2.45.1