#include "clitkSetBackgroundImageFilter.h"
#include "clitkDecomposeAndReconstructImageFilter.h"
#include "clitkAutoCropFilter.h"
+#include "clitkMemoryUsage.h"
// itk
#include "itkBinaryThresholdImageFilter.h"
#include "itkCastImageFilter.h"
//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+template <class TInputImageType>
+clitk::ExtractPatientFilter<TInputImageType>::
ExtractPatientFilter():
clitk::FilterBase(),
- itk::ImageToImageFilter<TInputImageType, TOutputImageType>()
+ clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
+ itk::ImageToImageFilter<TInputImageType, MaskImageType>()
{
this->SetNumberOfRequiredInputs(1);
SetBackgroundValue(0); // Must be zero
SetLastKeep(1);
// Step 4: OpenClose (option)
- FinalOpenCloseOn();
- AutoCropOff();
+ FinalOpenCloseOff();
+ AutoCropOn();
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
void
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractPatientFilter<TInputImageType>::
SetInput(const TInputImageType * image)
{
this->SetNthInput(0, const_cast<TInputImageType *>(image));
//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-template<class ArgsInfoType>
+template <class TInputImageType>
void
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
-SetArgsInfo(ArgsInfoType arg)
-{
- SetVerboseOption_GGO(arg);
- SetVerboseStep_GGO(arg);
- SetWriteStep_GGO(arg);
- SetVerboseWarningOff_GGO(arg);
-
- SetUpperThreshold_GGO(arg);
- SetLowerThreshold_GGO(arg);
-
- SetDecomposeAndReconstructDuringFirstStep_GGO(arg);
- SetRadius1_GGO(arg);
- SetMaximumNumberOfLabels1_GGO(arg);
- SetNumberOfNewLabels1_GGO(arg);
-
- SetDecomposeAndReconstructDuringSecondStep_GGO(arg);
- SetRadius2_GGO(arg);
- SetMaximumNumberOfLabels2_GGO(arg);
- SetNumberOfNewLabels2_GGO(arg);
-
- SetFirstKeep_GGO(arg);
- SetLastKeep_GGO(arg);
-
- SetFinalOpenClose_GGO(arg);
- SetAutoCrop_GGO(arg);
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-void
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractPatientFilter<TInputImageType>::
GenerateOutputInformation() {
+ clitk::PrintMemory(GetVerboseMemoryFlag(), "Initial memory"); // OK
+
Superclass::GenerateOutputInformation();
input = dynamic_cast<const TInputImageType*>(itk::ProcessObject::GetInput(0));
- // OutputImagePointer outputImage = this->GetOutput(0);
+ // MaskImagePointer outputImage = this->GetOutput(0);
// outputImage->SetRegions(input->GetLargestPossibleRegion());
// Get input pointers
typedef itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType> iBinarizeFilterType;
typename iBinarizeFilterType::Pointer binarizeFilter2 = iBinarizeFilterType::New();
binarizeFilter2->SetInput(working_image);
- binarizeFilter2->SetLowerThreshold(this->GetForegroundValue());
- binarizeFilter2->SetUpperThreshold(this->GetForegroundValue());
- binarizeFilter2 ->SetInsideValue(this->GetBackgroundValue());
- binarizeFilter2 ->SetOutsideValue(this->GetForegroundValue());
+ binarizeFilter2->SetLowerThreshold(GetFirstKeep());
+ binarizeFilter2->SetUpperThreshold(GetLastKeep());
+ binarizeFilter2 ->SetInsideValue(0);
+ binarizeFilter2 ->SetOutsideValue(1);
// binarizeFilter2 ->Update(); // NEEDED ?
typename ConnectFilterType::Pointer connectFilter2 = ConnectFilterType::New();
relabelFilter2->SetInput(connectFilter2->GetOutput());
relabelFilter2->Update();
working_image = relabelFilter2->GetOutput();
+
+ // Keep main label
+ working_image = KeepLabels<InternalImageType>
+ (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true);
StopCurrentStep<InternalImageType>(working_image);
//--------------------------------------------------------------------
StopCurrentStep<InternalImageType>(working_image);
}
- //--------------------------------------------------------------------
- //--------------------------------------------------------------------
- StartNewStep("Keep patient's labels");
- typename iBinarizeFilterType::Pointer binarizeFilter3 = iBinarizeFilterType::New();
- binarizeFilter3->SetInput(working_image);
- binarizeFilter3->SetLowerThreshold(GetFirstKeep());
- binarizeFilter3->SetUpperThreshold(GetLastKeep());
- binarizeFilter3 ->SetInsideValue(this->GetForegroundValue());
- binarizeFilter3 ->SetOutsideValue(this->GetBackgroundValue());
- binarizeFilter3->Update();
- working_image = binarizeFilter3->GetOutput();
- StopCurrentStep<InternalImageType>(working_image);
-
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// [Optional]
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Final Cast
- typedef itk::CastImageFilter<InternalImageType, OutputImageType> CastImageFilterType;
+ typedef itk::CastImageFilter<InternalImageType, MaskImageType> CastImageFilterType;
typename CastImageFilterType::Pointer caster= CastImageFilterType::New();
caster->SetInput(working_image);
caster->Update();
// [Optional]
if (GetAutoCrop()) {
StartNewStep("AutoCrop");
- typedef clitk::AutoCropFilter<OutputImageType> CropFilterType;
+ typedef clitk::AutoCropFilter<MaskImageType> CropFilterType;
typename CropFilterType::Pointer cropFilter = CropFilterType::New();
cropFilter->SetInput(output);
cropFilter->SetBackgroundValue(GetBackgroundValue());
cropFilter->Update();
output = cropFilter->GetOutput();
- StopCurrentStep<OutputImageType>(output);
+ StopCurrentStep<MaskImageType>(output);
}
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
void
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractPatientFilter<TInputImageType>::
GenerateData() {
- //this->SetNthOutput(0, output); // -> no because redo filter otherwise
+ // Final Graft
this->GraftOutput(output);
+ // Store image filename into AFDB
+ GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename());
+ WriteAFDB();
}
//--------------------------------------------------------------------