From: dsarrut Date: Wed, 15 Dec 2010 08:48:37 +0000 (+0000) Subject: add autocrop and options X-Git-Tag: v1.2.0~290 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a89d8140714c44dd29d96f6482dd90c40ad175b4;p=clitk.git add autocrop and options --- diff --git a/itk/clitkSliceBySliceRelativePositionFilter.h b/itk/clitkSliceBySliceRelativePositionFilter.h index 219f867..bc8ae97 100644 --- a/itk/clitkSliceBySliceRelativePositionFilter.h +++ b/itk/clitkSliceBySliceRelativePositionFilter.h @@ -76,23 +76,39 @@ namespace clitk { itkGetConstMacro(ObjectBackgroundValue, PixelType); itkSetMacro(ObjectBackgroundValue, PixelType); - itkSetMacro(OrientationType, OrientationTypeEnumeration); - itkGetConstMacro(OrientationType, OrientationTypeEnumeration); + itkSetMacro(OrientationTypeString, std::string); + itkGetConstMacro(OrientationTypeString, std::string); + itkGetConstMacro(ResampleBeforeRelativePositionFilter, bool); itkSetMacro(ResampleBeforeRelativePositionFilter, bool); itkBooleanMacro(ResampleBeforeRelativePositionFilter); + itkGetConstMacro(IntermediateSpacing, double); itkSetMacro(IntermediateSpacing, double); + itkGetConstMacro(FuzzyThreshold, double); itkSetMacro(FuzzyThreshold, double); + itkGetConstMacro(UniqueConnectedComponentBySlice, bool); + itkSetMacro(UniqueConnectedComponentBySlice, bool); + itkBooleanMacro(UniqueConnectedComponentBySlice); + + itkGetConstMacro(AutoCropFlag, bool); + itkSetMacro(AutoCropFlag, bool); + itkBooleanMacro(AutoCropFlag); + + itkGetConstMacro(NotFlag, bool); + itkSetMacro(NotFlag, bool); + itkBooleanMacro(NotFlag); + protected: SliceBySliceRelativePositionFilter(); virtual ~SliceBySliceRelativePositionFilter() {} int m_Direction; PixelType m_ObjectBackgroundValue; - OrientationTypeEnumeration m_OrientationType; + // OrientationTypeEnumeration m_OrientationType; + std::string m_OrientationTypeString; double m_IntermediateSpacing; double m_FuzzyThreshold; bool m_ResampleBeforeRelativePositionFilter; @@ -105,6 +121,9 @@ namespace clitk { ImagePointer object; ImagePointer m_working_input; ImagePointer m_working_object; + bool m_UniqueConnectedComponentBySlice; + bool m_NotFlag; + bool m_AutoCropFlag; private: SliceBySliceRelativePositionFilter(const Self&); //purposely not implemented diff --git a/itk/clitkSliceBySliceRelativePositionFilter.txx b/itk/clitkSliceBySliceRelativePositionFilter.txx index a8a79ec..bdffecb 100644 --- a/itk/clitkSliceBySliceRelativePositionFilter.txx +++ b/itk/clitkSliceBySliceRelativePositionFilter.txx @@ -19,6 +19,10 @@ // clitk #include "clitkSegmentationUtils.h" #include "clitkExtractSliceFilter.h" +#include "clitkResampleImageWithOptionsFilter.h" + +// itk +#include //-------------------------------------------------------------------- template @@ -31,9 +35,11 @@ SliceBySliceRelativePositionFilter(): SetDirection(2); SetObjectBackgroundValue(0); SetFuzzyThreshold(0.6); - SetOrientationType(RelPosFilterType::LeftTo); + SetOrientationTypeString("Left"); SetIntermediateSpacing(10); ResampleBeforeRelativePositionFilterOff(); + UniqueConnectedComponentBySliceOff(); + NotFlagOff(); } //-------------------------------------------------------------------- @@ -62,19 +68,6 @@ SetInputObject(const ImageType * 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 @@ -91,12 +84,12 @@ GenerateInputRequestedRegion() } //-------------------------------------------------------------------- - + //-------------------------------------------------------------------- template void clitk::SliceBySliceRelativePositionFilter:: -GenerateData() +GenerateOutputInformation() { // Get input pointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); @@ -110,7 +103,6 @@ GenerateData() StopCurrentStep(m_working_object); } else { - DD("no resampling"); m_working_object = object; } @@ -118,13 +110,12 @@ GenerateData() // 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, + m_working_object = clitk::ResizeImageLike(m_working_object, input, GetObjectBackgroundValue()); StopCurrentStep(m_working_object); } else { - DD("no pad"); } /* @@ -152,7 +143,7 @@ GenerateData() // Extract object slices StartNewStep("Extract object slices"); extractSliceFilter = ExtractSliceFilterType::New(); - extractSliceFilter->SetInput(object); + extractSliceFilter->SetInput(m_working_object);//object); extractSliceFilter->SetDirection(GetDirection()); extractSliceFilter->Update(); std::vector mObjectSlices; @@ -163,11 +154,7 @@ GenerateData() // Perform slice by slice relative position StartNewStep("Perform slice by slice relative position"); for(unsigned int i=0; iGetOrigin()); - // writeImage(mInputSlices[i], "inp"+clitk::toString(i)+".mhd"); - - // Select main CC in each object slice : this should be the main bronchus + // Select main CC in each object slice (required ?) mObjectSlices[i] = Labelize(mObjectSlices[i], 0, true, 1); mObjectSlices[i] = KeepLabels(mObjectSlices[i], 0, 1, 1, 1, true); @@ -179,53 +166,65 @@ GenerateData() relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); relPosFilter->SetInput(mInputSlices[i]); relPosFilter->SetInputObject(mObjectSlices[i]); - relPosFilter->SetOrientationType(this->GetOrientationType()); + relPosFilter->SetNotFlag(GetNotFlag()); + relPosFilter->SetOrientationTypeString(this->GetOrientationTypeString()); relPosFilter->SetIntermediateSpacing(this->GetIntermediateSpacing()); relPosFilter->SetResampleBeforeRelativePositionFilter(this->GetResampleBeforeRelativePositionFilter()); relPosFilter->SetFuzzyThreshold(this->GetFuzzyThreshold()); - relPosFilter->AutoCropOff(); // important ! because we join the slices after this loop + relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop relPosFilter->Update(); - // writeImage(relPosFilter->GetOutput(), "inp-after"+clitk::toString(i)+".mhd"); 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); + } + } - DD(this->GetIntermediateSpacing()); - DD(this->GetResampleBeforeRelativePositionFilter()); - DD("End slice"); 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; iGetLargestPossibleRegion().GetIndex()); -// DD(mInputSlices[i]->GetLargestPossibleRegion().GetSize()); -// DD(mInputSlices[i]->GetRequestedRegion().GetIndex()); -// DD(mInputSlices[i]->GetRequestedRegion().GetSize()); joinFilter->PushBackInput(mInputSlices[i]); - //SetInput(i, mInputSlices[i]); } - DD("before update"); joinFilter->Update(); - DD("after update"); m_working_input = joinFilter->GetOutput(); - - // Update the origin - DD(input->GetSpacing()); - DD(input->GetOrigin()); - DD(mInputSlices[0]->GetSpacing()); - DD(mInputSlices[0]->GetOrigin()); - DD(m_working_input->GetSpacing()); - DD(m_working_input->GetOrigin()); - // typename ImageType::PointType origin = m_working_input->GetOrigin(); -// origin[GetDirection()] = input->GetOrigin()[GetDirection()]; -// m_working_input->SetOrigin(origin); -// DD(m_working_input->GetOrigin()); StopCurrentStep(m_working_input); + //-------------------------------------------------------------------- + // Step 7: autocrop + if (GetAutoCropFlag()) { + 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); + } + + // Update output info + this->GetOutput(0)->SetRegions(m_working_input->GetLargestPossibleRegion()); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::SliceBySliceRelativePositionFilter:: +GenerateData() +{ + // Get input pointer //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Final Step -> set output - this->SetNthOutput(0, m_working_input); + //this->SetNthOutput(0, m_working_input); + this->GraftOutput(m_working_input); return; } //--------------------------------------------------------------------