#ifndef _itkMultipleUnlabeledImagesToLabeledImageFilter_txx #define _itkMultipleUnlabeledImagesToLabeledImageFilter_txx #include "itkMultipleUnlabeledImagesToLabeledImageFilter.h" #include "itkThresholdImageFilter.h" #include "itkAddImageFilter.h" #include "itkImageFileWriter.h" namespace itk { /** * Constructor */ template MultipleUnlabeledImagesToLabeledImageFilter ::MultipleUnlabeledImagesToLabeledImageFilter() { this->SetNumberOfRequiredInputs(0); this->SetNumberOfRequiredOutputs(1); m_IntensityThresholds = new std::vector; m_UseLowerThreshold = true; m_OutputImage = ImageType::New(); } /** * Print member variables */ template void MultipleUnlabeledImagesToLabeledImageFilter ::PrintSelf(std::ostream& os, Indent indent) const { Superclass::PrintSelf(os,indent); os << std::endl; // os << indent << "OrthogonalDirection: " << m_OrthogonalDirection << std::endl; } template void MultipleUnlabeledImagesToLabeledImageFilter ::GenerateData() { if(m_InputImageList.size() < 1) { // Image list cannot be empty. itk::ExceptionObject exceptionObject; exceptionObject.SetDescription("There are no input images!\n"); throw exceptionObject; } else if(m_IntensityThresholds->size() != m_InputImageList.size()) { // The number of thresholds should be the same as the number of input images. itk::ExceptionObject exceptionObject; exceptionObject.SetDescription("There are no lower threshold intensities!\n"); throw exceptionObject; } // The ThresholdImageFilter is used to assing a label to voxels outside of the the threshold. typename ThresholdFilterType::Pointer thresholdFilter = ThresholdFilterType::New(); // The AddImageFilter is used to combined labeled images into a single image. typename AddFilterType::Pointer addFilter = AddFilterType::New(); addFilter->SetInput1(thresholdFilter->GetOutput()); addFilter->SetInput2(addFilter->GetOutput()); typename ImageVectorType::iterator imageIt; unsigned int counter = 1; for(imageIt = m_InputImageList.begin(); imageIt != m_InputImageList.end(); imageIt++) { thresholdFilter->SetInput((*imageIt)); if(m_UseLowerThreshold) thresholdFilter->ThresholdAbove((*m_IntensityThresholds)[counter - 1]); else thresholdFilter->ThresholdBelow((*m_IntensityThresholds)[counter - 1]); thresholdFilter->SetOutsideValue(counter); thresholdFilter->Update(); addFilter->Update(); ++counter; } m_OutputImage = addFilter->GetOutput(); } } // end namespace itk #endif