diff --git a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp index 322e9697ed..a754d40622 100644 --- a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp +++ b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.cpp @@ -1,110 +1,143 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkImageToPointCloudFilter.h" #include #include #include #include #include #include #include mitk::ImageToPointCloudFilter::ImageToPointCloudFilter() { m_PointSurface = mitk::Surface::New(); + m_method = 0; + m_EdgeImage = mitk::Image::New(); this->SetNumberOfRequiredInputs(1); this->SetNumberOfRequiredOutputs(1); +// this->SetNumberOfRequiredOutputs(2); this->SetNthOutput(0, m_PointSurface); +// this->SetNthOutput(1, m_EdgeImage); } mitk::ImageToPointCloudFilter::~ImageToPointCloudFilter(){} +void mitk::ImageToPointCloudFilter::SetDetectionMethod(DetectionMethod method) +{ + this->m_method = method; +} + void mitk::ImageToPointCloudFilter::GenerateData() { mitk::Image::ConstPointer image = ImageToSurfaceFilter::GetInput(); if ( image.IsNull() ) { MITK_ERROR << "mitk::ImageToContourFilter: No input available. Please set the input!" << std::endl; return; } ImageType::Pointer itkImage = ImageType::New(); - mitk::Image::Pointer final = mitk::Image::New(); CastToItkImage( image, itkImage ); + if(!itkImage) + { + MITK_ERROR << "Cannot cast mitk::Image::ConstPointer to itk::Image::Pointer" << std::endl; + return; + } + + switch(m_method) + { + case 0: + this->LaplacianStdDev(itkImage,2); + break; + + case 1: + this->LaplacianStdDev(itkImage,3); + break; + + default: + this->LaplacianStdDev(itkImage,2); + break; + } +} + +void mitk::ImageToPointCloudFilter::LaplacianStdDev(itk::Image::Pointer image, int amount) +{ ImagePTypeToFloatPTypeCasterType::Pointer caster = ImagePTypeToFloatPTypeCasterType::New(); - caster->SetInput( itkImage ); + caster->SetInput( image ); caster->Update(); FloatImageType::Pointer fImage = caster->GetOutput(); LaplacianFilterType::Pointer laplacianFilter = LaplacianFilterType::New(); laplacianFilter->SetInput( fImage ); laplacianFilter->UpdateLargestPossibleRegion(); - final = mitk::ImportItkImage(laplacianFilter->GetOutput())->Clone(); + m_EdgeImage = mitk::ImportItkImage(laplacianFilter->GetOutput())->Clone(); mitk::ImageStatisticsCalculator::Pointer statCalc = mitk::ImageStatisticsCalculator::New(); - statCalc->SetImage(final); + statCalc->SetImage(m_EdgeImage); statCalc->ComputeStatistics(); mitk::ImageStatisticsCalculator::Statistics stats = statCalc->GetStatistics(); double mean = stats.GetMean(); double stdDev = stats.GetSigma(); - AccessByItk_2(final, StdDeviations, mean, stdDev); + AccessByItk_3(m_EdgeImage, StdDeviations, mean, stdDev, amount); } template -void mitk::ImageToPointCloudFilter::StdDeviations(itk::Image* image, double mean, double stdDev) +void mitk::ImageToPointCloudFilter::StdDeviations(itk::Image* image, double mean, double stdDev, int amount) { typedef itk::Image InputImageType; itk::ImageRegionIterator it(image, image->GetRequestedRegion()); - double upperThreshold = mean + stdDev * 2; - double lowerThreshold = mean - stdDev * 2; + double upperThreshold = mean + stdDev * amount; + double lowerThreshold = mean - stdDev * amount; vtkSmartPointer points = vtkSmartPointer::New(); it.GoToBegin(); while( !it.IsAtEnd() ) { if(it.Get() > lowerThreshold && it.Get() < upperThreshold) { it.Set(0); } else { it.Set(1); points->InsertNextPoint(it.GetIndex()[0],it.GetIndex()[1],it.GetIndex()[2]); } + ++it; } vtkSmartPointer polyData = vtkSmartPointer::New(); polyData->SetPoints(points); m_PointSurface->SetVtkPolyData(polyData); } void mitk::ImageToPointCloudFilter::GenerateOutputInformation() { Superclass::GenerateOutputInformation(); } diff --git a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h index 59b726791e..e509b04974 100644 --- a/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h +++ b/Modules/SurfaceInterpolation/mitkImageToPointCloudFilter.h @@ -1,65 +1,81 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef mitkImageToPointCloudFilter_h_Included #define mitkImageToPointCloudFilter_h_Included #include #include #include #include namespace mitk { +struct MitkSurfaceInterpolation_EXPORT DetectConstants +{ + static const int LAPLACIAN_STD_DEV2 = 0; + static const int LAPLACIAN_STD_DEV3 = 1; + static const int CANNY_EDGE = 2; + static const int THRESHOLD = 3; +}; + class MitkSurfaceInterpolation_EXPORT ImageToPointCloudFilter: public ImageToSurfaceFilter { public: mitkClassMacro( ImageToPointCloudFilter, ImageToSurfaceFilter); itkFactorylessNewMacro(Self) itkCloneMacro(Self) typedef itk::Image ImageType; typedef itk::Image DoubleImageType; typedef itk::Image FloatImageType; typedef itk::CastImageFilter< ImageType, FloatImageType > ImagePTypeToFloatPTypeCasterType; typedef itk::LaplacianImageFilter< FloatImageType, FloatImageType > LaplacianFilterType; + typedef int DetectionMethod; + + void SetDetectionMethod(DetectionMethod method); protected: virtual void GenerateData(); virtual void GenerateOutputInformation(); ImageToPointCloudFilter(); virtual ~ImageToPointCloudFilter(); private: template - void StdDeviations(itk::Image* image, double mean, double stdDev); + void StdDeviations(itk::Image* image, double mean, double stdDev, int amount); + + void LaplacianStdDev(itk::Image::Pointer image, int amount); mitk::Surface::Pointer m_PointSurface; + mitk::Image::Pointer m_EdgeImage; + + DetectionMethod m_method; }; } #endif