X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractMediastinumFilter.txx;fp=segmentation%2FclitkExtractMediastinumFilter.txx;h=b5535cf23af74e19f32275fca7ba5cc89e9fe8b1;hb=e008d74b0ecdc4ca2eaae8c429901a78f9ef5c31;hp=0000000000000000000000000000000000000000;hpb=bb436e8274c510438ccb5ec1df531675321341bb;p=clitk.git diff --git a/segmentation/clitkExtractMediastinumFilter.txx b/segmentation/clitkExtractMediastinumFilter.txx new file mode 100644 index 0000000..b5535cf --- /dev/null +++ b/segmentation/clitkExtractMediastinumFilter.txx @@ -0,0 +1,263 @@ +/*========================================================================= + 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 CLITKEXTRACTMEDIASTINUMFILTER_TXX +#define CLITKEXTRACTMEDIASTINUMFILTER_TXX + +// clitk +#include "clitkCommon.h" +#include "clitkExtractMediastinumFilter.h" +#include "clitkAddRelativePositionConstraintToLabelImageFilter.h" +#include "clitkSegmentationFunctions.h" + +// itk +#include +#include "itkStatisticsLabelMapFilter.h" +#include "itkLabelImageToStatisticsLabelMapFilter.h" +#include "itkRegionOfInterestImageFilter.h" +#include "itkBinaryThresholdImageFilter.h" + +// itk ENST +#include "RelativePositionPropImageFilter.h" + +//-------------------------------------------------------------------- +template +clitk::ExtractMediastinumFilter:: +ExtractMediastinumFilter(): + clitk::FilterBase(), + itk::ImageToImageFilter() +{ + this->SetNumberOfRequiredInputs(3); + + SetBackgroundValuePatient(0); + SetBackgroundValueLung(0); + SetBackgroundValueBones(0); + SetForegroundValueLeftLung(1); + SetForegroundValueRightLung(2); + SetBackgroundValue(0); + SetForegroundValue(1); + + SetIntermediateSpacing(6); + SetFuzzyThreshold1(0.6); + SetFuzzyThreshold2(0.7); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractMediastinumFilter:: +SetInputPatientLabelImage(const TImageType * image, ImagePixelType bg) { + this->SetNthInput(0, const_cast(image)); + m_BackgroundValuePatient = bg; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractMediastinumFilter:: +SetInputLungLabelImage(const TImageType * image, ImagePixelType bg, + ImagePixelType fgLeft, ImagePixelType fgRight) { + this->SetNthInput(1, const_cast(image)); + m_BackgroundValueLung = bg; + m_ForegroundValueLeftLung = fgLeft; + m_ForegroundValueRightLung = fgRight; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractMediastinumFilter:: +SetInputBonesLabelImage(const TImageType * image, ImagePixelType bg) { + this->SetNthInput(2, const_cast(image)); + m_BackgroundValueBones = bg; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void +clitk::ExtractMediastinumFilter:: +SetArgsInfo(ArgsInfoType mArgsInfo) +{ + SetVerboseOption_GGO(mArgsInfo); + SetVerboseStep_GGO(mArgsInfo); + SetWriteStep_GGO(mArgsInfo); + SetVerboseWarningOff_GGO(mArgsInfo); + + SetBackgroundValuePatient_GGO(mArgsInfo); + SetBackgroundValueLung_GGO(mArgsInfo); + SetBackgroundValueBones_GGO(mArgsInfo); + + SetForegroundValueLeftLung_GGO(mArgsInfo); + SetForegroundValueRightLung_GGO(mArgsInfo); + + SetIntermediateSpacing_GGO(mArgsInfo); + SetFuzzyThreshold1_GGO(mArgsInfo); + SetFuzzyThreshold2_GGO(mArgsInfo); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractMediastinumFilter:: +GenerateOutputInformation() { + ImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImagePointer outputImage = this->GetOutput(0); + outputImage->SetRegions(outputImage->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractMediastinumFilter:: +GenerateInputRequestedRegion() { + // Call default + Superclass::GenerateInputRequestedRegion(); + // Get input pointers + ImagePointer patient = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImagePointer lung = dynamic_cast(itk::ProcessObject::GetInput(1)); + ImagePointer bones = dynamic_cast(itk::ProcessObject::GetInput(2)); + + patient->SetRequestedRegion(patient->GetLargestPossibleRegion()); + lung->SetRequestedRegion(lung->GetLargestPossibleRegion()); + bones->SetRequestedRegion(bones->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::ExtractMediastinumFilter:: +GenerateData() { + // Get input pointers + ImageConstPointer patient = dynamic_cast(itk::ProcessObject::GetInput(0)); + ImageConstPointer lung = dynamic_cast(itk::ProcessObject::GetInput(1)); + ImageConstPointer bones = dynamic_cast(itk::ProcessObject::GetInput(2)); + + // Get output pointer + ImagePointer output; + + // Step 1: patient minus lungs, minus bones + StartNewStep("Patient contours minus lungs and minus bones"); + typedef clitk::BooleanOperatorLabelImageFilter BoolFilterType; + typename BoolFilterType::Pointer boolFilter = BoolFilterType::New(); + boolFilter->InPlaceOn(); + boolFilter->SetInput1(patient); + boolFilter->SetInput2(lung); + boolFilter->SetOperationType(BoolFilterType::AndNot); + boolFilter->Update(); + boolFilter->SetInput1(boolFilter->GetOutput()); + boolFilter->SetInput2(bones); + boolFilter->SetOperationType(BoolFilterType::AndNot); + boolFilter->Update(); + output = boolFilter->GetOutput(); + + output = clitk::AutoCrop(output, GetBackgroundValue()); + ////autoCropFilter->GetOutput(); typedef clitk::AutoCropFilter CropFilterType; + //typename CropFilterType::Pointer cropFilter = CropFilterType::New(); + //cropFilter->SetInput(output); + //cropFilter->Update(); + //output = cropFilter->GetOutput(); + + this->template StopCurrentStep(output); + + // Step 2: LR limits from lung (need separate lung ?) + StartNewStep("Left/Right limits with lungs"); + typedef clitk::AddRelativePositionConstraintToLabelImageFilter RelPosFilterType; + typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New(); + relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); + relPosFilter->VerboseStepOff(); + relPosFilter->WriteStepOff(); + relPosFilter->SetInput(output); + relPosFilter->SetInputObject(lung); + relPosFilter->SetOrientationType(RelPosFilterType::LeftTo); + relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); + relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold1()); + relPosFilter->Update(); + output = relPosFilter->GetOutput(); + + relPosFilter->SetInput(output); + relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); + relPosFilter->VerboseStepOff(); + relPosFilter->WriteStepOff(); + relPosFilter->SetInputObject(lung); + relPosFilter->SetOrientationType(RelPosFilterType::RightTo); + relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); + relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold1()); + relPosFilter->Update(); + output = relPosFilter->GetOutput(); + this->template StopCurrentStep(output); + + // Step 3: AP limits from bones + StartNewStep("Ant/Post limits with bones"); + relPosFilter->SetCurrentStepNumber(0); + relPosFilter->ResetPipeline();// = RelPosFilterType::New(); + relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); + relPosFilter->VerboseStepOff(); + relPosFilter->WriteStepOff(); + relPosFilter->SetInput(output); + relPosFilter->SetInputObject(bones); + relPosFilter->SetOrientationType(RelPosFilterType::AntTo); + relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); + relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold2()); + relPosFilter->Update(); + + relPosFilter->SetInput(relPosFilter->GetOutput()); + relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); + relPosFilter->VerboseStepOff(); + relPosFilter->WriteStepOff(); + relPosFilter->SetInputObject(bones); + relPosFilter->SetOrientationType(RelPosFilterType::PostTo); + relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); + relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold2()); + relPosFilter->Update(); + output = relPosFilter->GetOutput(); + this->template StopCurrentStep(output); + + // Get CCL + output = clitk::Labelize(output, GetBackgroundValue(), true, 100); + // output = RemoveLabels(output, BG, param->GetLabelsToRemove()); + output = clitk::KeepLabels(output, GetBackgroundValue(), + GetForegroundValue(), 1, 1, 0); + + output = clitk::AutoCrop(output, GetBackgroundValue()); + // cropFilter = CropFilterType::New(); + //cropFilter->SetInput(output); + //cropFilter->Update(); + //output = cropFilter->GetOutput(); + + // Final Step -> set output + this->SetNthOutput(0, output); +} +//-------------------------------------------------------------------- + + +#endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX