X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkAddRelativePositionConstraintToLabelImageFilter.txx;h=c97ba0ea915b4aef1bfd79c3b5611906c9d1f1cc;hb=738abae55fb33a7c77843a9d84bc14d5439bff1a;hp=e25f98b829fa3c65ed497f5fb5ffd73de863a066;hpb=1d616cc7be31f7195c8bba4142e02350cd2fb958;p=clitk.git diff --git a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx index e25f98b..c97ba0e 100644 --- a/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx +++ b/itk/clitkAddRelativePositionConstraintToLabelImageFilter.txx @@ -33,11 +33,7 @@ #include #include #include -#if ITK_VERSION_MAJOR >= 4 - #include -#else - #include -#endif +#include // itk [Bloch et al] #include "RelativePositionPropImageFilter.h" @@ -63,6 +59,9 @@ AddRelativePositionConstraintToLabelImageFilter(): VerboseStepFlagOff(); WriteStepFlagOff(); FuzzyMapOnlyFlagOff(); + FastFlagOff(); + SetRadius(2.0); + SetK1(vcl_acos(-1.0)/2); } //-------------------------------------------------------------------- @@ -356,14 +355,14 @@ GenerateData() //-------------------------------------------------------------------- // Step 1 : resample if (m_IntermediateSpacingFlag) { - StartNewStep("Resample object to intermediate spacing"); + StartNewStep("Resample object to intermediate spacing (" + toString(m_IntermediateSpacing) + ")"); typedef clitk::ResampleImageWithOptionsFilter ResampleFilterType; typename ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New(); resampleFilter->SetInput(working_image); resampleFilter->SetDefaultPixelValue(0); resampleFilter->SetOutputIsoSpacing(m_IntermediateSpacing); resampleFilter->SetGaussianFilteringEnabled(false); - // resampleFilter->SetVerboseOptions(true); + //resampleFilter->SetVerboseOptions(true); resampleFilter->Update(); working_image = resampleFilter->GetOutput(); StopCurrentStep(working_image); @@ -380,13 +379,14 @@ GenerateData() for(int i=0; iSetFast(GetFastFlag()); + relPosFilter->SetRadius(GetRadius()); relPosFilter->SetInput(working_image); relPosFilter->SetAlpha1(m_Angle1[i]); // xy plane relPosFilter->SetAlpha2(m_Angle2[i]); - relPosFilter->SetK1(M_PI/2.0); // Opening parameter, default = pi/2 - relPosFilter->SetFast(true); - relPosFilter->SetRadius(1); // seems sufficient in this case + relPosFilter->SetK1(GetK1());// M_PI/2.0); // Opening parameter, default = pi/2 // relPosFilter->SetVerboseProgress(true); + relPosFilter->Update(); relPos = relPosFilter->GetOutput(); @@ -410,15 +410,9 @@ GenerateData() // Divide by the number of relpos if (GetNumberOfAngles() != 1) { -#if ITK_VERSION_MAJOR >= 4 typedef itk::DivideImageFilter DivideFilter; typename DivideFilter::Pointer divideFilter = DivideFilter::New(); divideFilter->SetConstant2(GetNumberOfAngles()); -#else - typedef itk::DivideByConstantImageFilter DivideFilter; - typename DivideFilter::Pointer divideFilter = DivideFilter::New(); - divideFilter->SetConstant(GetNumberOfAngles()); -#endif divideFilter->SetInput(m_FuzzyMap); divideFilter->Update(); m_FuzzyMap = divideFilter->GetOutput(); @@ -426,7 +420,44 @@ GenerateData() relPos = m_FuzzyMap; StopCurrentStep(relPos); - if (GetFuzzyMapOnlyFlag()) return; + if (GetFuzzyMapOnlyFlag()) { + // If the spacing is used, recompute fuzzy map with the input size/spacing + if (m_IntermediateSpacingFlag) { + StartNewStep("Resample FuzzyMap to come back to the same sampling than input"); + typedef clitk::ResampleImageWithOptionsFilter ResampleFilterType; + typename ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New(); + resampleFilter->SetDefaultPixelValue(0.0); //Default fuzzymap value FIXME + resampleFilter->SetInput(relPos); + resampleFilter->SetOutputSpacing(input->GetSpacing()); + resampleFilter->SetGaussianFilteringEnabled(false); + resampleFilter->Update(); + relPos = m_FuzzyMap = resampleFilter->GetOutput(); + StopCurrentStep(relPos); + + // Need to put exactly the same size + if (relPos->GetLargestPossibleRegion() != input->GetLargestPossibleRegion()) { + StartNewStep("Pad to get the same size than input"); + typename FloatImageType::Pointer temp = FloatImageType::New(); + temp->CopyInformation(input); + temp->SetRegions(input->GetLargestPossibleRegion()); // Do not forget !! + temp->Allocate(); + temp->FillBuffer(0.0); // Default fuzzymap value FIXME + typename PasteFloatFilterType::Pointer padFilter2 = PasteFloatFilterType::New(); + padFilter2->SetSourceImage(relPos); + padFilter2->SetDestinationImage(temp); + padFilter2->SetDestinationIndex(input->GetLargestPossibleRegion().GetIndex()); + padFilter2->SetSourceRegion(relPos->GetLargestPossibleRegion()); + padFilter2->Update(); + relPos = padFilter2->GetOutput(); + StopCurrentStep(relPos); + m_FuzzyMap = relPos; + } + } + else { + StopCurrentStep(relPos); + } + return; + } //-------------------------------------------------------------------- //--------------------------------------------------------------------