/*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the copyright notices for more information. It is distributed under dual licence - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ #ifndef clitkImageLaplacianGenericFilter_txx #define clitkImageLaplacianGenericFilter_txx /* ================================================= * @file clitkImageLaplacianGenericFilter.txx * @author Jef Vandemeulebroucke * @date 29 june 2009 * * @brief * ===================================================*/ // itk include #include "itkCastImageFilter.h" #include "itkLaplacianImageFilter.h" #include "itkLaplacianRecursiveGaussianImageFilter.h" #include "itkLabelStatisticsImageFilter.h" #include "itkMaskImageFilter.h" #include "itkMaskNegatedImageFilter.h" #include namespace clitk { //-------------------------------------------------------------------- template ImageLaplacianGenericFilter::ImageLaplacianGenericFilter(): ImageToImageGenericFilter("ImageLaplacian") { InitializeImageType<2>(); InitializeImageType<3>(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template template void ImageLaplacianGenericFilter::InitializeImageType() { ADD_DEFAULT_IMAGE_TYPES(Dim); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template void ImageLaplacianGenericFilter::SetArgsInfo(const args_info_type & a) { mArgsInfo=a; this->SetIOVerbose(mArgsInfo.verbose_flag); if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); if (mArgsInfo.input_given) { this->SetInputFilename(mArgsInfo.input_arg); } if (mArgsInfo.output_given) { this->SetOutputFilename(mArgsInfo.output_arg); } if (mArgsInfo.mask_given) { this->AddInputFilename(mArgsInfo.mask_arg); } } //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Update with the number of dimensions and the pixeltype //-------------------------------------------------------------------- template template void ImageLaplacianGenericFilter::UpdateWithInputImageType() { // Main filter typedef typename InputImageType::PixelType InputPixelType; typedef itk::Image FloatImageType; typedef itk::Image MaskImageType; // Reading input typename InputImageType::Pointer input = this->template GetInput(0); //Cast input to float typedef itk::CastImageFilter< InputImageType, FloatImageType > CastFilterType; typename CastFilterType::Pointer castFilter = CastFilterType::New(); castFilter->SetInput(input); castFilter->Update(); typename MaskImageType::Pointer mask = ITK_NULLPTR; if(mArgsInfo.mask_given) { mask = this->template GetInput(1); } else { mask = MaskImageType::New(); mask->SetRegions(input->GetLargestPossibleRegion()); mask->SetOrigin(input->GetOrigin()); mask->SetSpacing(input->GetSpacing()); mask->Allocate(); mask->FillBuffer(1); } // Create output image typename FloatImageType::Pointer outputImage = FloatImageType::New(); outputImage->SetRegions(input->GetLargestPossibleRegion()); outputImage->SetOrigin(input->GetOrigin()); outputImage->SetSpacing(input->GetSpacing()); outputImage->Allocate(); outputImage->FillBuffer(0.0); // Set output iterator typedef itk::ImageRegionIterator IteratorOutputType; IteratorOutputType ito = IteratorOutputType(outputImage, outputImage->GetLargestPossibleRegion()); // Filter typename FloatImageType::Pointer outputLaplacianFilter; if (mArgsInfo.gaussian_filter_flag == 0) { //std::cout<<"gaussian filter flag == 0"< LaplacianImageFilterType; typename LaplacianImageFilterType::Pointer laplacianFilter=LaplacianImageFilterType::New(); laplacianFilter->SetInput(castFilter->GetOutput()); laplacianFilter->Update(); outputLaplacianFilter = laplacianFilter->GetOutput(); } else { //std::cout<<"gaussian filter flag == 1"< LaplacianImageFilterType; typename LaplacianImageFilterType::Pointer laplacianFilter=LaplacianImageFilterType::New(); laplacianFilter->SetInput(castFilter->GetOutput()); laplacianFilter->Update(); //std::cout<<"sigma value="<GetSigma()<GetOutput(); } // Set iterator typedef itk::ImageRegionIterator IteratorType; IteratorType it(outputLaplacianFilter, outputLaplacianFilter->GetLargestPossibleRegion()); // Set mask iterator typedef itk::ImageRegionIterator IteratorMaskType; IteratorMaskType itm(mask, mask->GetLargestPossibleRegion()); //typedef itk::MinimumMaximumImageCalculator ImageCalculatorFilterType; //typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New(); //imageCalculatorFilter->SetImage(gradientFilter->GetOutput()); //imageCalculatorFilter->Compute(); typedef itk::LabelStatisticsImageFilter< FloatImageType, MaskImageType > LabelStatisticsImageFilterType; typename LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New(); labelStatisticsImageFilter->SetLabelInput( mask ); labelStatisticsImageFilter->SetInput(outputLaplacianFilter); labelStatisticsImageFilter->Update(); //std::cout << "Number of labels: " << labelStatisticsImageFilter->GetNumberOfLabels() << std::endl; float minImg = labelStatisticsImageFilter->GetMinimum(1); //std::cout << "minImg: " << minImg << std::endl; float maxImg = labelStatisticsImageFilter->GetMaximum(1); //std::cout << "maxImg: " << maxImg << std::endl; it.GoToBegin(); ito.GoToBegin(); itm.GoToBegin(); while (!ito.IsAtEnd()) { if(mArgsInfo.normalize_flag && itm.Get() == 1) { ito.Set(((float) it.Get() - minImg)/(maxImg-minImg)); } if (mArgsInfo.normalize_flag == 0 && itm.Get() == 1) { ito.Set((float) it.Get()); } ++it; ++ito; ++itm; } //typename OutputImageType::Pointer outputImage = gradientFilter->GetOutput(); this->template SetNextOutput(outputImage); } //-------------------------------------------------------------------- }//end clitk #endif //#define clitkImageLaplacianGenericFilter_txx