From f34fdef46fa656a1eb32271c0b9bf7d81bc7fc35 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 7 Jul 2010 13:39:07 +0000 Subject: [PATCH] relative position 2D slice by slice (attempt) --- itk/clitkSliceBySliceRelativePositionFilter.h | 105 +++++++++ ...litkSliceBySliceRelativePositionFilter.txx | 203 ++++++++++++++++++ 2 files changed, 308 insertions(+) create mode 100644 itk/clitkSliceBySliceRelativePositionFilter.h create mode 100644 itk/clitkSliceBySliceRelativePositionFilter.txx diff --git a/itk/clitkSliceBySliceRelativePositionFilter.h b/itk/clitkSliceBySliceRelativePositionFilter.h new file mode 100644 index 0000000..01f9cd9 --- /dev/null +++ b/itk/clitkSliceBySliceRelativePositionFilter.h @@ -0,0 +1,105 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKSLICEBYSLICERELATIVEPOSITIONFILTER_H +#define CLITKSLICEBYSLICERELATIVEPOSITIONFILTER_H + +// clitk +#include "clitkFilterBase.h" + +namespace clitk { + + //-------------------------------------------------------------------- + /* + Perform Relative Position filtering in a slice by slice manner. + */ + //-------------------------------------------------------------------- + + template + class ITK_EXPORT SliceBySliceRelativePositionFilter: + public clitk::FilterBase, + public itk::ImageToImageFilter + { + + public: + /** Standard class typedefs. */ + typedef itk::ImageToImageFilter Superclass; + typedef SliceBySliceRelativePositionFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(SliceBySliceRelativePositionFilter, ImageToImageFilter); + FILTERBASE_INIT; + + /** Some convenient typedefs. */ + typedef typename ImageType::ConstPointer ImageConstPointer; + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::SpacingType SpacingType; + typedef typename ImageType::SizeType SizeType; + + /** ImageDimension constants */ + itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); + typedef itk::Image FloatImageType; + + /** Input : initial image and object */ + void SetInput(const ImageType * image); + void SetInputObject(const ImageType * image); + + // Options + itkGetConstMacro(Direction, int); + itkSetMacro(Direction, int); + itkGetConstMacro(ObjectBackgroundValue, PixelType); + itkSetMacro(ObjectBackgroundValue, PixelType); + + protected: + SliceBySliceRelativePositionFilter(); + virtual ~SliceBySliceRelativePositionFilter() {} + + int m_Direction; + PixelType m_ObjectBackgroundValue; + + virtual void GenerateOutputInformation(); + virtual void GenerateInputRequestedRegion(); + virtual void GenerateData(); + + ImagePointer input; + ImagePointer object; + ImagePointer m_working_input; + ImagePointer m_working_object; + + private: + SliceBySliceRelativePositionFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkSliceBySliceRelativePositionFilter.txx" +#endif + +#endif diff --git a/itk/clitkSliceBySliceRelativePositionFilter.txx b/itk/clitkSliceBySliceRelativePositionFilter.txx new file mode 100644 index 0000000..af9c4c5 --- /dev/null +++ b/itk/clitkSliceBySliceRelativePositionFilter.txx @@ -0,0 +1,203 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +// clitk +#include "clitkSegmentationUtils.h" +// #include "clitkBooleanOperatorLabelImageFilter.h" +// #include "clitkAutoCropFilter.h" +// #include "clitkResampleImageWithOptionsFilter.h" +// #include "clitkBooleanOperatorLabelImageFilter.h" +#include "clitkExtractSliceFilter.h" + +// // itk +// #include +// #include "itkStatisticsLabelMapFilter.h" +// #include "itkLabelImageToStatisticsLabelMapFilter.h" +// #include "itkRegionOfInterestImageFilter.h" +// #include "itkBinaryThresholdImageFilter.h" +// #include "itkBinaryErodeImageFilter.h" +// #include "itkBinaryBallStructuringElement.h" + +// // itk [Bloch et al] +// #include "RelativePositionPropImageFilter.h" + +//-------------------------------------------------------------------- +template +clitk::SliceBySliceRelativePositionFilter:: +SliceBySliceRelativePositionFilter(): + clitk::FilterBase(), + itk::ImageToImageFilter() +{ + this->SetNumberOfRequiredInputs(2); + SetDirection(2); + SetObjectBackgroundValue(0); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +SetInput(const ImageType * image) { + // Process object is not const-correct so the const casting is required. + this->SetNthInput(0, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +SetInputObject(const ImageType * image) { + // Process object is not const-correct so the const casting is required. + this->SetNthInput(1, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +GenerateOutputInformation() { + ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImagePointer outputImage = this->GetOutput(0); + outputImage->SetRegions(input->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +GenerateInputRequestedRegion() { + // Call default + itk::ImageToImageFilter::GenerateInputRequestedRegion(); + // Get input pointers and set requested region to common region + ImagePointer input1 = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImagePointer input2 = dynamic_cast(itk::ProcessObject::GetInput(1)); + input1->SetRequestedRegion(input1->GetLargestPossibleRegion()); + input2->SetRequestedRegion(input2->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +GenerateData() { + // Get input pointer + input = dynamic_cast(itk::ProcessObject::GetInput(0)); + object = dynamic_cast(itk::ProcessObject::GetInput(1)); + + //-------------------------------------------------------------------- + // Resample object to the same spacing than input + if (!clitk::HaveSameSpacing(object, input)) { + StartNewStep("Resample object to the same spacing than input"); + m_working_object = clitk::ResampleImageSpacing(object, input->GetSpacing()); + StopCurrentStep(m_working_object); + } + else { + DD("no resampling"); + m_working_object = object; + } + + //-------------------------------------------------------------------- + // Pad object to the same size than input + if (!clitk::HaveSameSizeAndSpacing(m_working_object, input)) { + StartNewStep("Pad object to the same size than input"); + m_working_object = clitk::EnlargeImageLike(m_working_object, + input, + GetObjectBackgroundValue()); + StopCurrentStep(m_working_object); + } + else { + DD("no pad"); + } + + /* + + + //-------------------------------------------------------------------- + // Extract input slices + StartNewStep("Extract input slices"); + typedef clitk::ExtractSliceFilter ExtractSliceFilterType; + typename ExtractSliceFilterType::Pointer extractSliceFilter = Extractslicefilter::New(); + extractSliceFilter->SetInput(input); + extractSliceFilter->SetDirection(GetDirection()); + extractSliceFilter->Update(); + typedef typename ExtractSliceFilterType::SliceType SliceType; + std::vector & mInputSlices = extractSliceFilter->GetOutput(); + DD(mInputSlices.size()); + StopCurrentStep(mInputSlices[5]); + + //-------------------------------------------------------------------- + // Extract object slices + + StartNewStep("Extract object slices"); + extractSliceFilter = Extractslicefilter::New(); + extractSliceFilter->SetInput(input); + extractSliceFilter->SetDirection(GetDirection()); + extractSliceFilter->Update(); + std::vector & mObjectSlices = extractSliceFilter->GetOutput(); + DD(mObjectSlices.size()); + StopCurrentStep(mInputSlices[5]); + + + //-------------------------------------------------------------------- + // Perform slice by slice relative position + StartNewStep("Perform slice by slice relative position"); + for(int i=0; i RelPosFilterType; + typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New(); + relPosFilter->VerboseStepOff(); + relPosFilter->WriteStepOff(); + relPosFilter->SetInput(mInputSlices[i]); + relPosFilter->SetInputObject(mObjectSlices[i]); + relPosFilter->SetOrientationType(GetOrientationType()); + relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); + relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold()); + relPosFilter->Update(); + mInputSlices[i] = relPosFilter->GetOutput(); + } + typedef itk::JoinSeriesImageFilter JointSeriesFilterType; + typename JointSeriesFilterType::Pointer jointFilter = JointSeriesFilterType::New(); + for(int i=0; iSetInput(i, mInputSlices[i]); + } + m_working_input = jointFilter->GetOutput(); + DD(m_working_input->GetSpacing()); + DD(m_working_input->GetOrigin()); + StopCurrentStep(m_working_input); + + */ + + + //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + // Final Step -> set output + this->SetNthOutput(0, m_working_input); + return; +} +//-------------------------------------------------------------------- + -- 2.47.1