X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkSliceBySliceRelativePositionFilter.txx;h=6a4b0f49ab507a089842ef723ab58f169f3ac61f;hb=90b2bcd02606cb901955c074cfe9c13dc48d12f8;hp=bdffecb71bc295f1b9590e3b046a229634dfc31a;hpb=a89d8140714c44dd29d96f6482dd90c40ad175b4;p=clitk.git diff --git a/itk/clitkSliceBySliceRelativePositionFilter.txx b/itk/clitkSliceBySliceRelativePositionFilter.txx index bdffecb..6a4b0f4 100644 --- a/itk/clitkSliceBySliceRelativePositionFilter.txx +++ b/itk/clitkSliceBySliceRelativePositionFilter.txx @@ -28,18 +28,15 @@ template clitk::SliceBySliceRelativePositionFilter:: SliceBySliceRelativePositionFilter(): - clitk::FilterBase(), - itk::ImageToImageFilter() + clitk::AddRelativePositionConstraintToLabelImageFilter() { - this->SetNumberOfRequiredInputs(2); SetDirection(2); - SetObjectBackgroundValue(0); - SetFuzzyThreshold(0.6); - SetOrientationTypeString("Left"); - SetIntermediateSpacing(10); - ResampleBeforeRelativePositionFilterOff(); UniqueConnectedComponentBySliceOff(); - NotFlagOff(); + SetIgnoreEmptySliceObjectFlag(false); + UseASingleObjectConnectedComponentBySliceFlagOn(); + this->VerboseStepFlagOff(); + this->WriteStepFlagOff(); + this->SetCombineWithOrFlag(false); } //-------------------------------------------------------------------- @@ -68,6 +65,27 @@ SetInputObject(const ImageType * image) //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +PrintOptions() +{ + DD(this->GetDirection()); + DD((int)this->GetObjectBackgroundValue()); + DDV(this->GetOrientationTypeString(), (uint)this->GetNumberOfAngles()); + DD(this->GetIntermediateSpacingFlag()); + DD(this->GetIntermediateSpacing()); + DD(this->GetFuzzyThreshold()); + DD(this->GetUniqueConnectedComponentBySlice()); + DD(this->GetAutoCropFlag()); + DD(this->GetInverseOrientationFlag()); + DD(this->GetRemoveObjectFlag()); + DD(this->GetCombineWithOrFlag()); +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template void @@ -91,6 +109,10 @@ void clitk::SliceBySliceRelativePositionFilter:: GenerateOutputInformation() { + if (this->GetVerboseOptionFlag()) { + PrintOptions(); + } + // Get input pointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); object = dynamic_cast(itk::ProcessObject::GetInput(1)); @@ -98,9 +120,9 @@ GenerateOutputInformation() //-------------------------------------------------------------------- // Resample object to the same spacing than input if (!clitk::HaveSameSpacing(object, input)) { - StartNewStep("Resample object to the same spacing than input"); + this->StartNewStep("Resample object to the same spacing than input"); m_working_object = clitk::ResampleImageSpacing(object, input->GetSpacing()); - StopCurrentStep(m_working_object); + this->template StopCurrentStep(m_working_object); } else { m_working_object = object; @@ -109,11 +131,11 @@ GenerateOutputInformation() //-------------------------------------------------------------------- // Pad object to the same size than input if (!clitk::HaveSameSizeAndSpacing(m_working_object, input)) { - StartNewStep("Pad object to the same size than input"); + this->StartNewStep("Pad object to the same size than input"); m_working_object = clitk::ResizeImageLike(m_working_object, - input, - GetObjectBackgroundValue()); - StopCurrentStep(m_working_object); + input, + this->GetObjectBackgroundValue()); + this->template StopCurrentStep(m_working_object); } else { } @@ -128,7 +150,7 @@ GenerateOutputInformation() //-------------------------------------------------------------------- // Extract input slices - StartNewStep("Extract input slices"); + this->StartNewStep("Extract input slices"); typedef clitk::ExtractSliceFilter ExtractSliceFilterType; typename ExtractSliceFilterType::Pointer extractSliceFilter = ExtractSliceFilterType::New(); extractSliceFilter->SetInput(input); @@ -137,74 +159,81 @@ GenerateOutputInformation() typedef typename ExtractSliceFilterType::SliceType SliceType; std::vector mInputSlices; extractSliceFilter->GetOutputSlices(mInputSlices); - StopCurrentStep(mInputSlices[0]); + this->template StopCurrentStep(mInputSlices[0]); //-------------------------------------------------------------------- // Extract object slices - StartNewStep("Extract object slices"); + this->StartNewStep("Extract object slices"); extractSliceFilter = ExtractSliceFilterType::New(); extractSliceFilter->SetInput(m_working_object);//object); extractSliceFilter->SetDirection(GetDirection()); extractSliceFilter->Update(); std::vector mObjectSlices; extractSliceFilter->GetOutputSlices(mObjectSlices); - StopCurrentStep(mObjectSlices[0]); + this->template StopCurrentStep(mObjectSlices[0]); //-------------------------------------------------------------------- // Perform slice by slice relative position - StartNewStep("Perform slice by slice relative position"); + this->StartNewStep("Perform slice by slice relative position"); for(unsigned int i=0; i(mObjectSlices[i], 0, true, 1); - mObjectSlices[i] = KeepLabels(mObjectSlices[i], 0, 1, 1, 1, true); - - // Relative position - typedef clitk::AddRelativePositionConstraintToLabelImageFilter RelPosFilterType; - typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New(); - relPosFilter->VerboseStepOff(); - relPosFilter->WriteStepOff(); - relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); - relPosFilter->SetInput(mInputSlices[i]); - relPosFilter->SetInputObject(mObjectSlices[i]); - relPosFilter->SetNotFlag(GetNotFlag()); - relPosFilter->SetOrientationTypeString(this->GetOrientationTypeString()); - relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing()); - relPosFilter->SetResampleBeforeRelativePositionFilter(this->GetResampleBeforeRelativePositionFilter()); - relPosFilter->SetFuzzyThreshold(this->GetFuzzyThreshold()); - relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop - relPosFilter->Update(); - mInputSlices[i] = relPosFilter->GetOutput(); - - // Select main CC if needed - if (GetUniqueConnectedComponentBySlice()) { - mInputSlices[i] = Labelize(mInputSlices[i], 0, true, 1); - mInputSlices[i] = KeepLabels(mInputSlices[i], 0, 1, 1, 1, true); - } + + // Count the number of CCL (allow to ignore empty slice) + int nb=0; + mObjectSlices[i] = LabelizeAndCountNumberOfObjects(mObjectSlices[i], 0, true, 1, nb); + if ((!GetIgnoreEmptySliceObjectFlag()) || (nb!=0)) { - } + // Select or not a single CCL ? + if (GetUseASingleObjectConnectedComponentBySliceFlag()) { + mObjectSlices[i] = KeepLabels(mObjectSlices[i], 0, 1, 1, 1, true); + } - typedef itk::JoinSeriesImageFilter JoinSeriesFilterType; - typename JoinSeriesFilterType::Pointer joinFilter = JoinSeriesFilterType::New(); - joinFilter->SetOrigin(input->GetOrigin()[GetDirection()]); - joinFilter->SetSpacing(input->GetSpacing()[GetDirection()]); - for(unsigned int i=0; iPushBackInput(mInputSlices[i]); + // Relative position + typedef clitk::AddRelativePositionConstraintToLabelImageFilter RelPosFilterType; + typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New(); + + relPosFilter->VerboseStepFlagOff(); + relPosFilter->WriteStepFlagOff(); + relPosFilter->SetBackgroundValue(this->GetBackgroundValue()); + relPosFilter->SetInput(mInputSlices[i]); + relPosFilter->SetInputObject(mObjectSlices[i]); + relPosFilter->SetRemoveObjectFlag(this->GetRemoveObjectFlag()); + for(int j=0; jGetNumberOfAngles(); j++) { + relPosFilter->AddOrientationTypeString(this->GetOrientationTypeString(j)); + } + relPosFilter->SetInverseOrientationFlag(this->GetInverseOrientationFlag()); + //relPosFilter->SetOrientationType(this->GetOrientationType()); + relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing()); + relPosFilter->SetIntermediateSpacingFlag(this->GetIntermediateSpacingFlag()); + relPosFilter->SetFuzzyThreshold(this->GetFuzzyThreshold()); + relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop + relPosFilter->SetCombineWithOrFlag(this->GetCombineWithOrFlag()); + relPosFilter->Update(); + mInputSlices[i] = relPosFilter->GetOutput(); + + // Select main CC if needed + if (GetUniqueConnectedComponentBySlice()) { + mInputSlices[i] = Labelize(mInputSlices[i], 0, true, 1); + mInputSlices[i] = KeepLabels(mInputSlices[i], 0, 1, 1, 1, true); + } + + } } - joinFilter->Update(); - m_working_input = joinFilter->GetOutput(); - StopCurrentStep(m_working_input); + + // Join the slices + m_working_input = clitk::JoinSlices(mInputSlices, input, GetDirection()); + this->template StopCurrentStep(m_working_input); //-------------------------------------------------------------------- // Step 7: autocrop - if (GetAutoCropFlag()) { - StartNewStep("Final AutoCrop"); + if (this->GetAutoCropFlag()) { + this->StartNewStep("Final AutoCrop"); typedef clitk::AutoCropFilter CropFilterType; typename CropFilterType::Pointer cropFilter = CropFilterType::New(); cropFilter->SetInput(m_working_input); cropFilter->ReleaseDataFlagOff(); cropFilter->Update(); m_working_input = cropFilter->GetOutput(); - StopCurrentStep(m_working_input); + this->template StopCurrentStep(m_working_input); } // Update output info