-
-
- //==============================================================================
- // Update with the pixel type
- //==============================================================================
- template <unsigned int Dimension, class InputPixelType>
- void
- MorphoMathGenericFilter::UpdateWithDimAndPixelType()
- {
-
- //---------------------------------
- // Define the images
- //---------------------------------
- typedef float InternalPixelType;
- typedef itk::Image<InputPixelType, Dimension> InputImageType;
- typedef itk::Image<InternalPixelType, Dimension> InternalImageType;
- typedef itk::Image<InputPixelType, Dimension> OutputImageType;
- typedef itk::ImageFileReader<InputImageType> FileReaderType;
- typename FileReaderType::Pointer fileReader=FileReaderType::New();
- fileReader->SetFileName(m_InputFileName);
- typedef itk::CastImageFilter<InputImageType, InternalImageType> InputCastImageFilterType;
- typename InputCastImageFilterType::Pointer caster = InputCastImageFilterType::New();
- caster->SetInput(fileReader->GetOutput());
- caster->Update();
- typename InternalImageType::Pointer input =caster->GetOutput();
-
-
- //---------------------------------
- // Find the type of action
- //---------------------------------
- typedef itk::ImageToImageFilter<InternalImageType, InternalImageType> ImageFilterType;
- typename ImageFilterType::Pointer filter;
-
- typedef itk::BinaryBallStructuringElement<InputPixelType,Dimension > KernelType;
- KernelType structuringElement;
- typename InternalImageType::SizeType radius;
- if (m_ArgsInfo.radius_given==Dimension)
- for (unsigned int i=0;i<Dimension;i++)
- {radius[i]=m_ArgsInfo.radius_arg[i];}
- else
- for (unsigned int i=0;i<Dimension;i++)
- radius[i]=m_ArgsInfo.radius_arg[0];
-
- structuringElement.SetRadius(radius);
- structuringElement.CreateStructuringElement();
-
- switch(m_ArgsInfo.type_arg)
- {
-
- case 0:
- {
- typedef itk::BinaryErodeImageFilter<InternalImageType, InternalImageType , KernelType> FilterType;
- typename FilterType::Pointer m = FilterType::New();
- m->SetBackgroundValue(m_ArgsInfo.bg_arg);
- m->SetForegroundValue(m_ArgsInfo.fg_arg);
- m->SetBoundaryToForeground(m_ArgsInfo.bound_flag);
- m->SetKernel(structuringElement);
-
- filter=m;
- if(m_Verbose) std::cout<<"Using the erode filter..."<<std::endl;
- break;
- }
-
- case 1:
- {
- typedef itk::BinaryDilateImageFilter<InternalImageType, InternalImageType , KernelType> FilterType;
- typename FilterType::Pointer m = FilterType::New();
- m->SetBackgroundValue(m_ArgsInfo.bg_arg);
- m->SetForegroundValue(m_ArgsInfo.fg_arg);
- m->SetBoundaryToForeground(m_ArgsInfo.bound_flag);
- m->SetKernel(structuringElement);
-
- filter=m;
- if(m_Verbose) std::cout<<"Using the dilate filter..."<<std::endl;
- break;
- }
-
- case 2:
- {
- typedef itk::BinaryMorphologicalClosingImageFilter<InternalImageType, InternalImageType , KernelType> FilterType;
- typename FilterType::Pointer m = FilterType::New();
- m->SetForegroundValue(m_ArgsInfo.fg_arg);
- m->SetSafeBorder(m_ArgsInfo.bound_flag);
- m->SetKernel(structuringElement);
-
- filter=m;
- if(m_Verbose) std::cout<<"Using the closing filter..."<<std::endl;
- break;
- }
-
- case 3:
- {
- typedef itk::BinaryMorphologicalOpeningImageFilter<InternalImageType, InternalImageType , KernelType> FilterType;
- typename FilterType::Pointer m = FilterType::New();
- m->SetBackgroundValue(m_ArgsInfo.bg_arg);
- m->SetForegroundValue(m_ArgsInfo.fg_arg);
- m->SetKernel(structuringElement);
-
- filter=m;
- if(m_Verbose) std::cout<<"Using the opening filter..."<<std::endl;
- break;
- }
-
- case 4:
- {
- typedef clitk::ConditionalBinaryErodeImageFilter<InternalImageType, InternalImageType , KernelType> FilterType;
- typename FilterType::Pointer m = FilterType::New();
- m->SetBackgroundValue(m_ArgsInfo.bg_arg);
- m->SetForegroundValue(m_ArgsInfo.fg_arg);
- m->SetBoundaryToForeground(m_ArgsInfo.bound_flag);
- m->SetKernel(structuringElement);
-
- filter=m;
- if(m_Verbose) std::cout<<"Using the conditional erode filter..."<<std::endl;
- break;
- }
-
- case 5:
- {
- typedef clitk::ConditionalBinaryDilateImageFilter<InternalImageType, InternalImageType , KernelType> FilterType;
- typename FilterType::Pointer m = FilterType::New();
- m->SetBackgroundValue(m_ArgsInfo.bg_arg);
- m->SetForegroundValue(m_ArgsInfo.fg_arg);
- m->SetBoundaryToForeground(m_ArgsInfo.bound_flag);
- m->SetKernel(structuringElement);
-
- filter=m;
- if(m_Verbose) std::cout<<"Using the conditional dilate filter..."<<std::endl;
- break;
- }
-
- }
-
-
- //---------------------------------
- // Execute the filter
- //---------------------------------
- filter->SetInput(input);